Skip to content

Commit 3a11a5a

Browse files
Perform clean code of ui/org.eclipse.pde.spy.context
1 parent 4e00417 commit 3a11a5a

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

Diff for: ui/org.eclipse.pde.spy.context/src/org/eclipse/pde/internal/spy/context/ContextDataFilter.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public class ContextDataFilter extends ViewerFilter {
4444
@Override
4545
public boolean select(Viewer viewer, Object parentElement, Object element) {
4646
if ((element == ContextDataProvider.LOCAL_VALUE_NODE)
47-
|| (element == ContextDataProvider.INHERITED_INJECTED_VALUE_NODE))
47+
|| (element == ContextDataProvider.INHERITED_INJECTED_VALUE_NODE)) {
4848
return true;
49+
}
4950

5051
// Must only select objects matching the pattern or objects under a kept
5152
// node (to see where it is injected)
@@ -73,10 +74,11 @@ public boolean select(Viewer viewer, Object parentElement, Object element) {
7374

7475
/** Set the pattern and use it as lowercase */
7576
public void setPattern(String newPattern) {
76-
if ((newPattern == null) || (newPattern.length() == 0))
77+
if ((newPattern == null) || (newPattern.length() == 0)) {
7778
pattern = null;
78-
else
79+
} else {
7980
pattern = newPattern.toLowerCase();
81+
}
8082
}
8183

8284
/**
@@ -129,8 +131,9 @@ private Collection<String> computeValues(IEclipseContext ctx) {
129131

130132
if (currentContext.getRawListenerNames() != null) {
131133
for (String name : currentContext.getRawListenerNames()) {
132-
if (!localKeys.contains(name) && !localContextFunctionsKeys.contains(name))
134+
if (!localKeys.contains(name) && !localContextFunctionsKeys.contains(name)) {
133135
result.add(name);
136+
}
134137
}
135138
}
136139

Diff for: ui/org.eclipse.pde.spy.context/src/org/eclipse/pde/internal/spy/context/ContextDataPart.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ public void setColumn(int column) {
162162
@Override
163163
public int compare(Viewer viewer, Object e1, Object e2) {
164164
// For root elements at first level, we keep Local before Inherited
165-
if ((e1 == ContextDataProvider.LOCAL_VALUE_NODE) || (e2 == ContextDataProvider.LOCAL_VALUE_NODE))
165+
if ((e1 == ContextDataProvider.LOCAL_VALUE_NODE) || (e2 == ContextDataProvider.LOCAL_VALUE_NODE)) {
166166
return -1;
167+
}
167168

168169
// Now can compare the text from label provider.
169170
String lp1 = labelProvider.getText(e1);

Diff for: ui/org.eclipse.pde.spy.context/src/org/eclipse/pde/internal/spy/context/ContextDataProvider.java

+30-19
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ public Object[] getElements(Object inputElement) {
107107

108108
@Override
109109
public Object[] getChildren(Object inputElement) {
110-
if (selectedContext == null)
110+
if (selectedContext == null) {
111111
return EMPTY_RESULT;
112+
}
112113

113114
if (inputElement == LOCAL_VALUE_NODE) {
114115
Collection<Object> result = new ArrayList<>();
@@ -118,12 +119,13 @@ public Object[] getChildren(Object inputElement) {
118119
// For context function, we have to compute the value (if possible),
119120
// and display it as a standard value
120121
Map<String, Object> cfValues = new HashMap<>();
121-
for (String key : selectedContext.localContextFunction().keySet())
122+
for (String key : selectedContext.localContextFunction().keySet()) {
122123
try {
123124
cfValues.put(key, selectedContext.get(key));
124125
} catch (Throwable e) {
125126
cfValues.put(key, NO_VALUE_COULD_BE_COMPUTED + " (Exception : " + e.getClass().getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
126127
}
128+
}
127129
result.addAll(cfValues.entrySet());
128130
return result.toArray();
129131

@@ -139,8 +141,9 @@ public Object[] getChildren(Object inputElement) {
139141

140142
if (selectedContext.getRawListenerNames() != null) {
141143
for (String name : selectedContext.getRawListenerNames()) {
142-
if (!localKeys.contains(name) && !localContextFunctionsKeys.contains(name))
144+
if (!localKeys.contains(name) && !localContextFunctionsKeys.contains(name)) {
143145
result.add(name);
146+
}
144147
}
145148
}
146149
return result.isEmpty() ? new String[] { NO_VALUES_FOUND } : result.toArray();
@@ -164,8 +167,9 @@ public void setDisplayKey(boolean k) {
164167
@Override
165168
@SuppressWarnings("unchecked")
166169
public String getText(Object element) {
167-
if (selectedContext == null)
170+
if (selectedContext == null) {
168171
return null;
172+
}
169173

170174
if (element instanceof Map.Entry) {
171175
Map.Entry<String, Object> mapEntry = (Map.Entry<String, Object>) element;
@@ -176,14 +180,16 @@ public String getText(Object element) {
176180
// value in value
177181
String txt = super.getText(element);
178182
if (displayKey) {
179-
if (txt.contains("#")) //$NON-NLS-1$
183+
if (txt.contains("#")) { //$NON-NLS-1$
180184
return INJECTED_IN_METHOD;
181-
else if (txt.contains("@")) //$NON-NLS-1$
185+
} else if (txt.contains("@")) { //$NON-NLS-1$
182186
return UPDATED_IN_CLASS;
183-
else
187+
} else {
184188
return INJECTED_IN_FIELD;
185-
} else
189+
}
190+
} else {
186191
return txt;
192+
}
187193
}
188194

189195
return displayKey ? super.getText(element) : null;
@@ -194,8 +200,9 @@ public Color getForeground(Object element) {
194200
// Return magenta color if the value could not be yet computed (for
195201
// context functions)
196202
String s = getText(element);
197-
if ((s != null) && s.startsWith(NO_VALUE_COULD_BE_COMPUTED))
203+
if ((s != null) && s.startsWith(NO_VALUE_COULD_BE_COMPUTED)) {
198204
return COLOR_IF_NOT_COMPUTED;
205+
}
199206

200207
// Return blue color if the string matches the search
201208
return (contextFilter.matchText(s)) ? COLOR_IF_FOUND : null;
@@ -210,8 +217,9 @@ public Font getFont(Object element) {
210217

211218
@Override
212219
public Image getImage(Object element) {
213-
if (!displayKey) // No image in value column, only in key column
220+
if (!displayKey) { // No image in value column, only in key column
214221
return null;
222+
}
215223

216224
if (element == LOCAL_VALUE_NODE) {
217225
return selectedContext == null ? null : imgReg.get(LOCAL_VARIABLE_IMG_KEY);
@@ -225,17 +233,18 @@ public Image getImage(Object element) {
225233
// value in value column
226234
String txt = super.getText(element);
227235

228-
if (txt.contains("#")) //$NON-NLS-1$
236+
if (txt.contains("#")) { //$NON-NLS-1$
229237
return imgReg.get(PUBLIC_METHOD_IMG_KEY);
230-
else if (txt.contains("@")) //$NON-NLS-1$
238+
} else if (txt.contains("@")) { //$NON-NLS-1$
231239
return imgReg.get(CONTEXT_FUNCTION_IMG_KEY);
232-
else
240+
} else {
233241
return imgReg.get(PUBLIC_FIELD_IMG_KEY);
242+
}
234243

235244
} else if (element instanceof Map.Entry) {
236-
if (isAContextKeyFunction(element))
245+
if (isAContextKeyFunction(element)) {
237246
return imgReg.get(CONTEXT_FUNCTION_IMG_KEY);
238-
else {
247+
} else {
239248
// It is a value. If it is injected somewhere, display the
240249
// inject image
241250
return hasChildren(element) ? imgReg.get(INJECT_IMG_KEY) : imgReg.get(VALUE_IN_CONTEXT_IMG_KEY);
@@ -262,11 +271,12 @@ public String getToolTipText(Object element) {
262271

263272
return Messages.ContextDataProvider_26 + fname;
264273
} else {
265-
if (hasChildren(element))
274+
if (hasChildren(element)) {
266275
return Messages.ContextDataProvider_27;
267-
else {
268-
if (element instanceof Map.Entry)
276+
} else {
277+
if (element instanceof Map.Entry) {
269278
return Messages.ContextDataProvider_28;
279+
}
270280
}
271281

272282
}
@@ -303,8 +313,9 @@ boolean isAContextKeyFunction(Object element) {
303313

304314
@Override
305315
public Object getParent(Object element) {
306-
if (element == LOCAL_VALUE_NODE || element == INHERITED_INJECTED_VALUE_NODE)
316+
if (element == LOCAL_VALUE_NODE || element == INHERITED_INJECTED_VALUE_NODE) {
307317
return null;
318+
}
308319

309320
// Not computed
310321
return null;

Diff for: ui/org.eclipse.pde.spy.context/src/org/eclipse/pde/spy/context/ContextSpyPart.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ public void widgetSelected(SelectionEvent e) {
135135
GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(filterText);
136136
filterText.setMessage(Messages.ContextSpyPart_7);
137137
filterText.setToolTipText(Messages.ContextSpyPart_8);
138-
if (lastFilterText != null)
138+
if (lastFilterText != null) {
139139
filterText.setText(lastFilterText);
140+
}
140141
contextFilter.setPattern(lastFilterText);
141142
filterText.addKeyListener(new KeyAdapter() {
142143
@Override
@@ -205,10 +206,11 @@ public void selectionChanged(SelectionChangedEvent event) {
205206

206207
/** Set the filter on context data part */
207208
public void setFilter() {
208-
if (showOnlyFilteredElements.isEnabled() && showOnlyFilteredElements.getSelection())
209+
if (showOnlyFilteredElements.isEnabled() && showOnlyFilteredElements.getSelection()) {
209210
contextDataPart.setFilter(contextFilter);
210-
else
211+
} else {
211212
contextDataPart.setFilter(null);
213+
}
212214
}
213215

214216
@PreDestroy

0 commit comments

Comments
 (0)