Skip to content

Commit c5aef98

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of runtime/bundles/org.eclipse.core.tools
1 parent e7ea945 commit c5aef98

38 files changed

+317
-177
lines changed

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/AbstractTreeContentProvider.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ protected AbstractTreeContentProvider() {
6666
*/
6767
@Override
6868
public Object[] getChildren(Object parentElement) {
69-
if (!(parentElement instanceof TreeContentProviderNode))
69+
if (!(parentElement instanceof TreeContentProviderNode treeNode)) {
7070
return null;
71+
}
7172

72-
TreeContentProviderNode treeNode = (TreeContentProviderNode) parentElement;
7373
return treeNode.getChildren();
7474
}
7575

@@ -84,10 +84,10 @@ public Object[] getChildren(Object parentElement) {
8484
*/
8585
@Override
8686
public Object getParent(Object element) {
87-
if (!(element instanceof TreeContentProviderNode))
87+
if (!(element instanceof TreeContentProviderNode treeNode)) {
8888
return null;
89+
}
8990

90-
TreeContentProviderNode treeNode = (TreeContentProviderNode) element;
9191
return treeNode.getParent();
9292
}
9393

@@ -114,8 +114,9 @@ public boolean hasChildren(Object element) {
114114
*/
115115
@Override
116116
public Object[] getElements(Object inputElement) {
117-
if (rootNode == null)
117+
if (rootNode == null) {
118118
return new Object[0];
119+
}
119120

120121
return omitRoot ? rootNode.getChildren() : new Object[] {rootNode};
121122
}
@@ -175,8 +176,9 @@ public void inputChanged(Viewer viewer, Object oldInput, final Object input) {
175176
return;
176177
}
177178

178-
if (!acceptInput(input))
179+
if (!acceptInput(input)) {
179180
return;
181+
}
180182

181183
rootNode = createNode("root"); //$NON-NLS-1$
182184
rebuild(viewer, input);

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/ByteUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ public static String byteArrayToString(byte[] byteArray, int max) {
3535
result.append(',');
3636
}
3737
// adds an ellipsis if there is too much bytes to show
38-
if (max > 0 && max < byteArray.length)
38+
if (max > 0 && max < byteArray.length) {
3939
result.append("..."); //$NON-NLS-1$
4040
// or remove the trailing comma
41-
else
41+
} else {
4242
result.deleteCharAt(result.length() - 1);
43+
}
4344
result.append(']');
4445
return result.toString();
4546
}

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/ClearTextAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ClearTextAction extends GlobalAction {
2828
/**
2929
* The document on which this action performs its duty.
3030
*/
31-
private IDocument document;
31+
private final IDocument document;
3232

3333
/**
3434
* Constructs a ClearTextAction action with the provided document.

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/CollapseAllAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class CollapseAllAction extends Action {
2424

2525
private static final String label = "Collapse All"; //$NON-NLS-1$
26-
private TreeViewer viewer;
26+
private final TreeViewer viewer;
2727

2828
public CollapseAllAction(TreeViewer viewer) {
2929
super(label);

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/DeepSize.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ public boolean equals(Object o) {
5757
if (o == null) {
5858
return false;
5959
}
60-
if (o.getClass() != ObjectWrapper.class)
60+
if (o.getClass() != ObjectWrapper.class) {
6161
return false;
62+
}
6263
return object == ((ObjectWrapper) o).object;
6364
}
6465

@@ -168,21 +169,25 @@ private boolean shouldIgnoreType(Class<?> clazz) {
168169
ignoreTypeNames = getDefaultIgnoreTypeNames();
169170
}
170171
while (clazz != null) {
171-
if (ignoreTypeNames.contains(clazz.getName()))
172+
if (ignoreTypeNames.contains(clazz.getName())) {
172173
return true;
174+
}
173175
clazz = clazz.getSuperclass();
174176
}
175177
return false;
176178
}
177179

178180
private int sizeOf(Object o) {
179-
if (o == null)
181+
if (o == null) {
180182
return 0;
181-
if (ignore(o))
183+
}
184+
if (ignore(o)) {
182185
return POINTER_SIZE;
186+
}
183187
Class<?> clazz = o.getClass();
184-
if (shouldIgnoreType(clazz))
188+
if (shouldIgnoreType(clazz)) {
185189
return POINTER_SIZE;
190+
}
186191
return clazz.isArray() ? sizeOfArray(clazz, o) : sizeOfObject(clazz, o);
187192
}
188193

@@ -258,8 +263,9 @@ private int sizeOfObject(Class<?> type, Object o) {
258263
}
259264

260265
private int sizeOfPrimitiveField(Class<?> type) {
261-
if (type == long.class || type == double.class)
266+
if (type == long.class || type == double.class) {
262267
return 8;
268+
}
263269
return 4;
264270
}
265271

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/ErrorUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public class ErrorUtil {
3131
* @param userMessage an optional higher-level explanation for the exception
3232
*/
3333
public static void logException(Exception exception, String userMessage) {
34-
if (userMessage == null)
34+
if (userMessage == null) {
3535
userMessage = exception.getMessage();
36+
}
3637
IStatus status = new Status(IStatus.ERROR, ErrorUtil.class, -1, userMessage, exception);
3738
ILog.of(ErrorUtil.class).log(status);
3839
}
@@ -44,8 +45,9 @@ public static void logException(Exception exception, String userMessage) {
4445
*/
4546
public static void showErrorMessage(String message, String title) {
4647
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
47-
if (title == null)
48+
if (title == null) {
4849
title = "Error in Spy plug-in"; //$NON-NLS-1$
50+
}
4951
MessageDialog.openError(shell, title, message);
5052
}
5153
}

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/TableSelectionProviderDecorator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ public ISelection getSelection() {
5858
ISelection selection = selectionProvider.getSelection();
5959

6060
// in these cases the original selection will be returned
61-
if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection))
61+
if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection structuredSelection)) {
6262
return selection;
63+
}
6364

6465
// constructs a list with the selected elements
65-
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
66-
6766
StringBuilder copyText = new StringBuilder();
6867
copyText.append(headerPluginStats());
6968
copyText.append('\n');

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/TableWithTotalView.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ public void widgetSelected(SelectionEvent event) {
7878
// Three state sort for column 0. !flat/!reverse -> flat/!reverse -> flat/reverse
7979
if (column == 0) {
8080
if (flat) {
81-
if (oldSorter.isReversed())
81+
if (oldSorter.isReversed()) {
8282
flat = false;
83+
}
8384
oldSorter.setReversed(!oldSorter.isReversed());
8485
} else {
8586
flat = true;
@@ -90,8 +91,9 @@ public void widgetSelected(SelectionEvent event) {
9091
oldSorter.setReversed(!oldSorter.isReversed());
9192
}
9293
}
93-
if (viewer.getContentProvider() instanceof IFlattable)
94+
if (viewer.getContentProvider() instanceof IFlattable) {
9495
((IFlattable) viewer.getContentProvider()).setFlat(flat);
96+
}
9597
viewer.refresh();
9698
viewer.setSelection(selection);
9799
}
@@ -199,15 +201,17 @@ public void run() {
199201
IStructuredSelection selection = viewer.getStructuredSelection();
200202
String result = ""; //$NON-NLS-1$
201203
String[] columnHeaders = getColumnHeaders();
202-
for (String columnHeader : columnHeaders)
204+
for (String columnHeader : columnHeaders) {
203205
result += columnHeader + ","; //$NON-NLS-1$
206+
}
204207
result += "\n\n"; //$NON-NLS-1$
205208

206209
ITableLabelProvider labelProvider = (ITableLabelProvider) viewer.getLabelProvider();
207210
for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
208211
Object selectedItem = iterator.next();
209-
for (int i = 0; i < columnHeaders.length; i++)
212+
for (int i = 0; i < columnHeaders.length; i++) {
210213
result += labelProvider.getColumnText(selectedItem, i) + ","; //$NON-NLS-1$
214+
}
211215
result += "\n"; //$NON-NLS-1$
212216
}
213217
clipboard.setContents(new Object[] {result}, new Transfer[] {TextTransfer.getInstance()});
@@ -268,7 +272,8 @@ public void setSelection(ISelection selection) {
268272

269273
@Override
270274
public void setFocus() {
271-
if (tableTree != null)
275+
if (tableTree != null) {
272276
tableTree.setFocus();
277+
}
273278
}
274279
}

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/TreeContentProviderNode.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ public boolean hasChildren() {
108108

109109
@Override
110110
public String toString() {
111-
if (name == null)
111+
if (name == null) {
112112
return value.toString();
113-
if (value == null)
113+
}
114+
if (value == null) {
114115
return name;
116+
}
115117
return name + " = " + value; //$NON-NLS-1$
116118
}
117119

@@ -149,8 +151,9 @@ public boolean isRoot() {
149151
* <code>TreeContentProviderNode</code>.
150152
*/
151153
public void sort() {
152-
if (children == null)
154+
if (children == null) {
153155
return;
156+
}
154157
children.sort(null);
155158
}
156159

@@ -173,10 +176,12 @@ public int compareTo(TreeContentProviderNode other) {
173176
* @see ITreeNodeVisitor#visit
174177
*/
175178
public void accept(ITreeNodeVisitor visitor) {
176-
if (!visitor.visit(this))
179+
if (!visitor.visit(this)) {
177180
return;
178-
if (children == null)
181+
}
182+
if (children == null) {
179183
return;
184+
}
180185
for (TreeContentProviderNode child : children) {
181186
child.accept(visitor);
182187
}
@@ -197,10 +202,12 @@ public TreeContentProviderNode getRoot() {
197202
* @return a tree node, or <code>null</code>
198203
*/
199204
public TreeContentProviderNode findNode(Object obj) {
200-
if (obj.equals(this.value))
205+
if (obj.equals(this.value)) {
201206
return this;
202-
if (children == null || children.isEmpty())
207+
}
208+
if (children == null || children.isEmpty()) {
203209
return null;
210+
}
204211
for (TreeContentProviderNode child : children) {
205212
TreeContentProviderNode found = child.findNode(obj);
206213
if (found != null) {
@@ -212,7 +219,7 @@ public TreeContentProviderNode findNode(Object obj) {
212219

213220
@Override
214221
public <T> T getAdapter(Class<T> adapter) {
215-
return value instanceof IAdaptable ? ((IAdaptable) value).getAdapter(adapter) : null;
222+
return value instanceof IAdaptable i ? i.getAdapter(adapter) : null;
216223
}
217224

218225
}

runtime/bundles/org.eclipse.core.tools/src/org/eclipse/core/tools/TreeSelectionProviderDecorator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,21 @@ public ISelection getSelection() {
6363
ISelection selection = selectionProvider.getSelection();
6464

6565
// in these cases the original selection will be returned
66-
if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection))
66+
if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection structuredSelection)) {
6767
return selection;
68+
}
6869

6970
// constructs a list with the selected elements
70-
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
7171
List<Object> list = structuredSelection.toList();
7272
final List<Object> selectedElements = new ArrayList<>(list);
7373

7474
// tries to find a TreeContentProviderNode between the selected elements
7575
TreeContentProviderNode anyNode = findNodeElement(selectedElements);
7676

7777
// if there is no TreeContentProviderNodes, there is nothing to do
78-
if (anyNode == null)
78+
if (anyNode == null) {
7979
return selection;
80+
}
8081

8182
// otherwise, we will move the elements to a new list in the same order
8283
// we find them in the tree.
@@ -87,8 +88,9 @@ public ISelection getSelection() {
8788
anyNode.getRoot().accept(node -> {
8889
int elementIndex = selectedElements.indexOf(node);
8990

90-
if (selectedElements.contains(node))
91+
if (selectedElements.contains(node)) {
9192
orderedElements.add(selectedElements.remove(elementIndex));
93+
}
9294

9395
return true;
9496
});
@@ -108,8 +110,9 @@ public ISelection getSelection() {
108110
private TreeContentProviderNode findNodeElement(List<Object> elements) {
109111
for (Iterator<?> iter = elements.iterator(); iter.hasNext();) {
110112
Object element = iter.next();
111-
if (element instanceof TreeContentProviderNode)
113+
if (element instanceof TreeContentProviderNode) {
112114
return (TreeContentProviderNode) element;
115+
}
113116
}
114117

115118
return null;

0 commit comments

Comments
 (0)