Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2016-10-15 00:02:24 +0000
committerSergey Prigogin2016-10-15 02:05:14 +0000
commit594fd3222c63fc6392b19f034cd038b7728bdb34 (patch)
tree81b97c847d526bc5024fbdf5d7db879fdc8a259f
parentbe955ed849a2b51f10f4b534ee2ee9418cc578f0 (diff)
downloadrt.equinox.bundles-594fd3222c63fc6392b19f034cd038b7728bdb34.tar.gz
rt.equinox.bundles-594fd3222c63fc6392b19f034cd038b7728bdb34.tar.xz
rt.equinox.bundles-594fd3222c63fc6392b19f034cd038b7728bdb34.zip
Bug 506012 - Add SubMonitor.checkCanceled method
Change-Id: I489da9d6b1d0213768f3e4915f87d0a76b8077a1 Signed-off-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
-rw-r--r--bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/SubMonitor.java34
1 files changed, 27 insertions, 7 deletions
diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/SubMonitor.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/SubMonitor.java
index 14e278a8a..39ab47c52 100644
--- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/SubMonitor.java
+++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/SubMonitor.java
@@ -205,7 +205,7 @@ public final class SubMonitor implements IProgressMonitorWithBlocking {
* Amount to increment {@link RootInfo#cancellationCheckCounter} when performing
* a trivial {@link #step(int)} operation.
*/
- private static final int TRIVIAL_TICK_DELTA = TRIVIAL_OPERATION_COUNT_LIMIT / TRIVIAL_TICKS_BEFORE_CANCELLATION_CHECK;;
+ private static final int TRIVIAL_TICK_DELTA = TRIVIAL_OPERATION_COUNT_LIMIT / TRIVIAL_TICKS_BEFORE_CANCELLATION_CHECK;
/**
* Minimum number of ticks to allocate when calling beginTask on an unknown IProgressMonitor.
@@ -216,7 +216,7 @@ public final class SubMonitor implements IProgressMonitorWithBlocking {
/**
* The RootInfo holds information about the root progress monitor. A SubMonitor and
- * its active descendents share the same RootInfo.
+ * its active descendants share the same RootInfo.
*/
private static final class RootInfo {
final IProgressMonitor root;
@@ -225,13 +225,13 @@ public final class SubMonitor implements IProgressMonitorWithBlocking {
* Remembers the last task name. Prevents us from setting the same task name multiple
* times in a row.
*/
- String taskName = null;
+ String taskName;
/**
* Remembers the last subtask name. Prevents the SubMonitor from setting the same
* subtask string more than once in a row.
*/
- String subTask = null;
+ String subTask;
/**
* Counter that indicates when we should perform an cancellation check for a trivial
@@ -240,9 +240,8 @@ public final class SubMonitor implements IProgressMonitorWithBlocking {
int cancellationCheckCounter;
/**
- * Creates a RootInfo struct that delegates to the given progress
- * monitor.
- *
+ * Creates a RootInfo structure that delegates to the given progress monitor.
+ *
* @param root progress monitor to delegate to
*/
public RootInfo(IProgressMonitor root) {
@@ -600,6 +599,27 @@ public final class SubMonitor implements IProgressMonitorWithBlocking {
return false;
}
+ /**
+ * Checks whether cancellation of current operation has been requested and throws
+ * an {@link OperationCanceledException} if it was the case. This method is a shorthand
+ * for:
+ * <pre>
+ * if (monitor.isCanceled())
+ * throw new OperationCanceledException();
+ * </pre>
+ *
+ * @return this SubMonitor to allow for chained invocation
+ * @throws OperationCanceledException if cancellation has been requested
+ * @see #isCanceled()
+ * @since 3.9
+ */
+ public SubMonitor checkCanceled() throws OperationCanceledException {
+ if (isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ return this;
+ }
+
@Override
public void setTaskName(String name) {
if ((flags & SUPPRESS_SETTASKNAME) == 0)

Back to the top