Skip to content

Commit 037c5d7

Browse files
committed
Use static IStatus factories in JFace
1 parent 2e549bb commit 037c5d7

19 files changed

+33
-93
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/action/ExternalActionManager.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.eclipse.core.commands.NotEnabledException;
3434
import org.eclipse.core.commands.ParameterizedCommand;
3535
import org.eclipse.core.commands.common.NotDefinedException;
36-
import org.eclipse.core.runtime.IStatus;
3736
import org.eclipse.core.runtime.ListenerList;
3837
import org.eclipse.core.runtime.Status;
3938
import org.eclipse.jface.bindings.BindingManager;
@@ -358,14 +357,10 @@ public final boolean isActive(final String commandId) {
358357
if (!command.isDefined()
359358
&& (!loggedCommandIds.contains(commandId))) {
360359
// The command is not yet defined, so we should log this.
361-
final String message = MessageFormat.format(Util
362-
.translateString(RESOURCE_BUNDLE,
363-
"undefinedCommand.WarningMessage", null), //$NON-NLS-1$
360+
String message = MessageFormat.format(
361+
Util.translateString(RESOURCE_BUNDLE, "undefinedCommand.WarningMessage", null), //$NON-NLS-1$
364362
command.getId());
365-
IStatus status = new Status(IStatus.ERROR,
366-
"org.eclipse.jface", //$NON-NLS-1$
367-
0, message, new Exception());
368-
Policy.getLog().log(status);
363+
Policy.getLog().log(Status.error(message));
369364

370365
// And remember this item so we don't log it again.
371366
loggedCommandIds.add(commandId);

bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/BindingManager.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,7 @@ private final void computeBindings(final Map activeContextTree,
655655
} catch (IOException e) {
656656
// we should not get this
657657
}
658-
conflicts.add(new Status(IStatus.WARNING,
659-
"org.eclipse.jface", //$NON-NLS-1$
660-
sw.toString()));
658+
conflicts.add(Status.warning(sw.toString()));
661659
}
662660
if (DEBUG) {
663661
Tracing.printTrace("BINDINGS", //$NON-NLS-1$
@@ -861,9 +859,7 @@ private final Map createFilteredContextTreeFor(final Set contextIds) {
861859
bindingErrors.add(context.getId());
862860

863861
// now log like you've never logged before!
864-
Status status = new Status(IStatus.ERROR, Policy.JFACE, IStatus.OK,
865-
"Undefined context while filtering dialog/window contexts", e); //$NON-NLS-1$
866-
Policy.getLog().log(status);
862+
Policy.getLog().log(Status.error("Undefined context while filtering dialog/window contexts", e)); //$NON-NLS-1$
867863
}
868864
}
869865
}
@@ -1568,10 +1564,7 @@ private final String[] getSchemeIds(String schemeId) {
15681564
try {
15691565
schemeId = getScheme(schemeId).getParentId();
15701566
} catch (final NotDefinedException e) {
1571-
Policy.getLog().log(
1572-
new Status(IStatus.ERROR, Policy.JFACE, IStatus.OK,
1573-
"Failed ascending scheme parents", //$NON-NLS-1$
1574-
e));
1567+
Policy.getLog().log(Status.error("Failed ascending scheme parents", e)); //$NON-NLS-1$
15751568
return new String[0];
15761569
}
15771570
}

bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/Dialog.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,7 @@ public void showBlocked(Shell parentShell, IProgressMonitor blocking,
420420
protected Dialog(Shell parentShell) {
421421
this(new SameShellProvider(parentShell));
422422
if (parentShell == null && Policy.DEBUG_DIALOG_NO_PARENT) {
423-
Policy.getLog().log(
424-
new Status(IStatus.INFO, Policy.JFACE, IStatus.INFO, this
425-
.getClass()
426-
+ " created with no shell",//$NON-NLS-1$
427-
new Exception()));
423+
Policy.getLog().log(Status.info(this.getClass() + " created with no shell")); //$NON-NLS-1$
428424
}
429425
}
430426

bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/StatusDialog.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public abstract class StatusDialog extends TrayDialog {
5858
*/
5959
public StatusDialog(Shell parent) {
6060
super(parent);
61-
fLastStatus = new Status(IStatus.OK, Policy.JFACE, IStatus.OK,
62-
Util.ZERO_LENGTH_STRING, null);
61+
fLastStatus = new Status(IStatus.OK, Policy.JFACE, Util.ZERO_LENGTH_STRING);
6362
}
6463

6564
/**

bundles/org.eclipse.jface/src/org/eclipse/jface/operation/ModalContext.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.eclipse.core.runtime.Assert;
2020
import org.eclipse.core.runtime.IProgressMonitor;
21-
import org.eclipse.core.runtime.IStatus;
2221
import org.eclipse.core.runtime.OperationCanceledException;
2322
import org.eclipse.core.runtime.ProgressMonitorWrapper;
2423
import org.eclipse.core.runtime.Status;
@@ -194,8 +193,8 @@ public void block() {
194193
throw new RuntimeException(t);
195194
}
196195
}
197-
Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE,
198-
"Unhandled event loop exception during blocked modal context.", t)); //$NON-NLS-1$
196+
Policy.getLog()
197+
.log(Status.error("Unhandled event loop exception during blocked modal context.", t)); //$NON-NLS-1$
199198
}
200199
}
201200
} else {

bundles/org.eclipse.jface/src/org/eclipse/jface/preference/PreferenceDialog.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import org.eclipse.core.runtime.Assert;
2727
import org.eclipse.core.runtime.ISafeRunnable;
28-
import org.eclipse.core.runtime.IStatus;
2928
import org.eclipse.core.runtime.ListenerList;
3029
import org.eclipse.core.runtime.SafeRunner;
3130
import org.eclipse.core.runtime.Status;
@@ -816,8 +815,7 @@ protected void handleSave() {
816815
} catch (IOException e) {
817816
String message = JFaceResources.format("PreferenceDialog.saveErrorMessage", page.getTitle(), //$NON-NLS-1$
818817
e.getMessage());
819-
Policy.getStatusHandler().show(
820-
new Status(IStatus.ERROR, Policy.JFACE, message, e),
818+
Policy.getStatusHandler().show(Status.error(message, e),
821819
JFaceResources.getString("PreferenceDialog.saveErrorTitle")); //$NON-NLS-1$
822820

823821
}
@@ -932,15 +930,11 @@ public void run() {
932930
public void handleException(Throwable e) {
933931
errorOccurred = true;
934932

935-
Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e));
933+
Policy.getLog().log(Status.error(e.toString(), e));
936934

937935
clearSelectedNode();
938936
String message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$
939-
940-
Policy.getStatusHandler().show(
941-
new Status(IStatus.ERROR, Policy.JFACE, message, e),
942-
JFaceResources.getString("Error")); //$NON-NLS-1$
943-
937+
Policy.getStatusHandler().show(Status.error(message, e), JFaceResources.getString("Error")); //$NON-NLS-1$
944938
}
945939
});
946940
}

bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.eclipse.core.runtime.FileLocator;
3030
import org.eclipse.core.runtime.IAdaptable;
3131
import org.eclipse.core.runtime.IPath;
32-
import org.eclipse.core.runtime.IStatus;
3332
import org.eclipse.core.runtime.Status;
3433
import org.eclipse.jface.internal.InternalPolicy;
3534
import org.eclipse.jface.util.Policy;
@@ -303,7 +302,7 @@ String getFilePath(String name, boolean logIOException) {
303302
} else if (InternalPolicy.DEBUG_LOG_URL_IMAGE_DESCRIPTOR_MISSING_2x) {
304303
if (name.endsWith("@2x.png") || name.endsWith("@1.5x.png")) { //$NON-NLS-1$ //$NON-NLS-2$
305304
String message = "High-resolution image missing: " + location + ' ' + name; //$NON-NLS-1$
306-
Policy.getLog().log(new Status(IStatus.WARNING, Policy.JFACE, message, e));
305+
Policy.getLog().log(Status.warning(message, e));
307306
}
308307
}
309308
return null;

bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.eclipse.core.runtime.FileLocator;
2929
import org.eclipse.core.runtime.IAdaptable;
3030
import org.eclipse.core.runtime.IPath;
31-
import org.eclipse.core.runtime.IStatus;
3231
import org.eclipse.core.runtime.Status;
3332
import org.eclipse.jface.internal.InternalPolicy;
3433
import org.eclipse.jface.util.Policy;
@@ -172,7 +171,7 @@ private static ImageData getImageData(URL url) {
172171
// fall through otherwise
173172
}
174173
} catch (IOException e) {
175-
Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, e.getLocalizedMessage(), e));
174+
Policy.getLog().log(Status.error(e.getLocalizedMessage(), e));
176175
}
177176
return result;
178177
}
@@ -204,8 +203,7 @@ private static InputStream getStream(URL url) {
204203
if (InternalPolicy.DEBUG_LOG_URL_IMAGE_DESCRIPTOR_MISSING_2x) {
205204
String path = url.getPath();
206205
if (path.endsWith("@2x.png") || path.endsWith("@1.5x.png")) { //$NON-NLS-1$ //$NON-NLS-2$
207-
String message = "High-resolution image missing: " + url; //$NON-NLS-1$
208-
Policy.getLog().log(new Status(IStatus.WARNING, Policy.JFACE, message, e));
206+
Policy.getLog().log(Status.warning("High-resolution image missing: " + url, e)); //$NON-NLS-1$
209207
}
210208
}
211209
return null;
@@ -244,7 +242,7 @@ private static URL getxURL(URL url, int zoom) {
244242
}
245243
return new URL(url.getProtocol(), url.getHost(), url.getPort(), file);
246244
} catch (MalformedURLException e) {
247-
Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, e.getLocalizedMessage(), e));
245+
Policy.getLog().log(Status.error(e.getLocalizedMessage(), e));
248246
}
249247
}
250248
return null;
@@ -282,8 +280,7 @@ private static String getFilePath(URL url, boolean logIOException) {
282280
} else if (InternalPolicy.DEBUG_LOG_URL_IMAGE_DESCRIPTOR_MISSING_2x) {
283281
String path = url.getPath();
284282
if (path.endsWith("@2x.png") || path.endsWith("@1.5x.png")) { //$NON-NLS-1$ //$NON-NLS-2$
285-
String message = "High-resolution image missing: " + url; //$NON-NLS-1$
286-
Policy.getLog().log(new Status(IStatus.WARNING, Policy.JFACE, message, e));
283+
Policy.getLog().log(Status.warning("High-resolution image missing: " + url, e)); //$NON-NLS-1$
287284
}
288285
}
289286
return null;
@@ -363,7 +360,7 @@ private static URL getURL(String urlString) {
363360
try {
364361
result = new URL(urlString);
365362
} catch (MalformedURLException e) {
366-
Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, e.getLocalizedMessage(), e));
363+
Policy.getLog().log(Status.error(e.getLocalizedMessage(), e));
367364
}
368365
return result;
369366
}

bundles/org.eclipse.jface/src/org/eclipse/jface/util/LocalSelectionTransfer.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package org.eclipse.jface.util;
1515

1616

17-
import org.eclipse.core.runtime.IStatus;
1817
import org.eclipse.core.runtime.Status;
1918
import org.eclipse.jface.resource.JFaceResources;
2019
import org.eclipse.jface.viewers.ISelection;
@@ -129,11 +128,7 @@ public void javaToNative(Object object, TransferData transferData) {
129128
public Object nativeToJava(TransferData transferData) {
130129
Object result = super.nativeToJava(transferData);
131130
if (result != null && isInvalidNativeType(result)) {
132-
Policy.getLog().log(new Status(
133-
IStatus.ERROR,
134-
Policy.JFACE,
135-
IStatus.ERROR,
136-
JFaceResources.getString("LocalSelectionTransfer.errorMessage"), null)); //$NON-NLS-1$
131+
Policy.getLog().log(Status.error(JFaceResources.getString("LocalSelectionTransfer.errorMessage"))); //$NON-NLS-1$
137132
}
138133
return selection;
139134
}

bundles/org.eclipse.jface/src/org/eclipse/jface/util/Policy.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,7 @@ public static ErrorSupportProvider getErrorSupportProvider() {
259259
* @since 3.4
260260
*/
261261
public static void logException(Exception exception) {
262-
getLog().log(
263-
new Status(IStatus.ERROR, JFACE, exception
264-
.getLocalizedMessage(), exception));
265-
262+
getLog().log(Status.error(exception.getLocalizedMessage(), exception));
266263
}
267264

268265
}

bundles/org.eclipse.jface/src/org/eclipse/jface/util/SafeRunnable.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.eclipse.jface.util;
1717

1818
import org.eclipse.core.runtime.ISafeRunnable;
19-
import org.eclipse.core.runtime.IStatus;
2019
import org.eclipse.core.runtime.OperationCanceledException;
2120
import org.eclipse.core.runtime.Status;
2221
import org.eclipse.jface.resource.JFaceResources;
@@ -63,9 +62,7 @@ public void handleException(Throwable e) {
6362
if (message == null)
6463
message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$
6564

66-
Policy.getStatusHandler().show(
67-
new Status(IStatus.ERROR, Policy.JFACE, message, e),
68-
JFaceResources.getString("SafeRunnable.errorMessage")); //$NON-NLS-1$
65+
Policy.getStatusHandler().show(Status.error(message, e), JFaceResources.getString("SafeRunnable.errorMessage")); //$NON-NLS-1$
6966
}
7067

7168
/**
@@ -135,11 +132,7 @@ public void run(ISafeRunnable code) {
135132
private void handleException(ISafeRunnable code, Throwable e) {
136133
if (!(e instanceof OperationCanceledException)) {
137134
try {
138-
Policy.getLog()
139-
.log(
140-
new Status(IStatus.ERROR, Policy.JFACE,
141-
IStatus.ERROR,
142-
"Exception occurred", e)); //$NON-NLS-1$
135+
Policy.getLog().log(Status.error("Exception occurred", e)); //$NON-NLS-1$
143136
} catch (Exception ex) {
144137
e.printStackTrace();
145138
}

bundles/org.eclipse.jface/src/org/eclipse/jface/util/StructuredTextSegmentListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package org.eclipse.jface.util;
1616

17-
import org.eclipse.core.runtime.IStatus;
1817
import org.eclipse.core.runtime.Status;
1918
import org.eclipse.equinox.bidi.StructuredTextTypeHandlerFactory;
2019
import org.eclipse.equinox.bidi.advanced.IStructuredTextExpert;
@@ -84,8 +83,8 @@ public void getSegments(SegmentEvent event) {
8483
} catch (RuntimeException ex) {
8584
// Only log the first exception. Logging every exception would make the system unusable.
8685
if (logExceptions) {
87-
Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE,
88-
"An error occurred while processing \"" + event.lineText + "\" with " + expert, ex)); //$NON-NLS-1$//$NON-NLS-2$
86+
Policy.getLog().log(Status
87+
.error("An error occurred while processing \"" + event.lineText + "\" with " + expert, ex)); //$NON-NLS-1$//$NON-NLS-2$
8988
logExceptions = false;
9089
}
9190
}

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.List;
3131

3232
import org.eclipse.core.runtime.Assert;
33-
import org.eclipse.core.runtime.IStatus;
3433
import org.eclipse.core.runtime.ListenerList;
3534
import org.eclipse.core.runtime.Status;
3635
import org.eclipse.jface.internal.InternalPolicy;
@@ -1510,9 +1509,7 @@ private void assertElementsNotNull(Object parent, Object[] elements) {
15101509
if (old != null) {
15111510
String message = "Sibling elements in viewer must not be equal:\n " //$NON-NLS-1$
15121511
+ old + ",\n " + element + ",\n parent: " + parent; //$NON-NLS-1$ //$NON-NLS-2$
1513-
Policy.getLog().log(
1514-
new Status(IStatus.WARNING, Policy.JFACE, message,
1515-
new RuntimeException()));
1512+
Policy.getLog().log(Status.warning(message));
15161513
return;
15171514
}
15181515
}

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Set;
2525

2626
import org.eclipse.core.runtime.Assert;
27-
import org.eclipse.core.runtime.IStatus;
2827
import org.eclipse.core.runtime.Status;
2928
import org.eclipse.jface.internal.InternalPolicy;
3029
import org.eclipse.jface.util.Policy;
@@ -757,9 +756,7 @@ protected boolean checkBusy() {
757756
message += " This is only logged once per viewer instance," + //$NON-NLS-1$
758757
" but similar calls will still be ignored."; //$NON-NLS-1$
759758
}
760-
Policy.getLog().log(
761-
new Status(IStatus.WARNING, Policy.JFACE, message,
762-
new RuntimeException()));
759+
Policy.getLog().log(Status.warning(message));
763760
}
764761
return true;
765762
}

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ContentViewer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.eclipse.jface.viewers;
1717

1818
import org.eclipse.core.runtime.Assert;
19-
import org.eclipse.core.runtime.IStatus;
2019
import org.eclipse.core.runtime.Status;
2120
import org.eclipse.jface.internal.InternalPolicy;
2221
import org.eclipse.jface.util.Policy;
@@ -86,9 +85,7 @@ public void labelProviderChanged(LabelProviderChangedEvent event) {
8685
message += " This is only logged once per viewer instance," + //$NON-NLS-1$
8786
" but similar calls will still be ignored."; //$NON-NLS-1$
8887
}
89-
Policy.getLog().log(
90-
new Status(IStatus.WARNING, Policy.JFACE, message,
91-
new RuntimeException()));
88+
Policy.getLog().log(Status.warning(message));
9289
}
9390
return;
9491
}
@@ -173,7 +170,7 @@ protected void handleDispose(DisposeEvent event) {
173170
// ignore exception
174171
String message = "Exception while calling ContentProvider.inputChanged from ContentViewer.handleDispose"; //$NON-NLS-1$
175172
message += " (" + contentProvider.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$
176-
Policy.getLog().log(new Status(IStatus.WARNING, Policy.JFACE, message, e));
173+
Policy.getLog().log(Status.warning(message, e));
177174
}
178175
contentProvider.dispose();
179176
contentProvider = null;

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.List;
2727

2828
import org.eclipse.core.runtime.Assert;
29-
import org.eclipse.core.runtime.IStatus;
3029
import org.eclipse.core.runtime.ListenerList;
3130
import org.eclipse.core.runtime.Status;
3231
import org.eclipse.jface.internal.InternalPolicy;
@@ -548,9 +547,7 @@ protected void assertElementsNotNull(Object... elements) {
548547
if (old != null) {
549548
String message = "Sibling elements in viewer must not be equal:\n " //$NON-NLS-1$
550549
+ old + ",\n " + element; //$NON-NLS-1$
551-
Policy.getLog().log(
552-
new Status(IStatus.WARNING, Policy.JFACE, message,
553-
new RuntimeException()));
550+
Policy.getLog().log(Status.warning(message));
554551
return;
555552
}
556553
}

bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerComparator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Arrays;
2020
import java.util.Comparator;
2121

22-
import org.eclipse.core.runtime.IStatus;
2322
import org.eclipse.core.runtime.Status;
2423
import org.eclipse.jface.util.Policy;
2524

@@ -223,7 +222,7 @@ public void sort(final Viewer viewer, Object[] elements) {
223222
labels.append(getLabel(viewer, element));
224223
}
225224
msg += labels;
226-
Policy.getLog().log(new Status(IStatus.ERROR, "org.eclipse.jface", msg)); //$NON-NLS-1$
225+
Policy.getLog().log(Status.error(msg));
227226
throw e;
228227
}
229228
}

0 commit comments

Comments
 (0)