Skip to content

Commit 1d40268

Browse files
Perform clean code of ui/org.eclipse.swt.tools.spies
1 parent 7c4e17e commit 1d40268

File tree

2 files changed

+58
-20
lines changed

2 files changed

+58
-20
lines changed

ui/org.eclipse.swt.tools.spies/src/org/eclipse/swt/tools/internal/Sleak.java

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ public static void main (String [] args) {
8888
// shell2.open();
8989

9090
while (!shell.isDisposed ()) {
91-
if (!display.readAndDispatch ()) display.sleep ();
91+
if (!display.readAndDispatch ()) {
92+
display.sleep ();
93+
}
9294
}
9395
display.dispose ();
9496
}
@@ -107,7 +109,7 @@ public void create (Composite parent) {
107109
Composite right = new Composite(sash, 0);
108110
right.setLayout(new GridLayout());
109111

110-
sash.setWeights(new int[] {40,60});
112+
sash.setWeights(40, 60);
111113

112114
// Right side
113115
canvas = new Canvas (right, SWT.BORDER);
@@ -393,29 +395,39 @@ void toggleStackTrace () {
393395
void paintCanvas (Event event) {
394396
canvas.setCursor (null);
395397
int index = list.getSelectionIndex ();
396-
if (index == -1) return;
398+
if (index == -1) {
399+
return;
400+
}
397401
GC gc = event.gc;
398402
Object object = objects.get(index).object;
399403
draw(gc, object);
400404
}
401405

402406
void draw(GC gc, Object object) {
403407
if (object instanceof Cursor) {
404-
if (((Cursor)object).isDisposed ()) return;
408+
if (((Cursor)object).isDisposed ()) {
409+
return;
410+
}
405411
canvas.setCursor ((Cursor) object);
406412
return;
407413
}
408414
if (object instanceof Font) {
409-
if (((Font)object).isDisposed ()) return;
415+
if (((Font)object).isDisposed ()) {
416+
return;
417+
}
410418
gc.setFont ((Font) object);
411419
String string = "";
412420
String lf = text.getLineDelimiter ();
413421
for (FontData data : gc.getFont ().getFontData ()) {
414422
String style = "NORMAL";
415423
int bits = data.getStyle ();
416424
if (bits != 0) {
417-
if ((bits & SWT.BOLD) != 0) style = "BOLD ";
418-
if ((bits & SWT.ITALIC) != 0) style += "ITALIC";
425+
if ((bits & SWT.BOLD) != 0) {
426+
style = "BOLD ";
427+
}
428+
if ((bits & SWT.ITALIC) != 0) {
429+
style += "ITALIC";
430+
}
419431
}
420432
string += data.getName () + " " + data.getHeight () + " " + style + lf;
421433
}
@@ -427,35 +439,47 @@ void draw(GC gc, Object object) {
427439
// return;
428440
// }
429441
if (object instanceof Image) {
430-
if (((Image)object).isDisposed ()) return;
442+
if (((Image)object).isDisposed ()) {
443+
return;
444+
}
431445
gc.drawImage ((Image) object, 0, 0);
432446
return;
433447
}
434448
if (object instanceof Path) {
435-
if (((Path)object).isDisposed ()) return;
449+
if (((Path)object).isDisposed ()) {
450+
return;
451+
}
436452
gc.drawPath ((Path) object);
437453
return;
438454
}
439455
if (object instanceof Pattern) {
440-
if (((Pattern)object).isDisposed ()) return;
456+
if (((Pattern)object).isDisposed ()) {
457+
return;
458+
}
441459
gc.setBackgroundPattern ((Pattern)object);
442460
gc.fillRectangle (canvas.getClientArea ());
443461
gc.setBackgroundPattern (null);
444462
return;
445463
}
446464
if (object instanceof Region) {
447-
if (((Region)object).isDisposed ()) return;
465+
if (((Region)object).isDisposed ()) {
466+
return;
467+
}
448468
String string = ((Region)object).getBounds().toString();
449469
gc.drawString (string, 0, 0);
450470
return;
451471
}
452472
if (object instanceof TextLayout) {
453-
if (((TextLayout)object).isDisposed ()) return;
473+
if (((TextLayout)object).isDisposed ()) {
474+
return;
475+
}
454476
((TextLayout)object).draw (gc, 0, 0);
455477
return;
456478
}
457479
if (object instanceof Transform) {
458-
if (((Transform)object).isDisposed ()) return;
480+
if (((Transform)object).isDisposed ()) {
481+
return;
482+
}
459483
String string = ((Transform)object).toString();
460484
gc.drawString (string, 0, 0);
461485
return;
@@ -464,7 +488,9 @@ void draw(GC gc, Object object) {
464488

465489
void refreshObject () {
466490
int index = list.getSelectionIndex ();
467-
if (index == -1) return;
491+
if (index == -1) {
492+
return;
493+
}
468494
if (stackTrace.getSelection ()) {
469495
text.setText (objects.get(index).getStack());
470496
setVisible(text, true);

ui/org.eclipse.swt.tools.spies/src/org/eclipse/swt/tools/views/SpyView.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public void createPartControl(Composite parent) {
6161
timer = new Runnable() {
6262
@Override
6363
public void run() {
64-
if (output == null || output.isDisposed() || !spyAction.isChecked()) return;
64+
if (output == null || output.isDisposed() || !spyAction.isChecked()) {
65+
return;
66+
}
6567
Display display = output.getDisplay();
6668
Control control = display.getCursorControl();
6769
if (control != lastControl) {
@@ -86,7 +88,9 @@ public void run() {
8688
text.append("\nPeers:\n");
8789
for (Control peer : parent.getChildren()) {
8890
text.append("\t");
89-
if (peer == control) text.append("*");
91+
if (peer == control) {
92+
text.append("*");
93+
}
9094
text.append(getName(peer)+"@"+getOSHandle(peer));
9195
text.append(" Layout Data: "+getName(peer.getLayoutData()));
9296
text.append(" Bounds: "+peer.getBounds());
@@ -134,7 +138,9 @@ public void run() {
134138
}
135139

136140
String getName(Object object) {
137-
if (object == null) return "null";
141+
if (object == null) {
142+
return "null";
143+
}
138144
String name = object.toString ();
139145
if (fullyQualifiedAction.isChecked()) {
140146
int index = name.indexOf(' ');
@@ -150,15 +156,19 @@ String getName(Object object) {
150156
*/
151157
@Override
152158
public void setFocus() {
153-
if (output != null & !output.isDisposed()) output.setFocus();
159+
if (output != null & !output.isDisposed()) {
160+
output.setFocus();
161+
}
154162
}
155163

156164
private String getOSHandle(Control control) {
157165
if (field == null) {
158166
for (String fieldName : new String[]{"handle", "view"}) {
159167
try {
160168
field = control.getClass().getField(fieldName);
161-
if (field != null) break;
169+
if (field != null) {
170+
break;
171+
}
162172
} catch (Throwable e) {}
163173
}
164174
}
@@ -509,7 +519,9 @@ private String getStyle(Widget w) {
509519
result += "DOUBLE_BUFFERED | ";
510520
}
511521
int lastOr = result.lastIndexOf("|");
512-
if (lastOr == result.length() - 2 ) result = result.substring(0, result.length() - 2);
522+
if (lastOr == result.length() - 2 ) {
523+
result = result.substring(0, result.length() - 2);
524+
}
513525
return result;
514526
}
515527
}

0 commit comments

Comments
 (0)