diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/LocaleChangeServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/LocaleChangeServiceImpl.java index d8f814bf027..350d060fe0a 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/LocaleChangeServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/LocaleChangeServiceImpl.java @@ -110,8 +110,7 @@ protected void updateLocalization(List children) { updateLocalization(((MElementContainer) element).getChildren()); } - if (element instanceof MWindow) { - MWindow window = (MWindow) element; + if (element instanceof MWindow window) { MMenu mainMenu = window.getMainMenu(); if (mainMenu != null) { mainMenu.updateLocalization(); @@ -132,8 +131,7 @@ protected void updateLocalization(List children) { updateLocalization(((MPerspective) element).getWindows()); } - if (element instanceof MPart) { - MPart mPart = (MPart) element; + if (element instanceof MPart mPart) { MToolBar toolbar = mPart.getToolbar(); if (toolbar != null && toolbar.getChildren() != null) { toolbar.updateLocalization(); diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ActiveChildLookupFunction.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ActiveChildLookupFunction.java index afd24b8ff77..5f604283f31 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ActiveChildLookupFunction.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ActiveChildLookupFunction.java @@ -19,8 +19,8 @@ public class ActiveChildLookupFunction extends ContextFunction { - private String localVar; - private String var; + private final String localVar; + private final String var; public ActiveChildLookupFunction(String var, String localVar) { this.var = var; diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ActivePartLookupFunction.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ActivePartLookupFunction.java index 05064f2fa5c..d7100f447d1 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ActivePartLookupFunction.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ActivePartLookupFunction.java @@ -42,11 +42,13 @@ public Object compute(IEclipseContext context, String contextKey) { return null; } MPart part = current.getActiveLeaf().get(MPart.class); - if (part == null) + if (part == null) { return null; + } MUIElement parent = part.getCurSharedRef() != null ? part.getCurSharedRef().getParent() : part.getParent(); - if (parent == null) + if (parent == null) { return part; + } List parentTags = parent.getTags(); if (parentTags.contains(IPresentationEngine.MINIMIZED) && !parentTags.contains(IPresentationEngine.ACTIVE) && !part.getTags().contains(IPresentationEngine.ACTIVE)) { diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java index 134a77c48b3..d7eaaa26603 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java @@ -38,9 +38,9 @@ public class ApplicationPartServiceImpl implements EPartService { private static final Supplier NO_VALID_PARTSERVICE = () -> new IllegalStateException( "No valid PartService can be acquired from the current context"); //$NON-NLS-1$ - private MApplication application; + private final MApplication application; - private EModelService modelService; + private final EModelService modelService; @Inject ApplicationPartServiceImpl(MApplication application, EModelService modelService) { diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/BundleFinder.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/BundleFinder.java index 84e7c03c642..98762cc20da 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/BundleFinder.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/BundleFinder.java @@ -49,8 +49,9 @@ final class BundleFinder implements BundleTrackerCustomizer> { */ public Bundle findBundle(String symbolicName) { List bundlesWithSameSymName = trackedBundles.get(symbolicName); - if (bundlesWithSameSymName == null) + if (bundlesWithSameSymName == null) { return null; + } List snapshot = new ArrayList<>(bundlesWithSameSymName); diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ConfigurationElementAdapter.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ConfigurationElementAdapter.java index 0ed60bf2354..389409de8b8 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ConfigurationElementAdapter.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ConfigurationElementAdapter.java @@ -54,12 +54,14 @@ public Object getProperty(Object element, String id) { String constructedName = Util.ZERO_LENGTH_STRING; if (nameVal != null) { constructedName = nameVal; - if (idVal != null) + if (idVal != null) { constructedName += " [" + idVal + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } } else if (idVal != null) { constructedName = idVal; - } else + } else { constructedName = ice.getName(); + } return constructedName; } else if (CLASS_IMPL.equals(id)) { diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java index f7a18fb8d84..c20de801f7b 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java @@ -196,10 +196,9 @@ static boolean isFiltered(MMenu menuModel, MMenuContribution menuContribution, } public static void collectInfo(ExpressionInfo info, MExpression exp) { - if (!(exp instanceof MCoreExpression)) { + if (!(exp instanceof MCoreExpression expr)) { return; } - MCoreExpression expr = (MCoreExpression) exp; Expression ref = null; if (expr.getCoreExpression() instanceof Expression) { ref = (Expression) expr.getCoreExpression(); @@ -232,8 +231,7 @@ public static boolean isVisible(MTrimContribution contribution, ExpressionContex } public static boolean isVisible(MExpression exp, final ExpressionContext eContext) { - if (exp instanceof MCoreExpression) { - MCoreExpression coreExpression = (MCoreExpression) exp; + if (exp instanceof MCoreExpression coreExpression) { return isCoreExpressionVisible(coreExpression, eContext); } else if (exp instanceof MImperativeExpression) { return isImperativeExpressionVisible((MImperativeExpression) exp, eContext); @@ -472,10 +470,10 @@ public static MCommand getCommandById(MApplication app, String cmdId) { static class Key { private int tag = -1; private int hc = -1; - private String parentId; - private String position; - private MCoreExpression vexp; - private Object factory; + private final String parentId; + private final String position; + private final MCoreExpression vexp; + private final Object factory; public Key(String parentId, String position, List tags, MCoreExpression vexp, Object factory) { @@ -500,10 +498,9 @@ int getSchemeTag() { @Override public boolean equals(Object obj) { - if (!(obj instanceof Key)) { + if (!(obj instanceof Key other)) { return false; } - Key other = (Key) obj; Object exp1 = vexp == null ? null : vexp.getCoreExpression(); Object exp2 = other.vexp == null ? null : other.vexp.getCoreExpression(); return Objects.equals(parentId, other.parentId) && Objects.equals(position, other.position) @@ -533,7 +530,7 @@ public String toString() { static class MenuKey extends Key { static final String FACTORY = "ContributionFactory"; //$NON-NLS-1$ - private MMenuContribution contribution; + private final MMenuContribution contribution; public MenuKey(MMenuContribution mc) { super(mc.getParentId(), mc.getPositionInParent(), mc.getTags(), (MCoreExpression) mc @@ -549,7 +546,7 @@ public MMenuContribution getContribution() { static class ToolBarKey extends Key { static final String FACTORY = "ToolBarContributionFactory"; //$NON-NLS-1$ - private MToolBarContribution contribution; + private final MToolBarContribution contribution; public ToolBarKey(MToolBarContribution mc) { super(mc.getParentId(), mc.getPositionInParent(), mc.getTags(), (MCoreExpression) mc @@ -564,7 +561,7 @@ public MToolBarContribution getContribution() { } static class TrimKey extends Key { - private MTrimContribution contribution; + private final MTrimContribution contribution; public TrimKey(MTrimContribution mc) { super(mc.getParentId(), mc.getPositionInParent(), mc.getTags(), (MCoreExpression) mc diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4XMIResource.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4XMIResource.java index b408d3ad91e..7f718742055 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4XMIResource.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4XMIResource.java @@ -30,8 +30,8 @@ public class E4XMIResource extends XMIResourceImpl { public static final String OPTION_FILTER_PERSIST_STATE = "E4_FILTER_PERSISTED_STATE"; //$NON-NLS-1$ - private Map objectMap = new WeakHashMap<>(); - private Set knownIds = new HashSet<>(); + private final Map objectMap = new WeakHashMap<>(); + private final Set knownIds = new HashSet<>(); public E4XMIResource() { } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4XMISave.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4XMISave.java index 56b240319d7..6f910849940 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4XMISave.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4XMISave.java @@ -37,15 +37,13 @@ public E4XMISave(XMLHelper helper) { */ @Override protected void saveElement(InternalEObject o, EStructuralFeature f) { - if (o instanceof MApplicationElement) { - MApplicationElement appElement = (MApplicationElement) o; + if (o instanceof MApplicationElement appElement) { String persists = appElement.getPersistedState().get(IWorkbench.PERSIST_STATE); if (persists != null && !Boolean.parseBoolean(persists)) { return; } } - if (o instanceof MUIElement) { - MUIElement uiElement = (MUIElement) o; + if (o instanceof MUIElement uiElement) { if (OpaqueElementUtil.isOpaqueElement(uiElement) || RenderedElementUtil.isRenderedElement(uiElement)) { return; } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ExtensionTrackeContextFunction.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ExtensionTrackeContextFunction.java index 6f5b03b94ad..3fa7ed68724 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ExtensionTrackeContextFunction.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ExtensionTrackeContextFunction.java @@ -37,7 +37,7 @@ public class ExtensionTrackeContextFunction extends ContextFunction implements E @Reference private ILog log; - private Map createdObjects = new ConcurrentHashMap<>(); + private final Map createdObjects = new ConcurrentHashMap<>(); @Override public Object compute(IEclipseContext context, String contextKey) { diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/GenericMApplicationElementFactoryImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/GenericMApplicationElementFactoryImpl.java index 44c4b6a90d2..f69c6be5b57 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/GenericMApplicationElementFactoryImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/GenericMApplicationElementFactoryImpl.java @@ -69,8 +69,9 @@ final class GenericMApplicationElementFactoryImpl { * if the given Eclipse ExtensionRegistry is {@code null} */ GenericMApplicationElementFactoryImpl(IExtensionRegistry extensionRegistry) { - if (extensionRegistry == null) + if (extensionRegistry == null) { throw new NullPointerException("No ExtensionRegistry given!"); //$NON-NLS-1$ + } emfGeneratedPackages = new MApplicationElementClassToEClass(); @@ -278,16 +279,15 @@ private List> addToMapping( */ private final Map, EClass> buildMapping( EPackage ePackage) { - if (ePackage == null) + if (ePackage == null) { return null; + } List eClassifiers = ePackage.getEClassifiers(); Map, EClass> mapping = new HashMap<>(); for (EClassifier eClassifier : eClassifiers) { - if (eClassifier instanceof EClass) { - EClass eClass = (EClass) eClassifier; - + if (eClassifier instanceof EClass eClass) { if (mApplicationElementEClass.isSuperTypeOf(eClass) && !eClass.isAbstract() && !eClass.isInterface()) { @SuppressWarnings("unchecked") diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelFragmentComparator.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelFragmentComparator.java index 057e61d4fc4..e416344bf2a 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelFragmentComparator.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelFragmentComparator.java @@ -54,8 +54,9 @@ public ModelFragmentComparator(MApplication application) { @Override public int compare(ModelFragmentWrapper o1, ModelFragmentWrapper o2) { - if (o1 == o2) + if (o1 == o2) { return 0; + } PositionDescription posInfo1 = getPositionDescription(o1); PositionDescription posInfo2 = getPositionDescription(o2); @@ -80,8 +81,9 @@ public int compare(ModelFragmentWrapper o1, ModelFragmentWrapper o2) { switch (posInfo2.getPlace()) { case INDEX: int result = posInfo1.getPositionReferenceAsInteger() - posInfo2.getPositionReferenceAsInteger(); - if (result == 0) + if (result == 0) { return 1; + } return result; default: return -1; @@ -92,24 +94,29 @@ public int compare(ModelFragmentWrapper o1, ModelFragmentWrapper o2) { boolean hasElement = false; for (MApplicationElement element : o2.getModelFragment().getElements()) { hasElement |= ModelUtils.findElementById(element, posInfo1.getReference()) != null; - if (hasElement) + if (hasElement) { break; + } } - if (hasElement) + if (hasElement) { return 1; + } hasElement = false; for (MApplicationElement element : o1.getModelFragment().getElements()) { hasElement |= ModelUtils.findElementById(element, posInfo2.getReference()) != null; - if (hasElement) + if (hasElement) { break; + } } - if (hasElement) + if (hasElement) { return -1; + } hasElement = ModelUtils.findElementById(application, posInfo1.getReference()) != null; - if (hasElement) + if (hasElement) { return -1; + } return 1; default: @@ -122,15 +129,18 @@ public int compare(ModelFragmentWrapper o1, ModelFragmentWrapper o2) { } private PositionDescription getPositionDescription(ModelFragmentWrapper wrapper) { - if (!MStringModelFragment.class.isInstance(wrapper.getModelFragment())) + if (!MStringModelFragment.class.isInstance(wrapper.getModelFragment())) { return new PositionDescription(PositionPlace.NONE, null); + } MStringModelFragment stringFragment = (MStringModelFragment) wrapper.getModelFragment(); - if (stringFragment.getPositionInList() == null) + if (stringFragment.getPositionInList() == null) { return new PositionDescription(PositionPlace.NONE, null); + } String posInList = stringFragment.getPositionInList().trim(); PositionInfo posInfo = PositionInfo.parse(posInList); - if (posInfo == null) + if (posInfo == null) { return new PositionDescription(PositionPlace.NONE, null); + } switch (posInfo.getPosition()) { case AFTER: case BEFORE: diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java index fcc64a9900f..5fb2f8e0017 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java @@ -89,10 +89,10 @@ public class ModelServiceImpl implements EModelService { static String HOSTED_ELEMENT = "HostedElement"; //$NON-NLS-1$ - private IEclipseContext appContext; + private final IEclipseContext appContext; /** Factory which is able to create {@link MApplicationElement}s in a generic way. */ - private GenericMApplicationElementFactoryImpl mApplicationElementFactory; + private final GenericMApplicationElementFactoryImpl mApplicationElementFactory; private ServiceRegistration handlerRegistration; @@ -184,9 +184,7 @@ private void findElementsRecursive(MApplicationElement searchRoot, Class T element = (T) searchRoot; elements.add(element); } - if (searchRoot instanceof MApplication && (searchFlags == ANYWHERE)) { - MApplication app = (MApplication) searchRoot; - + if (searchRoot instanceof MApplication app && (searchFlags == ANYWHERE)) { List children = new ArrayList<>(); if (clazz != null) { if (clazz.equals(MHandler.class)) { @@ -212,22 +210,20 @@ private void findElementsRecursive(MApplicationElement searchRoot, Class } } - if (searchRoot instanceof MBindingContext && (searchFlags == ANYWHERE)) { - MBindingContext bindingContext = (MBindingContext) searchRoot; + if (searchRoot instanceof MBindingContext bindingContext && (searchFlags == ANYWHERE)) { for (MBindingContext child : bindingContext.getChildren()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } - if (searchRoot instanceof MBindingTable) { - MBindingTable bindingTable = (MBindingTable) searchRoot; + if (searchRoot instanceof MBindingTable bindingTable) { for (MKeyBinding child : bindingTable.getBindings()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } // Check regular containers - if (searchRoot instanceof MElementContainer) { + if (searchRoot instanceof MElementContainer searchContainer) { /* * Bug 455281: If given a window with a primary perspective stack, * and we're not told to look outside of the perspectives (i.e., @@ -236,7 +232,6 @@ private void findElementsRecursive(MApplicationElement searchRoot, Class * like the compat layer's stack holding the Help, CheatSheets, and * Intro. */ - MElementContainer searchContainer = (MElementContainer) searchRoot; MPerspectiveStack primaryStack = null; if (searchRoot instanceof MWindow ) { if((searchFlags & IN_SHARED_ELEMENTS) != 0) { @@ -283,8 +278,7 @@ private void findElementsRecursive(MApplicationElement searchRoot, Class } // Search Trim - if (searchRoot instanceof MTrimmedWindow && (searchFlags & IN_TRIM) != 0) { - MTrimmedWindow tw = (MTrimmedWindow) searchRoot; + if (searchRoot instanceof MTrimmedWindow tw && (searchFlags & IN_TRIM) != 0) { List bars = tw.getTrimBars(); for (MTrimBar bar : bars) { findElementsRecursive(bar, clazz, matcher, elements, searchFlags); @@ -292,8 +286,7 @@ private void findElementsRecursive(MApplicationElement searchRoot, Class } // Search Detached Windows - if (searchRoot instanceof MWindow) { - MWindow window = (MWindow) searchRoot; + if (searchRoot instanceof MWindow window) { for (MWindow dw : window.getWindows()) { findElementsRecursive(dw, clazz, matcher, elements, searchFlags); } @@ -310,16 +303,13 @@ private void findElementsRecursive(MApplicationElement searchRoot, Class } } - if (searchRoot instanceof MPerspective) { - MPerspective persp = (MPerspective) searchRoot; + if (searchRoot instanceof MPerspective persp) { for (MWindow dw : persp.getWindows()) { findElementsRecursive(dw, clazz, matcher, elements, searchFlags); } } // Search shared elements - if (searchRoot instanceof MPlaceholder) { - MPlaceholder ph = (MPlaceholder) searchRoot; - + if (searchRoot instanceof MPlaceholder ph) { // Don't search in shared areas unless the flag is set if (ph.getRef() != null && (!(ph.getRef() instanceof MArea) || (searchFlags & IN_SHARED_AREA) != 0)) { @@ -327,9 +317,7 @@ private void findElementsRecursive(MApplicationElement searchRoot, Class } } - if (searchRoot instanceof MPart && (searchFlags & IN_PART) != 0) { - MPart part = (MPart) searchRoot; - + if (searchRoot instanceof MPart part && (searchFlags & IN_PART) != 0) { for (MMenu menu : part.getMenus()) { findElementsRecursive(menu, clazz, matcher, elements, searchFlags); } @@ -479,8 +467,7 @@ public int countRenderableChildren(MUIElement element) { } } - if (element instanceof MPerspective) { - MPerspective perspective = (MPerspective) element; + if (element instanceof MPerspective perspective) { for (MWindow window : perspective.getWindows()) { if (window.isToBeRendered()) { count++; @@ -568,8 +555,7 @@ private List getNullRefPlaceHolders(MUIElement element, MWindow re } else if ((!resolveAlways) && (ph.getRef() == null)) { resolver.resolvePlaceholderRef(ph, refWin); MUIElement partElement = ph.getRef(); - if (partElement instanceof MPart) { - MPart part = (MPart) partElement; + if (partElement instanceof MPart part) { if (part.getIconURI() == null) { MPartDescriptor desc = getPartDescriptor(part.getElementId()); if (desc != null) { @@ -1053,15 +1039,16 @@ public int getElementLocation(MUIElement element) { MUIElement curElement = element; while (curElement != null) { Object container = ((EObject) curElement).eContainer(); - if (!(container instanceof MUIElement)) + if (!(container instanceof MUIElement)) { return NOT_IN_UI; + } if (container instanceof MApplication) { - if (location != NOT_IN_UI) + if (location != NOT_IN_UI) { return location; + } return OUTSIDE_PERSPECTIVE; - } else if (container instanceof MPerspective) { - MPerspective perspective = (MPerspective) container; + } else if (container instanceof MPerspective perspective) { MUIElement perspParent = perspective.getParent(); if (perspParent == null) { location = NOT_IN_UI; diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Parameter.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Parameter.java index ad6f61179c9..ec281b9a90f 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Parameter.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Parameter.java @@ -101,7 +101,7 @@ public final class Parameter implements IParameter, ITypedParameter { */ private transient IParameterValues values = null; - private IConfigurationElement valuesConfigurationElement; + private final IConfigurationElement valuesConfigurationElement; /** * Constructs a new instance of Parameter with all of its values pre-defined. @@ -149,11 +149,10 @@ public final boolean equals(final Object object) { return true; } - if (!(object instanceof Parameter)) { + if (!(object instanceof final Parameter parameter)) { return false; } - final Parameter parameter = (Parameter) object; if (!Objects.equals(id, parameter.id)) { return false; } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartActivationHistory.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartActivationHistory.java index 46cc662f896..9d751a88354 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartActivationHistory.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartActivationHistory.java @@ -38,11 +38,11 @@ class PartActivationHistory { - private PartServiceImpl partService; + private final PartServiceImpl partService; - private EModelService modelService; + private final EModelService modelService; - private LinkedList generalActivationHistory = new LinkedList<>(); + private final LinkedList generalActivationHistory = new LinkedList<>(); PartActivationHistory(PartServiceImpl partService, EModelService modelService) { this.partService = partService; @@ -166,7 +166,7 @@ private MArea isInArea(MUIElement element) { // may be null for detached windows parent = (MUIElement) ((EObject) element).eContainer(); } - return parent instanceof MApplication ? null : parent instanceof MArea ? (MArea) parent + return parent instanceof MApplication ? null : parent instanceof MArea m ? m : isInArea(parent); } @@ -175,7 +175,7 @@ private MArea isInArea(MUIElement element) { // may be null for detached windows parent = (MUIElement) ((EObject) placeholder).eContainer(); } - return parent instanceof MApplication ? null : parent instanceof MArea ? (MArea) parent + return parent instanceof MApplication ? null : parent instanceof MArea m ? m : isInArea(parent); } @@ -345,7 +345,7 @@ private MPart getSiblingActivationCandidate(MPart part) { MPlaceholder placeholder = part.getCurSharedRef(); MUIElement candidate = getSiblingSelectionCandidate(part, placeholder == null ? part : placeholder); - return (MPart) (candidate instanceof MPlaceholder ? ((MPlaceholder) candidate).getRef() + return (MPart) (candidate instanceof MPlaceholder m ? m.getRef() : candidate); } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartOnTopManager.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartOnTopManager.java index 23c56fedf2c..3b760f1335e 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartOnTopManager.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartOnTopManager.java @@ -108,8 +108,7 @@ private void handlePartSelection(Object oldValue, Object newValue) { oldElement = ((MPlaceholder) oldElement).getRef(); } - if (oldElement instanceof MPart) { - MPart contextElement = (MPart) oldElement; + if (oldElement instanceof MPart contextElement) { if (contextElement.getContext() != null) { contextElement.getContext().set(IWorkbench.ON_TOP, Boolean.FALSE); } @@ -121,8 +120,7 @@ private void handlePartSelection(Object oldValue, Object newValue) { newElement = ((MPlaceholder) newElement).getRef(); } - if (newElement instanceof MPart) { - MPart contextElement = (MPart) newElement; + if (newElement instanceof MPart contextElement) { if (contextElement.getContext() != null) { contextElement.getContext().set(IWorkbench.ON_TOP, Boolean.TRUE); } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceCreationFunction.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceCreationFunction.java index 8380b5a3aa6..57604a7e07b 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceCreationFunction.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceCreationFunction.java @@ -37,8 +37,9 @@ public Object compute(IEclipseContext context, String contextKey) { IEclipseContext current = context; do { MContext model = current.get(MContext.class); - if (model instanceof MWindow) + if (model instanceof MWindow) { window = (MWindow) model; + } current = current.getParent(); } while (current != null); diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java index 3989f671859..c5d66843adb 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java @@ -75,7 +75,7 @@ public class PartServiceImpl implements EPartService { */ public static final String PART_ACTIVATION_TIME = "partActivationTime"; //$NON-NLS-1$ - private EventHandler selectedHandler = event -> { + private final EventHandler selectedHandler = event -> { // no need to do anything if we have no listeners if (!this.listeners.isEmpty()) { Object oldSelected = event.getProperty(UIEvents.EventTags.OLD_VALUE); @@ -115,7 +115,7 @@ && getParts().contains(selectedPart)) { } }; - private EventHandler minimizedPartHandler = new EventHandler() { + private final EventHandler minimizedPartHandler = new EventHandler() { @Override public void handleEvent(Event event) { Object element = event.getProperty(UIEvents.EventTags.ELEMENT); @@ -145,19 +145,19 @@ public void handleEvent(Event event) { private MPart toPart(MStackElement stackElement) { if (stackElement != null) { - return stackElement instanceof MPlaceholder ? (MPart) ((MPlaceholder) stackElement) + return stackElement instanceof MPlaceholder m ? (MPart) m .getRef() : (MPart) stackElement; } return null; } }; - private MApplication application; + private final MApplication application; /** * Might be null if this part service is created for the application */ - private MWindow workbenchWindow; + private final MWindow workbenchWindow; @Inject private IPresentationEngine engine; @@ -188,7 +188,7 @@ private MPart toPart(MStackElement stackElement) { private MPart activePart; - private ListenerList listeners = new ListenerList<>(); + private final ListenerList listeners = new ListenerList<>(); private boolean constructed = false; @@ -333,13 +333,16 @@ public void removePartListener(IPartListener listener) { } private MWindow getWindow() { - if (workbenchWindow != null) + if (workbenchWindow != null) { return workbenchWindow; - if (application.getSelectedElement() != null) + } + if (application.getSelectedElement() != null) { return application.getSelectedElement(); + } List windows = application.getChildren(); - if (!windows.isEmpty()) + if (!windows.isEmpty()) { return windows.get(0); + } return null; } @@ -351,8 +354,9 @@ private MContext getParentWithContext(MUIElement part) { } else { while (parent != null) { if (parent instanceof MContext) { - if (((MContext) parent).getContext() != null) + if (((MContext) parent).getContext() != null) { return (MContext) parent; + } } intermediate = parent; parent = parent.getParent(); @@ -363,8 +367,9 @@ private MContext getParentWithContext(MUIElement part) { parent = placeholder.getParent(); while (parent != null) { if (parent instanceof MContext) { - if (((MContext) parent).getContext() != null) + if (((MContext) parent).getContext() != null) { return (MContext) parent; + } } parent = parent.getParent(); } @@ -443,10 +448,12 @@ private void internalFixContext(MPart part, MUIElement oldSelectedElement) { if (part == null) { // TBD this should not be necessary; deactivation is missing somewhere IEclipseContext currentActive = parentContext.getActiveChild(); - if (currentActive != null) + if (currentActive != null) { currentActive.deactivate(); - } else + } + } else { part.getContext().activate(); + } } } @@ -505,8 +512,9 @@ private boolean isMinimized(MUIElement elt) { } private boolean isInActivePerspective(MUIElement element) { - if (modelService.isHostedElement(element, getWindow())) + if (modelService.isHostedElement(element, getWindow())) { return true; + } MPerspective persp = modelService.getPerspectiveFor(element); if (persp == null) { List allPerspectiveElements = modelService.findElements(workbenchWindow, null, MUIElement.class, @@ -517,8 +525,9 @@ private boolean isInActivePerspective(MUIElement element) { } private boolean isInContainer(MUIElement element) { - if (modelService.isHostedElement(element, getWindow())) + if (modelService.isHostedElement(element, getWindow())) { return true; + } List allPerspectiveElements = modelService.findElements(workbenchWindow, null, MUIElement.class, null, EModelService.PRESENTATION); return allPerspectiveElements.contains(element); @@ -541,34 +550,34 @@ boolean isInContainer(MElementContainer container, MUIElement element) { return true; } } - } else if (object instanceof MPerspective) { - MPerspective persp = (MPerspective) object; + } else if (object instanceof MPerspective persp) { for (MWindow dw : persp.getWindows()) { - if (isInContainer(dw, element)) + if (isInContainer(dw, element)) { return true; + } } - } else if (object instanceof MWindow) { - MWindow win = (MWindow) object; + } else if (object instanceof MWindow win) { for (MWindow dw : win.getWindows()) { - if (isInContainer(dw, element)) + if (isInContainer(dw, element)) { return true; + } } } } - if (container instanceof MWindow) { - MWindow win = (MWindow) container; + if (container instanceof MWindow win) { for (MWindow dw : win.getWindows()) { - if (isInContainer(dw, element)) + if (isInContainer(dw, element)) { return true; + } } } - if (container instanceof MPerspective) { - MPerspective persp = (MPerspective) container; + if (container instanceof MPerspective persp) { for (MWindow dw : persp.getWindows()) { - if (isInContainer(dw, element)) + if (isInContainer(dw, element)) { return true; + } } } @@ -1087,8 +1096,7 @@ private void addToLastContainer(String category, MPart part) { MPlaceholder.class, null, EModelService.PRESENTATION); if (!phList.isEmpty()) { MUIElement phParent = phList.get(0).getParent(); - if (phParent instanceof MPartStack) { - MPartStack theStack = (MPartStack) phParent; + if (phParent instanceof MPartStack theStack) { int phIndex = theStack.getChildren().indexOf(phList.get(0)); adjustPlaceholder(part); MPlaceholder placeholder = part.getCurSharedRef(); @@ -1152,8 +1160,7 @@ private MElementContainer getLastContainer(MElementContain for (int i = children.size() - 1; i > -1; i--) { Object muiElement = children.get(i); - if (muiElement instanceof MElementContainer) { - MElementContainer childContainer = (MElementContainer) muiElement; + if (muiElement instanceof MElementContainer childContainer) { MElementContainer lastContainer = getLastContainer(childContainer, childContainer.getChildren()); if (lastContainer != null) { @@ -1193,8 +1200,7 @@ private MElementContainer findContainer(MElementContainer targetClass = bundle.loadClass(clazz); - if (staticContext == null) + if (staticContext == null) { contribution = ContextInjectionFactory.make(targetClass, context); - else + } else { contribution = ContextInjectionFactory .make(targetClass, context, staticContext); + } if (contribution == null) { String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java index 5093f65aac3..e763473da1f 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java @@ -83,12 +83,12 @@ public class ResourceHandler implements IModelResourceHandler { @Inject @Optional @Named(IWorkbench.PERSIST_STATE) - private boolean saveAndRestore; + private final boolean saveAndRestore; @Inject @Optional @Named(IWorkbench.CLEAR_PERSISTED_STATE) - private boolean clearPersistedState; + private final boolean clearPersistedState; /** * Constructor. diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java index e3c63a07319..6740ce5632a 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java @@ -44,32 +44,31 @@ public class SelectionAggregator { static final String OUT_SELECTION = "org.eclipse.ui.output.selection"; //$NON-NLS-1$ static final String OUT_POST_SELECTION = "org.eclipse.ui.output.postSelection"; //$NON-NLS-1$ - private ListenerList genericListeners = new ListenerList<>(); - private ListenerList genericPostListeners = new ListenerList<>(); - private Map> targetedListeners = new HashMap<>(); - private Map> targetedPostListeners = new HashMap<>(); - private Set tracked = new HashSet<>(); + private final ListenerList genericListeners = new ListenerList<>(); + private final ListenerList genericPostListeners = new ListenerList<>(); + private final Map> targetedListeners = new HashMap<>(); + private final Map> targetedPostListeners = new HashMap<>(); + private final Set tracked = new HashSet<>(); - private EventHandler eventHandler = event -> { + private final EventHandler eventHandler = event -> { Object element = event.getProperty(UIEvents.EventTags.ELEMENT); - if (element instanceof MPart) { - MPart part = (MPart) element; - + if (element instanceof MPart part) { String partId = part.getElementId(); - if (targetedListeners.containsKey(partId) || targetedPostListeners.containsKey(partId)) + if (targetedListeners.containsKey(partId) || targetedPostListeners.containsKey(partId)) { track(part); + } } }; private MPart activePart; - private IEclipseContext context; + private final IEclipseContext context; - private EPartService partService; + private final EPartService partService; - private IEventBroker eventBroker; + private final IEventBroker eventBroker; - private Logger logger; + private final Logger logger; @Inject SelectionAggregator(IEclipseContext context, EPartService partService, @@ -301,8 +300,9 @@ public void addSelectionListener(String partId, ISelectionListener listener) { listeners.add(listener); MPart part = partService.findPart(partId); - if (part != null) + if (part != null) { track(part); + } } public void addPostSelectionListener(String partId, ISelectionListener listener) { @@ -314,8 +314,9 @@ public void addPostSelectionListener(String partId, ISelectionListener listener) listeners.add(listener); MPart part = partService.findPart(partId); - if (part != null) + if (part != null) { track(part); + } } public void removeSelectionListener(String partId, ISelectionListener listener) { diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionServiceImpl.java index acd9c952065..cad8930e993 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionServiceImpl.java @@ -22,7 +22,7 @@ public class SelectionServiceImpl implements ESelectionService { - private IEclipseContext context; + private final IEclipseContext context; @Inject SelectionServiceImpl(IEclipseContext context) { @@ -123,14 +123,17 @@ public void removePostSelectionListener(String partId, ISelectionListener listen private SelectionAggregator getServiceAggregator() { SelectionAggregator aggregator = context.get(SelectionAggregator.class); - if (aggregator != null) + if (aggregator != null) { return aggregator; + } MApplication app = context.get(MApplication.class); - if (app == null) + if (app == null) { return null; + } IEclipseContext windowContext = findContext(app); - if (windowContext == null) + if (windowContext == null) { return null; + } return windowContext.get(SelectionAggregator.class); } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/UIEventPublisher.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/UIEventPublisher.java index a254d8a0f48..be37aa2c36c 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/UIEventPublisher.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/UIEventPublisher.java @@ -36,7 +36,7 @@ */ public class UIEventPublisher extends EContentAdapter { - private IEclipseContext context; + private final IEclipseContext context; public UIEventPublisher(IEclipseContext e4Context) { this.context = e4Context; @@ -47,8 +47,9 @@ public void notifyChanged(Notification notification) { super.notifyChanged(notification); // Ignore events that did not change the model value - if (notification.isTouch()) + if (notification.isTouch()) { return; + } // Format the EMF event as an E4 UIEvent Map argMap = new HashMap<>(); diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/UIExtensionTracker.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/UIExtensionTracker.java index 9b98e3d6fdf..14223e23961 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/UIExtensionTracker.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/UIExtensionTracker.java @@ -25,8 +25,8 @@ * @since 3.1 */ public class UIExtensionTracker extends ExtensionTracker { - private Executor executor; - private ILog log; + private final Executor executor; + private final ILog log; public UIExtensionTracker(Executor executor, ILog log) { this.executor = executor; diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/URIHelper.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/URIHelper.java index 87aa2c853fc..ed6f0f81535 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/URIHelper.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/URIHelper.java @@ -56,15 +56,17 @@ public class URIHelper { static public String constructPlatformURI(Bundle bundle) { BundleRevision bundleRevision = bundle.adapt(BundleRevision.class); - if (bundleRevision == null) + if (bundleRevision == null) { return null; + } StringBuilder tmp = new StringBuilder(); tmp.append(PLATFORM_SCHEMA); - if ((bundleRevision.getTypes() & BundleRevision.TYPE_FRAGMENT) == BundleRevision.TYPE_FRAGMENT) + if ((bundleRevision.getTypes() & BundleRevision.TYPE_FRAGMENT) == BundleRevision.TYPE_FRAGMENT) { tmp.append(FRAGMENT_SEGMENT); - else + } else { tmp.append(PLUGIN_SEGMENT); + } tmp.append(bundle.getSymbolicName()); return tmp.toString(); } @@ -72,11 +74,12 @@ static public String constructPlatformURI(Bundle bundle) { static public String constructPlatformURI(IContributor contributor) { // registry contributors are singletons String bundleName; - if (contributor instanceof RegistryContributor) + if (contributor instanceof RegistryContributor) { bundleName = ((RegistryContributor) contributor).getActualName(); - else + } else { // should not happen for the standard registry, but try to make a best guess // should not happen for the standard registry, but try to make a best guess bundleName = contributor.getName(); + } Bundle bundle = Activator.getDefault().getBundleForName(bundleName); return constructPlatformURI(bundle); } @@ -89,19 +92,22 @@ static public Bundle getBundle(String contributorURI) { ILog.get().error("Invalid contributor URI: " + contributorURI); //$NON-NLS-1$ return null; } - if (!PLATFORM_SCHEMA.equals(uri.getScheme())) + if (!PLATFORM_SCHEMA.equals(uri.getScheme())) { return null; // not implemented + } return Activator.getDefault().getBundleForName(uri.getPath()); } static public String EMFtoPlatform(org.eclipse.emf.common.util.URI uri) { - if (!PLATFORM_SCHEMA_EMF.equals(uri.scheme())) + if (!PLATFORM_SCHEMA_EMF.equals(uri.scheme())) { return null; + } // remove all segments but first two - only need bundle/fragment name int segments = uri.segmentCount(); // segments: { "plugin", "org.eclipse.platform", "myDir", "model.e4xmi" } - if (segments > 2) + if (segments > 2) { uri = uri.trimSegments(segments - 2); + } return uri.toString(); } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/WorkbenchLogger.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/WorkbenchLogger.java index 4459d5f108b..f23753a21d8 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/WorkbenchLogger.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/WorkbenchLogger.java @@ -32,7 +32,7 @@ public final class WorkbenchLogger extends Logger { protected DebugTrace trace; protected FrameworkLog log; - private String bundleName; + private final String bundleName; /** * Creates a new workbench logger @@ -126,8 +126,9 @@ private void log(IStatus status) { log.log(getLog(status)); } else { System.out.println(status.getMessage()); - if (status.getException() != null) + if (status.getException() != null) { status.getException().printStackTrace(); + } } } @@ -159,8 +160,9 @@ private void trace(String flag, Throwable t, String message) { trace.trace(flag, message, t); } else { System.out.println(message); - if (t != null) + if (t != null) { t.printStackTrace(); + } } } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/ContextProcessingAddon.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/ContextProcessingAddon.java index 2a7abdd282a..2ea5a19ffba 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/ContextProcessingAddon.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/ContextProcessingAddon.java @@ -100,16 +100,14 @@ private void registerModelListeners() { if (UIEvents.isADD(event)) { for (Object newObj : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) { - if (newObj instanceof MBindingContext) { - MBindingContext newCtx = (MBindingContext) newObj; + if (newObj instanceof MBindingContext newCtx) { defineContexts((MBindingContext) elementObj, newCtx); } } } else if (UIEvents.isREMOVE(event)) { for (Object oldObj : UIEvents.asIterable(event, UIEvents.EventTags.OLD_VALUE)) { - if (oldObj instanceof MBindingContext) { - MBindingContext oldCtx = (MBindingContext) oldObj; + if (oldObj instanceof MBindingContext oldCtx) { undefineContext(oldCtx); } } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/HandlerProcessingAddon.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/HandlerProcessingAddon.java index 42b9a7023a0..bf0b880b35f 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/HandlerProcessingAddon.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/HandlerProcessingAddon.java @@ -44,8 +44,7 @@ public class HandlerProcessingAddon { public void postConstruct(MApplication application, EModelService modelService) { List findElements = modelService.findElements(application, null, MHandlerContainer.class); for (MHandlerContainer mHandlerContainer : findElements) { - if (mHandlerContainer instanceof MContext) { - MContext mContext = (MContext) mHandlerContainer; + if (mHandlerContainer instanceof MContext mContext) { IEclipseContext context = mContext.getContext(); if (context != null) { for (MHandler mHandler : mHandlerContainer.getHandlers()) { @@ -112,10 +111,8 @@ public void handleHandlerEvent(@EventTopic(UIEvents.HandlerContainer.TOPIC_HANDL public void handleContextEvent(@EventTopic(UIEvents.Context.TOPIC_CONTEXT) Event event) { Object origin = event.getProperty(UIEvents.EventTags.ELEMENT); Object context = event.getProperty(UIEvents.EventTags.NEW_VALUE); - if ((origin instanceof MHandlerContainer) - && (UIEvents.EventTypes.SET.equals(event.getProperty(UIEvents.EventTags.TYPE)) && context instanceof IEclipseContext)) { - MHandlerContainer handlerContainer = (MHandlerContainer) origin; - IEclipseContext castedContext = (IEclipseContext) context; + if ((origin instanceof MHandlerContainer handlerContainer) + && (UIEvents.EventTypes.SET.equals(event.getProperty(UIEvents.EventTags.TYPE)) && context instanceof IEclipseContext castedContext)) { for (MHandler mHandler : handlerContainer.getHandlers()) { processActiveHandler(mHandler, castedContext); } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/IPresentationEngine.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/IPresentationEngine.java index 32ed301c04d..1d0d975baec 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/IPresentationEngine.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/IPresentationEngine.java @@ -217,6 +217,7 @@ public interface IPresentationEngine { * * @deprecated not supported in the Eclipse platform anymore */ + @Deprecated String ANIMATIONS_ENABLED = "Animations Enabled"; //$NON-NLS-1$ /** diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/UIEvents.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/UIEvents.java index 80c389bb004..3dceb10f40d 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/UIEvents.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/UIEvents.java @@ -368,8 +368,9 @@ public interface UILifeCycle { * @return true if the event is published correctly, false otherwise */ public static boolean publishEvent(String topic, MUIElement changedElement) { - if (topic == null || topic.isEmpty() || changedElement == null) + if (topic == null || topic.isEmpty() || changedElement == null) { return false; + } Map argMap = new HashMap<>(1); argMap.put(EventTags.ELEMENT, changedElement); @@ -388,22 +389,25 @@ public static boolean publishEvent(String topic, MUIElement changedElement) { * @return true if the event is published correctly, false otherwise */ public static boolean publishEvent(String topic, Map argMap) { - if (topic == null || topic.isEmpty() || argMap == null) + if (topic == null || topic.isEmpty() || argMap == null) { return false; + } Object uiElement = argMap.get(EventTags.ELEMENT); if (!(uiElement instanceof MUIElement)) { return false; } - IEclipseContext context = uiElement instanceof MApplication ? ((MApplication) uiElement) + IEclipseContext context = uiElement instanceof MApplication m ? m .getContext() : ModelUtils.getContainingContext((MUIElement) uiElement); - if (context == null) + if (context == null) { return false; + } IEventBroker eventBroker = context.get(IEventBroker.class); - if (eventBroker == null) + if (eventBroker == null) { return false; + } return eventBroker.send(topic, argMap); } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EObjModelHandler.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EObjModelHandler.java index 5d9410112b1..b3fd4dccd75 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EObjModelHandler.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/EObjModelHandler.java @@ -47,20 +47,23 @@ public Object[] getChildren(Object element, String id) { @Override public Object getProperty(Object element, String id) { EObject eObj = (EObject) element; - if (eObj == null) + if (eObj == null) { return null; + } EStructuralFeature eFeature = eObj.eClass().getEStructuralFeature(id); - if (eFeature == null) + if (eFeature == null) { return null; + } return eObj.eGet(eFeature); } @Override public String[] getPropIds(Object element) { - if (element == null) + if (element == null) { return new String[0]; + } EObject eObj = (EObject) element; EList features = eObj.eClass().getEAllStructuralFeatures(); @@ -77,12 +80,14 @@ public String[] getPropIds(Object element) { @Override public void setProperty(Object element, String id, Object value) { EObject eObj = (EObject) element; - if (eObj == null) + if (eObj == null) { return; + } EStructuralFeature eFeature = eObj.eClass().getEStructuralFeature(id); - if (eFeature == null) + if (eFeature == null) { return; + } eObj.eSet(eFeature, value); }