Skip to content

Commit 8d5c857

Browse files
eclipse-pde-botlaeubi
authored andcommitted
Perform clean code of ui/org.eclipse.pde.runtime
1 parent 12457f7 commit 8d5c857

12 files changed

+45
-100
lines changed

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/RegistryBrowser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ private void createTreeViewer(Composite parent) {
285285
@Override
286286
public int compare(Viewer viewer, Object e1, Object e2) {
287287
// let Comparables compare themselves
288-
if (e1 instanceof Comparable && e2 instanceof Comparable && e1.getClass().equals(e2.getClass())) {
289-
Comparable c1 = (Comparable) e1;
288+
if (e1 instanceof Comparable c1 && e2 instanceof Comparable && e1.getClass().equals(e2.getClass())) {
290289
Comparable c2 = (Comparable) e2;
291290

292291
return c1.compareTo(c2);

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/RegistryBrowserContentProvider.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public Object[] getElements(Object element) {
5151

5252
@Override
5353
public Object[] getChildren(Object element) {
54-
if (element instanceof RegistryModel) {
55-
RegistryModel model = (RegistryModel) element;
56-
54+
if (element instanceof RegistryModel model) {
5755
switch (fRegistryBrowser.getGroupBy()) {
5856
case (RegistryBrowser.BUNDLES) :
5957
return model.getBundles();
@@ -122,8 +120,7 @@ public Object[] getChildren(Object element) {
122120

123121
isInExtensionSet = false;
124122

125-
if (element instanceof Folder) {
126-
Folder folder = (Folder) element;
123+
if (element instanceof Folder folder) {
127124
isInExtensionSet = folder.getId() == Folder.F_EXTENSIONS;
128125
ModelObject[] objs = folder.getChildren();
129126
if (folder.getId() == Folder.F_USING_BUNDLES) {
@@ -142,8 +139,7 @@ public Object[] getChildren(Object element) {
142139
return ((ConfigurationElement) element).getElements();
143140
}
144141

145-
if (element instanceof ExtensionPoint) {
146-
ExtensionPoint extensionPoint = (ExtensionPoint) element;
142+
if (element instanceof ExtensionPoint extensionPoint) {
147143
Object[] objs = extensionPoint.getExtensions().toArray();
148144
return objs;
149145
}
@@ -152,9 +148,7 @@ public Object[] getChildren(Object element) {
152148
return ((ServiceName) element).getChildren();
153149
}
154150

155-
if (element instanceof ServiceRegistration) {
156-
ServiceRegistration service = (ServiceRegistration) element;
157-
151+
if (element instanceof ServiceRegistration service) {
158152
List<Folder> folders = new ArrayList<>();
159153

160154
if (service.getProperties().length > 0) {

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/RegistryBrowserLabelProvider.java

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ private boolean isProxyService(ServiceRegistration reg) {
151151

152152
@Override
153153
public Image getImage(Object element) {
154-
if (element instanceof Bundle) {
155-
Bundle bundle = (Bundle) element;
156-
154+
if (element instanceof Bundle bundle) {
157155
if (bundle.getFragmentHost() != null) {
158156
return fFragmentImage;
159157
}
@@ -168,24 +166,21 @@ public Image getImage(Object element) {
168166
}
169167
}
170168

171-
if (element instanceof ServiceName) {
172-
ServiceName serviceName = (ServiceName) element;
169+
if (element instanceof ServiceName serviceName) {
173170
if (isProxyService(serviceName.getServiceReference())) {
174171
return fRemoteServiceProxyImage;
175172
}
176173
return fServiceImage;
177174
}
178175

179-
if (element instanceof ServiceRegistration) {
180-
ServiceRegistration reg = (ServiceRegistration) element;
176+
if (element instanceof ServiceRegistration reg) {
181177
if (isProxyService(reg)) {
182178
return fRemoteServiceProxyImage;
183179
}
184180
return fPluginImage;
185181
}
186182

187-
if (element instanceof Property) {
188-
Property property = (Property) element;
183+
if (element instanceof Property property) {
189184
// special handling for property objectClass
190185
if (property.getName().equals(Constants.OBJECTCLASS)) {
191186
return PDERuntimePluginImages.get(PDERuntimePluginImages.IMG_CLASS_OBJ);
@@ -233,9 +228,7 @@ public Image getImage(Object element) {
233228
return fExtensionPointImage;
234229
}
235230

236-
if (element instanceof BundlePrerequisite) {
237-
BundlePrerequisite prereq = (BundlePrerequisite) element;
238-
231+
if (element instanceof BundlePrerequisite prereq) {
239232
if (prereq.isPackage()) {
240233
return fPackageImage;
241234
}
@@ -251,8 +244,7 @@ public Image getImage(Object element) {
251244
return fGenericTagImage;
252245
}
253246

254-
if (element instanceof Attribute) {
255-
Attribute attr = (Attribute) element;
247+
if (element instanceof Attribute attr) {
256248
if (Attribute.F_LOCATION.equals(attr.getName())) {
257249
return fLocationImage;
258250
}
@@ -267,9 +259,7 @@ public Image getImage(Object element) {
267259

268260
protected StyledString getStyledText(Object element) {
269261

270-
if (element instanceof Bundle) {
271-
Bundle bundle = ((Bundle) element);
272-
262+
if (element instanceof Bundle bundle) {
273263
StyledString sb = new StyledString(bundle.getSymbolicName());
274264
String version = bundle.getVersion();
275265
if (version != null) {
@@ -286,8 +276,7 @@ protected StyledString getStyledText(Object element) {
286276
return sb;
287277
}
288278

289-
if (element instanceof ServiceRegistration) {
290-
ServiceRegistration ref = (ServiceRegistration) element;
279+
if (element instanceof ServiceRegistration ref) {
291280
String identifier = " (id=" + ref.getId() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
292281

293282
StyledString ss = new StyledString();
@@ -370,9 +359,7 @@ protected StyledString getStyledText(Object element) {
370359
return new StyledString(NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_contributedBy, contributor));
371360

372361
}
373-
if (element instanceof ExtensionPoint) {
374-
ExtensionPoint extPoint = (ExtensionPoint) element;
375-
362+
if (element instanceof ExtensionPoint extPoint) {
376363
StyledString ss = new StyledString(extPoint.getUniqueIdentifier());
377364
String name = extPoint.getLabel();
378365
if (name != null && name.length() > 0) {
@@ -383,9 +370,7 @@ protected StyledString getStyledText(Object element) {
383370

384371
return ss;
385372
}
386-
if (element instanceof BundlePrerequisite) {
387-
BundlePrerequisite prereq = (BundlePrerequisite) element;
388-
373+
if (element instanceof BundlePrerequisite prereq) {
389374
StyledString ss = new StyledString(prereq.getName());
390375

391376
String version = prereq.getVersion();
@@ -406,16 +391,14 @@ protected StyledString getStyledText(Object element) {
406391
if (element instanceof ConfigurationElement) {
407392
return new StyledString(((ConfigurationElement) element).getName());
408393
}
409-
if (element instanceof Attribute) {
410-
Attribute attribute = (Attribute) element;
394+
if (element instanceof Attribute attribute) {
411395
if (Attribute.F_BUNDLE.equals(attribute.getName())) {
412396
return new StyledString(attribute.getValue());
413397
}
414398

415399
return new StyledString(attribute.getName() + " = " + attribute.getValue()); //$NON-NLS-1$
416400
}
417-
if (element instanceof Property) {
418-
Property property = (Property) element;
401+
if (element instanceof Property property) {
419402
return new StyledString(property.getName() + " = " + property.getValue()); //$NON-NLS-1$
420403
}
421404

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/RegistryBrowserModelChangeListener.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,11 @@ private Object getTopLevelElement(Object object) {
6363
case RegistryBrowser.BUNDLES:
6464
if (object instanceof Bundle) {
6565
return object;
66-
} else if (object instanceof ExtensionPoint) {
67-
ExtensionPoint ext = (ExtensionPoint) object;
66+
} else if (object instanceof ExtensionPoint ext) {
6867
return ext.getContributor();
69-
} else if (object instanceof Extension) {
70-
Extension ext = (Extension) object;
68+
} else if (object instanceof Extension ext) {
7169
return ext.getContributor();
72-
} else if (object instanceof ServiceRegistration) {
73-
ServiceRegistration reg = (ServiceRegistration) object;
74-
70+
} else if (object instanceof ServiceRegistration reg) {
7571
Bundle[] bundles = reg.getUsingBundles();
7672
if (bundles.length == 0) {
7773
return reg.getBundle();
@@ -87,14 +83,12 @@ private Object getTopLevelElement(Object object) {
8783
case RegistryBrowser.EXTENSION_REGISTRY:
8884
if (object instanceof ExtensionPoint) {
8985
return object;
90-
} else if (object instanceof Extension) {
91-
Extension ext = (Extension) object;
86+
} else if (object instanceof Extension ext) {
9287
return ext.getExtensionPoint();
9388
}
9489
break;
9590
case RegistryBrowser.SERVICES:
96-
if (object instanceof ServiceRegistration) {
97-
ServiceRegistration service = (ServiceRegistration) object;
91+
if (object instanceof ServiceRegistration service) {
9892
return service.getName();
9993
} else if (object instanceof Bundle) {
10094
return ((Bundle) object).getServicesInUse();

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/ServiceRegistration.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ public Property getProperty(String name) {
104104
public static String toString(Object value) {
105105
if (value == null) {
106106
return ""; //$NON-NLS-1$
107-
} else if (value instanceof CharSequence) {
108-
CharSequence charSequence = (CharSequence) value;
107+
} else if (value instanceof CharSequence charSequence) {
109108
return charSequence.toString();
110109
} else if (value instanceof Object[]) {
111110
StringBuilder buff = new StringBuilder();
@@ -120,8 +119,7 @@ public static String toString(Object value) {
120119
public static void appendString(StringBuilder buff, Object value) {
121120
if (value == null) {
122121
// ignore
123-
} else if (value instanceof Object[]) {
124-
Object[] objects = (Object[]) value;
122+
} else if (value instanceof Object[] objects) {
125123
buff.append("["); //$NON-NLS-1$
126124
for (int o = 0; o < objects.length; o++) {
127125
Object object = objects[o];

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/spy/sections/ActiveDialogPageSection.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ public void build(ScrolledForm form, SpyFormToolkit toolkit, ExecutionEvent even
4444
}
4545
Class<?> clazz = object.getClass();
4646

47-
if (object instanceof IPageChangeProvider) {
48-
IPageChangeProvider pageChangeProvider = (IPageChangeProvider) object;
47+
if (object instanceof IPageChangeProvider pageChangeProvider) {
4948
Object selectedPage = pageChangeProvider.getSelectedPage();
5049
if (selectedPage != null) {
5150
Section section = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR);
5251
section.clientVerticalSpacing = 9;
53-
if (selectedPage instanceof IDialogPage) {
54-
IDialogPage page = (IDialogPage) selectedPage;
52+
if (selectedPage instanceof IDialogPage page) {
5553
clazz = page.getClass();
5654
section.setText(NLS.bind(PDERuntimeMessages.SpyDialog_activeDialogPageSection_title, page.getTitle()));
5755

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/spy/sections/ActiveFormEditorSection.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ public class ActiveFormEditorSection implements ISpySection {
4242
@Override
4343
public void build(ScrolledForm form, SpyFormToolkit toolkit, ExecutionEvent event) {
4444
final IWorkbenchPart part = HandlerUtil.getActivePart(event);
45-
if (!(part instanceof FormEditor)) {
45+
if (!(part instanceof FormEditor multiEditor)) {
4646
return;
4747
}
48-
FormEditor multiEditor = (FormEditor) part;
49-
5048
Shell shell = HandlerUtil.getActiveShell(event);
5149
Object object = shell.getData();
5250
if (object == null) {
@@ -105,8 +103,7 @@ private SectionPart getActiveFormSection(IFormPage activePage) {
105103

106104
//find section which controls contains actual focus control (also recursively)
107105
for (IFormPart formPart : form.getParts()) {
108-
if (formPart instanceof SectionPart) {
109-
SectionPart formSection = (SectionPart) formPart;
106+
if (formPart instanceof SectionPart formSection) {
110107
Control[] sectionWidgets = formSection.getSection().getChildren();
111108
for (Control widget : sectionWidgets) {
112109
if (contains(widget, focusedControl)) {
@@ -126,9 +123,7 @@ private boolean contains(Control whereToLook, Control whatToFind) {
126123
return false;
127124
}
128125

129-
if (whereToLook instanceof Composite) {
130-
Composite compositeWhereToLook = (Composite) whereToLook;
131-
126+
if (whereToLook instanceof Composite compositeWhereToLook) {
132127
for (Control child : compositeWhereToLook.getChildren()) {
133128
if (contains(child, whatToFind)) {
134129
return true;

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/spy/sections/ActiveHelpSection.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ public void build(ScrolledForm form, SpyFormToolkit toolkit, ExecutionEvent even
6262
StringBuilder helpBuffer = new StringBuilder();
6363
// process help
6464
// TODO we need to make this cleaner... help processing is complicated atm
65-
if (object instanceof PreferenceDialog) {
66-
PreferenceDialog dialog = (PreferenceDialog) object;
65+
if (object instanceof PreferenceDialog dialog) {
6766
IPreferencePage page = (IPreferencePage) dialog.getSelectedPage();
6867
processHelp(page.getControl().getShell(), helpBuffer);
6968
processChildren(page.getControl(), helpBuffer);
70-
} else if (object instanceof Dialog) {
71-
Dialog dialog = (Dialog) object;
69+
} else if (object instanceof Dialog dialog) {
7270
processChildren(dialog.getShell(), helpBuffer);
7371
} else {
7472
helpBuffer.append(processControlHelp(event, toolkit));
@@ -108,8 +106,7 @@ private void processHelp(Widget widget, StringBuilder buffer) {
108106

109107
private void processChildren(Control control, StringBuilder buffer) {
110108
processHelp(control, buffer);
111-
if (control instanceof Composite) {
112-
Composite composite = (Composite) control;
109+
if (control instanceof Composite composite) {
113110
Control[] controls = composite.getChildren();
114111
for (Control child : controls) {
115112
processChildren(child, buffer);
@@ -134,29 +131,25 @@ private String processControlHelp(ExecutionEvent event, SpyFormToolkit toolkit)
134131
Shell shell = null;
135132
Control control = null;
136133

137-
if (part instanceof IEditorPart) {
138-
IEditorPart editorPart = (IEditorPart) part;
134+
if (part instanceof IEditorPart editorPart) {
139135
shell = editorPart.getSite().getShell();
140136

141137
for (int j = 0; j < window.getActivePage().getEditorReferences().length; j++) {
142138
IEditorReference er = window.getActivePage().getEditorReferences()[j];
143139
if (er.getId().equals(editorPart.getEditorSite().getId())) {
144-
if (er instanceof org.eclipse.ui.internal.WorkbenchPartReference) {
145-
org.eclipse.ui.internal.WorkbenchPartReference wpr = (org.eclipse.ui.internal.WorkbenchPartReference) er;
140+
if (er instanceof org.eclipse.ui.internal.WorkbenchPartReference wpr) {
146141
control = wpr.getPane().getControl();
147142
shell = null;
148143
break;
149144
}
150145
}
151146
}
152-
} else if (part instanceof ViewPart) {
153-
ViewPart viewPart = (ViewPart) part;
147+
} else if (part instanceof ViewPart viewPart) {
154148
shell = viewPart.getSite().getShell();
155149
for (int j = 0; j < window.getActivePage().getViewReferences().length; j++) {
156150
IViewReference vr = window.getActivePage().getViewReferences()[j];
157151
if (vr.getId().equals(viewPart.getViewSite().getId())) {
158-
if (vr instanceof org.eclipse.ui.internal.WorkbenchPartReference) {
159-
org.eclipse.ui.internal.WorkbenchPartReference wpr = (org.eclipse.ui.internal.WorkbenchPartReference) vr;
152+
if (vr instanceof org.eclipse.ui.internal.WorkbenchPartReference wpr) {
160153
control = wpr.getPane().getControl();
161154
shell = null;
162155
break;
@@ -182,8 +175,7 @@ private String processControlHelp(ExecutionEvent event, SpyFormToolkit toolkit)
182175
} else {
183176
buffer.append(toolkit.createHelpIdentifierSection(control));
184177
}
185-
if (control instanceof Composite) {
186-
Composite parent = (Composite) control;
178+
if (control instanceof Composite parent) {
187179
for (int i = 0; i < parent.getChildren().length; i++) {
188180
processChildren(parent.getChildren()[i], buffer);
189181
}

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/spy/sections/ActiveMenuSection.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public void build(ScrolledForm form, SpyFormToolkit toolkit, Event event) {
6767

6868
StringBuilder buffer = new StringBuilder();
6969
buffer.append("<form>"); //$NON-NLS-1$
70-
if (object instanceof IContributionItem) {
71-
IContributionItem item = (IContributionItem) object;
70+
if (object instanceof IContributionItem item) {
7271
String id = item.getId();
7372
if (id != null) {
7473
buffer.append(toolkit.createIdentifierSection(text, PDERuntimeMessages.ActiveMenuSection_0, new String[] {id}));
@@ -113,17 +112,14 @@ private void createLocationURI(SpyFormToolkit toolkit, Object object, FormText t
113112
@SuppressWarnings("restriction")
114113
private void scan(IContributionItem item, StringBuilder buffer, SpyFormToolkit toolkit, FormText text) {
115114
// check for action set information
116-
if (item instanceof org.eclipse.ui.internal.IActionSetContributionItem) {
117-
org.eclipse.ui.internal.IActionSetContributionItem actionItem = (org.eclipse.ui.internal.IActionSetContributionItem) item;
115+
if (item instanceof org.eclipse.ui.internal.IActionSetContributionItem actionItem) {
118116
buffer.append(toolkit.createIdentifierSection(text, PDERuntimeMessages.ActiveMenuSection_1, new String[] {actionItem.getActionSetId()}));
119117
}
120118
if (item instanceof ActionContributionItem) {
121119
createActionContributionItemText(item, buffer, toolkit, text);
122-
} else if (item instanceof SubContributionItem) {
123-
SubContributionItem subItem = (SubContributionItem) item;
120+
} else if (item instanceof SubContributionItem subItem) {
124121
scan(subItem.getInnerItem(), buffer, toolkit, text); // recurse
125-
} else if (item instanceof CommandContributionItem) { // TODO... this is hard...
126-
CommandContributionItem contributionItem = (CommandContributionItem) item;
122+
} else if (item instanceof CommandContributionItem contributionItem) { // TODO... this is hard...
127123
Command command = contributionItem.getCommand().getCommand();
128124
buffer.append(toolkit.createClassSection(text, PDERuntimeMessages.ActiveMenuSection_2, command.getClass()));
129125
buffer.append(toolkit.createClassSection(text, PDERuntimeMessages.ActiveMenuSection_3,
@@ -141,8 +137,7 @@ private void createActionContributionItemText(Object object, StringBuilder buffe
141137
buffer.append(toolkit.createIdentifierSection(text, PDERuntimeMessages.ActiveMenuSection_4, new String[] {action.getActionDefinitionId()}));
142138
}
143139

144-
if (action instanceof org.eclipse.ui.internal.PluginAction) {
145-
org.eclipse.ui.internal.PluginAction pluginAction = (org.eclipse.ui.internal.PluginAction) action;
140+
if (action instanceof org.eclipse.ui.internal.PluginAction pluginAction) {
146141
Class<?> clazz = pluginAction.getClass();
147142
createActionContributionItemText(object, buffer, toolkit, text, clazz, pluginAction);
148143

0 commit comments

Comments
 (0)