Skip to content

Commit 5f3d828

Browse files
eclipse-pde-botmerks
authored andcommitted
Perform clean code of e4tools/bundles/org.eclipse.e4.tools.emf.ui
1 parent 4742f4a commit 5f3d828

31 files changed

+85
-164
lines changed

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/MemoryTransfer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ public void javaToNative(Object object, TransferData transferData) {
5757
@Override
5858
public Object nativeToJava(TransferData transferData) {
5959
byte[] bytes = (byte[]) super.nativeToJava(transferData);
60-
if (bytes == null)
60+
if (bytes == null) {
6161
return null;
62+
}
6263

6364
if (new String(bytes).equals(uid)) {
6465
return object;

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/Util.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public static final boolean isImport(EObject object) {
7474

7575
public static final void addClasses(EPackage ePackage, List<FeatureClass> list) {
7676
for (final EClassifier c : ePackage.getEClassifiers()) {
77-
if (c instanceof EClass) {
78-
final EClass eclass = (EClass) c;
77+
if (c instanceof final EClass eclass) {
7978
if (eclass != ApplicationPackageImpl.Literals.APPLICATION && !eclass.isAbstract()
8079
&& !eclass.isInterface()
8180
&& eclass.getEAllSuperTypes().contains(ApplicationPackageImpl.Literals.APPLICATION_ELEMENT)) {
@@ -144,8 +143,7 @@ public static List<InternalPackage> loadPackages() {
144143
final InternalPackage iePackage = new InternalPackage(ePackage);
145144
boolean found = false;
146145
for (final EClassifier cl : ePackage.getEClassifiers()) {
147-
if (cl instanceof EClass) {
148-
final EClass eClass = (EClass) cl;
146+
if (cl instanceof final EClass eClass) {
149147
if (eClass.getEAllSuperTypes().contains(ApplicationPackageImpl.Literals.APPLICATION_ELEMENT)) {
150148
if (!eClass.isInterface() && !eClass.isAbstract()) {
151149
found = true;

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ComponentLabelProvider.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ public void dispose() {
8787

8888
@Override
8989
public StyledString getStyledText(Object element) {
90-
if (element instanceof EObject) {
90+
if (element instanceof final EObject o) {
9191

92-
final EObject o = (EObject) element;
9392
final AbstractComponentEditor<?> elementEditor = editor.getEditor(o.eClass());
9493
if (elementEditor != null) {
9594
String label = elementEditor.getLabel(o);
@@ -124,8 +123,7 @@ public StyledString getStyledText(Object element) {
124123

125124
@Override
126125
public Image getImage(Object element) {
127-
if (element instanceof EObject) {
128-
final EObject o = (EObject) element;
126+
if (element instanceof final EObject o) {
129127
final AbstractComponentEditor<?> elementEditor = editor.getEditor(o.eClass());
130128
if (elementEditor != null) {
131129
return elementEditor.getImage(element);

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,8 +1212,7 @@ private void registerContributedEditorTabs() {
12121212

12131213
try {
12141214
final Object o = el.createExecutableExtension("contribution"); //$NON-NLS-1$
1215-
if (o instanceof AbstractElementEditorContribution) {
1216-
final AbstractElementEditorContribution contribution = (AbstractElementEditorContribution) o;
1215+
if (o instanceof final AbstractElementEditorContribution contribution) {
12171216
ContextInjectionFactory.inject(contribution, context);
12181217
final Class<?> contribElem = contribution.getContributableTo();
12191218
if (contribElem == null) {
@@ -1620,8 +1619,7 @@ private void handleStructurePaste() {
16201619

16211620
List<EClass> targetChildrenClasses = new ArrayList<>();
16221621

1623-
if (container instanceof MStringModelFragment) {
1624-
MStringModelFragment stringModelFragment = (MStringModelFragment) container;
1622+
if (container instanceof MStringModelFragment stringModelFragment) {
16251623
EClass targetType = StringModelFragment.findContainerType(stringModelFragment);
16261624
if (targetType != null) {
16271625
EStructuralFeature targetFeature = targetType
@@ -1831,10 +1829,9 @@ protected DropListener(Viewer viewer, EditingDomain domain) {
18311829

18321830
@Override
18331831
public boolean performDrop(Object data) {
1834-
if (!(data instanceof Object[])) {
1832+
if (!(data instanceof final Object[] dropDataArray)) {
18351833
return false;
18361834
}
1837-
final Object[] dropDataArray = (Object[]) data;
18381835
for (final Object object : dropDataArray) {
18391836
final boolean result = performSingleDrop(object);
18401837
if (!result) {
@@ -2052,8 +2049,7 @@ private boolean isValidTarget(Object target, Object instance, boolean isIndex) {
20522049
}
20532050

20542051
}
2055-
} else if (target instanceof EObject) {
2056-
final EObject eObj = (EObject) target;
2052+
} else if (target instanceof final EObject eObj) {
20572053
for (final EStructuralFeature f : eObj.eClass().getEAllStructuralFeatures()) {
20582054
final EClassifier cl = ModelUtils.getTypeArgument(eObj.eClass(), f.getEGenericType());
20592055
if (cl.isInstance(instance)) {
@@ -2072,9 +2068,9 @@ private boolean isValidTarget(Object target, Object instance, boolean isIndex) {
20722068
* @return a representative string for the object or 'Object' if nothing found
20732069
*/
20742070
private String getObjectNameForCommand(Object data) {
2075-
String clname = (data instanceof ApplicationElementImpl) ? ((ApplicationElementImpl) data).eClass().getName()
2071+
String clname = (data instanceof ApplicationElementImpl a) ? a.eClass().getName()
20762072
: "Object"; //$NON-NLS-1$
2077-
String dname = (data instanceof MUILabel) ? ((MUILabel) data).getLabel() : ""; //$NON-NLS-1$
2073+
String dname = (data instanceof MUILabel m) ? m.getLabel() : ""; //$NON-NLS-1$
20782074
return clname + " " + dname; //$NON-NLS-1$
20792075
}
20802076

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,7 @@ public static <M> void createTextField(Composite parent, String label, String to
438438
controlDecoration.show();
439439
return ValidationStatus.warning(decorationText);
440440
}
441-
if (value instanceof String) {
442-
final String text = (String) value;
441+
if (value instanceof final String text) {
443442
if (text.trim().length() == 0) {
444443
controlDecoration.show();
445444
return getValidationStatus(decorationType, decorationText);
@@ -580,16 +579,14 @@ public String getText(Object element) {
580579
final EObject o = (EObject) element;
581580
final String rv = o.eClass().getName();
582581

583-
if (element instanceof MUILabel) {
584-
final MUILabel label = (MUILabel) element;
582+
if (element instanceof final MUILabel label) {
585583
if (!Util.isNullOrEmpty(label.getLabel())) {
586584
return rv + " - " + label.getLabel().trim(); //$NON-NLS-1$
587585
}
588586

589587
}
590588

591-
if (element instanceof MApplicationElement) {
592-
final MApplicationElement appEl = (MApplicationElement) element;
589+
if (element instanceof final MApplicationElement appEl) {
593590
if (!Util.isNullOrEmpty(appEl.getElementId())) {
594591
return rv + " - " + appEl.getElementId(); //$NON-NLS-1$
595592
}
@@ -704,38 +701,6 @@ private static void handleAddText(AbstractComponentEditor<? extends MApplication
704701
}
705702
}
706703

707-
// This method is left in for reference purposes
708-
@SuppressWarnings("unused")
709-
private static void handleReplaceText(AbstractComponentEditor<? extends MApplicationElement> editor,
710-
EStructuralFeature feature, Text tagText, TableViewer viewer) {
711-
if (tagText.getText().trim().length() > 0) {
712-
if (!viewer.getSelection().isEmpty()) {
713-
final String[] tags = tagText.getText().split(";"); //$NON-NLS-1$
714-
for (int i = 0; i < tags.length; i++) {
715-
tags[i] = tags[i].trim();
716-
}
717-
718-
final MApplicationElement appEl = editor.getMaster().getValue();
719-
final EObject el = (EObject) editor.getMaster().getValue();
720-
final List<?> ids = ((IStructuredSelection) viewer.getSelection()).toList();
721-
final Object curVal = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
722-
final EObject container = (EObject) editor.getMaster().getValue();
723-
final List<?> l = (List<?>) container.eGet(feature);
724-
final int idx = l.indexOf(curVal);
725-
if (idx >= 0) {
726-
final Command cmdRemove = RemoveCommand.create(editor.getEditingDomain(), el, feature, ids);
727-
final Command cmdInsert = AddCommand.create(editor.getEditingDomain(), appEl, feature,
728-
Arrays.asList(tags), idx);
729-
if (cmdRemove.canExecute() && cmdInsert.canExecute()) {
730-
editor.getEditingDomain().getCommandStack().execute(cmdRemove);
731-
editor.getEditingDomain().getCommandStack().execute(cmdInsert);
732-
}
733-
tagText.setText(""); //$NON-NLS-1$
734-
}
735-
}
736-
}
737-
}
738-
739704
public static <M> void createCheckBox(Composite parent, String label, IObservableValue<M> master,
740705
EMFDataBindingContext context, IWidgetValueProperty<Button, Boolean> selectionProp,
741706
IValueProperty<? super M, Boolean> modelProp) {

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ public void widgetSelected(SelectionEvent e) {
300300
combo.setLabelProvider(new LabelProvider() {
301301
@Override
302302
public String getText(Object element) {
303-
if (element instanceof EClass) {
304-
final EClass eClass = (EClass) element;
303+
if (element instanceof final EClass eClass) {
305304
return eClass.getName();
306305
}
307306

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuItemEditor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,7 @@ public Boolean convert(ItemType fromObject) {
298298
combo.setLabelProvider(new LabelProvider() {
299299
@Override
300300
public String getText(Object element) {
301-
if (element instanceof EClass) {
302-
final EClass eClass = (EClass) element;
301+
if (element instanceof final EClass eClass) {
303302
return eClass.getName();
304303
}
305304

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ModelFragmentsEditor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ public int compare(Viewer viewer, Object e1, Object e2) {
213213

214214
public void addClasses(EPackage ePackage, List<FeatureClass> list) {
215215
for (final EClassifier c : ePackage.getEClassifiers()) {
216-
if (c instanceof EClass) {
217-
final EClass eclass = (EClass) c;
216+
if (c instanceof final EClass eclass) {
218217
if (eclass != ApplicationPackageImpl.Literals.APPLICATION && !eclass.isAbstract()
219218
&& !eclass.isInterface()
220219
&& eclass.getEAllSuperTypes().contains(ApplicationPackageImpl.Literals.APPLICATION_ELEMENT)) {

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PlaceholderEditor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ public MUIElement convert(String fromObject) {
211211
public String convert(MUIElement fromObject) {
212212
if (fromObject != null) {
213213
final EObject o = (EObject) fromObject;
214-
if (o instanceof MUILabel) {
215-
final MUILabel label = (MUILabel) o;
214+
if (o instanceof final MUILabel label) {
216215
final String l = getLocalizedLabel(label);
217216
if (!Util.isNullOrEmpty(l)) {
218217
return o.eClass().getName() + " - " + l; //$NON-NLS-1$

e4tools/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ToolItemEditor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ public Boolean convert(ItemType fromObject) {
318318
combo.setLabelProvider(new LabelProvider() {
319319
@Override
320320
public String getText(Object element) {
321-
if (element instanceof EClass) {
322-
final EClass eClass = (EClass) element;
321+
if (element instanceof final EClass eClass) {
323322
return eClass.getName();
324323
}
325324

0 commit comments

Comments
 (0)