Bug 385451 - SubMonitor should provide a helper method for done
Add a helper method for invoking done on a nullable IProgressMonitor.
Change-Id: Ic5b9889049f1de032f1bb716c649211f86f32e13
Signed-off-by: Stefan Xenos <sxenos@gmail.com>
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 c77a103..88b904a 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
@@ -120,9 +120,7 @@
* doSomeWork(progress.split(40));
*
* } finally {
- * if (monitor != null) {
- * monitor.done();
- * }
+ * SubMonitor.done(monitor);
* }
* }
* </pre>
@@ -503,6 +501,21 @@
}
/**
+ * Calls {@link #done()} on the given monitor if is non-null. If the given monitor is null,
+ * this is a no-op.
+ * <p>
+ * This is a convenience method intended to reduce the boilerplate around code which must call
+ * {@link #done()} on a possibly-null monitor.
+ *
+ * @param monitor a progress monitor or null
+ */
+ public static void done(IProgressMonitor monitor) {
+ if (monitor != null) {
+ monitor.done();
+ }
+ }
+
+ /**
* <p>Sets the work remaining for this SubMonitor instance. This is the total number
* of ticks that may be reported by all subsequent calls to worked(int), split(int), etc.
* This may be called many times for the same SubMonitor instance. When this method