Skip to content

Commit

Permalink
Don't use unconditional pattern in instanceof for non-null checks
Browse files Browse the repository at this point in the history
- Can't do something like this in Java 17: if(object.toString() instanceof String s)

- This is allowed in Java 21

- In Eclipse 4.35+ these give an "Expression type cannot be a subtype of the Pattern type" compile error. Was OK in earlier versions of Eclipse.

- See eclipse-jdt/eclipse.jdt.core#3478
  • Loading branch information
Phillipus committed Mar 8, 2025
1 parent 0645fe8 commit 6ba5d66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.eclipse.ui.actions.RetargetAction;

import com.archimatetool.editor.diagram.commands.TextAlignmentCommand;
import com.archimatetool.editor.ui.factory.IObjectUIProvider;
import com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider;
import com.archimatetool.editor.ui.factory.ObjectUIFactory;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.ILockable;
Expand Down Expand Up @@ -117,7 +117,7 @@ private List<ITextAlignment> getValidSelectedObjects() {
for(Object object : getSelectedObjects()) {
if(object instanceof EditPart editPart && editPart.getModel() instanceof ITextAlignment textAlignmentObject
&& !(textAlignmentObject instanceof ILockable lockable && lockable.isLocked())
&& ObjectUIFactory.INSTANCE.getProvider(textAlignmentObject) instanceof IObjectUIProvider provider
&& ObjectUIFactory.INSTANCE.getProvider(textAlignmentObject) instanceof IGraphicalObjectUIProvider provider
&& provider.shouldExposeFeature(IArchimatePackage.Literals.TEXT_ALIGNMENT__TEXT_ALIGNMENT.getName())) {
list.add(textAlignmentObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.eclipse.ui.actions.RetargetAction;

import com.archimatetool.editor.diagram.commands.TextPositionCommand;
import com.archimatetool.editor.ui.factory.IObjectUIProvider;
import com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider;
import com.archimatetool.editor.ui.factory.ObjectUIFactory;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.ILockable;
Expand Down Expand Up @@ -117,7 +117,7 @@ private List<ITextPosition> getValidSelectedObjects() {
for(Object object : getSelectedObjects()) {
if(object instanceof EditPart editPart && editPart.getModel() instanceof ITextPosition textPositionObject
&& !(textPositionObject instanceof ILockable lockable && lockable.isLocked())
&& ObjectUIFactory.INSTANCE.getProvider(textPositionObject) instanceof IObjectUIProvider provider
&& ObjectUIFactory.INSTANCE.getProvider(textPositionObject) instanceof IGraphicalObjectUIProvider provider
&& provider.shouldExposeFeature(IArchimatePackage.Literals.TEXT_POSITION__TEXT_POSITION.getName())) {
list.add(textPositionObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ private boolean doSync() {
}

/**
* Update with the last known selection
* Update with the last known selections
*/
private void updateSelection() {
// In this case we have created a new TreeViewer and synchroniser, so create a new selection event
if(lastSelectionEvent == null) {
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if(activeEditor instanceof IDiagramModelEditor editor && editor.getGraphicalViewer() instanceof GraphicalViewer viewer) { // check this is not a zombie editor part
selectionChanged(new SelectionChangedEvent(viewer, viewer.getSelection()));
if(activeEditor instanceof IDiagramModelEditor editor && editor.getGraphicalViewer() != null) { // check this is not a zombie editor part
selectionChanged(new SelectionChangedEvent(editor.getGraphicalViewer(), editor.getGraphicalViewer().getSelection()));
}
}
else {
Expand Down

0 comments on commit 6ba5d66

Please sign in to comment.