diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java index 444a68482e4..623e4cf0713 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java @@ -194,12 +194,10 @@ void handleToBeRenderedEvent(@UIEventTopic(UIEvents.UIElement.TOPIC_TOBERENDERED void handleLabelEvent(@UIEventTopic(UIEvents.UILabel.TOPIC_ALL) Event event) { Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT); - if (!(changedObj instanceof MPerspective) || (ignoreEvent(changedObj))) { + if (!(changedObj instanceof MPerspective perspective) || (ignoreEvent(changedObj))) { return; } - MPerspective perspective = (MPerspective) changedObj; - if (!perspective.isToBeRendered()) { return; @@ -222,12 +220,10 @@ void handleLabelEvent(@UIEventTopic(UIEvents.UILabel.TOPIC_ALL) Event event) { void handleSelectionEvent(@UIEventTopic(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT) Event event) { Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT); - if (!(changedObj instanceof MPerspectiveStack) || (ignoreEvent(changedObj))) { + if (!(changedObj instanceof MPerspectiveStack perspStack) || (ignoreEvent(changedObj))) { return; } - MPerspectiveStack perspStack = (MPerspectiveStack) changedObj; - if (!perspStack.isToBeRendered()) { return; } @@ -259,8 +255,7 @@ void createWidget(Composite parent, MToolControl toolControl) { perspSwitcherToolControl = toolControl; MUIElement meParent = perspSwitcherToolControl.getParent(); int orientation = SWT.HORIZONTAL; - if (meParent instanceof MTrimBar) { - MTrimBar bar = (MTrimBar) meParent; + if (meParent instanceof MTrimBar bar) { if (bar.getSide() == SideValue.RIGHT || bar.getSide() == SideValue.LEFT) { orientation = SWT.VERTICAL; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/ActiveShellExpression.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/ActiveShellExpression.java index 0c4bc1c008e..252bbc7a427 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/ActiveShellExpression.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/ActiveShellExpression.java @@ -78,8 +78,7 @@ protected int computeHashCode() { @Override public boolean equals(final Object object) { - if (object instanceof ActiveShellExpression) { - final ActiveShellExpression that = (ActiveShellExpression) object; + if (object instanceof final ActiveShellExpression that) { return equals(this.activeShell, that.activeShell); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/BasicWorkingSetElementAdapter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/BasicWorkingSetElementAdapter.java index 61af368b727..6dbfe637b4b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/BasicWorkingSetElementAdapter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/BasicWorkingSetElementAdapter.java @@ -93,8 +93,9 @@ public IAdaptable[] adaptElements(IWorkingSet ws, IAdaptable[] elements) { List adaptedElements = new ArrayList<>(); for (IAdaptable element : elements) { IAdaptable adaptable = adapt(element); - if (adaptable != null) + if (adaptable != null) { adaptedElements.add(adaptable); + } } return adaptedElements.toArray(new IAdaptable[adaptedElements.size()]); @@ -111,8 +112,9 @@ public IAdaptable[] adaptElements(IWorkingSet ws, IAdaptable[] elements) { private IAdaptable adapt(IAdaptable adaptable) { for (Type preferredType : preferredTypes) { IAdaptable adaptedAdaptable = adapt(preferredType, adaptable); - if (adaptedAdaptable != null) + if (adaptedAdaptable != null) { return adaptedAdaptable; + } } return null; } @@ -129,14 +131,16 @@ private IAdaptable adapt(Type type, IAdaptable adaptable) { IAdapterManager adapterManager = Platform.getAdapterManager(); Class[] directClasses = adapterManager.computeClassOrder(adaptable.getClass()); for (Class clazz : directClasses) { - if (clazz.getName().equals(type.className)) + if (clazz.getName().equals(type.className)) { return adaptable; + } } if ((type.flags & Type.ADAPT) != 0) { Object adapted = adapterManager.getAdapter(adaptable, type.className); - if (adapted instanceof IAdaptable) + if (adapted instanceof IAdaptable) { return (IAdaptable) adapted; + } PackageAdmin admin = getPackageAdmin(); if (admin != null) { @@ -155,8 +159,9 @@ private IAdaptable adapt(Type type, IAdaptable adaptable) { // object directly adapted = adaptable .getAdapter(packages[0].getExportingBundle().loadClass(type.className)); - if (adapted instanceof IAdaptable) + if (adapted instanceof IAdaptable) { return (IAdaptable) adapted; + } } catch (ClassNotFoundException e) { WorkbenchPlugin.log(e); @@ -171,8 +176,9 @@ private IAdaptable adapt(Type type, IAdaptable adaptable) { @Override public void dispose() { - if (packageTracker != null) + if (packageTracker != null) { packageTracker.close(); + } } @Override @@ -200,9 +206,9 @@ public void setInitializationData(IConfigurationElement config, String propertyN private void parseOptions(String classNameAndOptions, Type record) { for (StringTokenizer toker = new StringTokenizer(classNameAndOptions, ";"); toker.hasMoreTokens();) { //$NON-NLS-1$ String token = toker.nextToken(); - if (record.className == null) + if (record.className == null) { record.className = token; - else { + } else { for (StringTokenizer pair = new StringTokenizer(token, "="); pair.hasMoreTokens();) {//$NON-NLS-1$ if (pair.countTokens() == 2) { String param = pair.nextToken(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/LegacyHandlerSubmissionExpression.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/LegacyHandlerSubmissionExpression.java index 0e7a296fdb5..2d3b6721341 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/LegacyHandlerSubmissionExpression.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/LegacyHandlerSubmissionExpression.java @@ -104,8 +104,7 @@ protected int computeHashCode() { @Override public boolean equals(final Object object) { - if (object instanceof LegacyHandlerSubmissionExpression) { - final LegacyHandlerSubmissionExpression that = (LegacyHandlerSubmissionExpression) object; + if (object instanceof final LegacyHandlerSubmissionExpression that) { return equals(this.activePartId, that.activePartId) && equals(this.activeShell, that.activeShell) && equals(this.activeSite, that.activeSite); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/MultiPartInitException.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/MultiPartInitException.java index b00867cc275..e7c9dd32d7e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/MultiPartInitException.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/MultiPartInitException.java @@ -23,8 +23,8 @@ */ public class MultiPartInitException extends WorkbenchException { - private IWorkbenchPartReference[] references; - private PartInitException[] exceptions; + private final IWorkbenchPartReference[] references; + private final PartInitException[] exceptions; /** * Creates a new exception object. Note that as of 3.5, this constructor expects @@ -65,8 +65,9 @@ public PartInitException[] getExceptions() { private static int findFirstException(PartInitException[] exceptions) { for (int i = 0; i < exceptions.length; i++) { - if (exceptions[i] != null) + if (exceptions[i] != null) { return i; + } } throw new IllegalArgumentException(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/NavigationLocation.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/NavigationLocation.java index dfca35ecce5..ae7a9cd362b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/NavigationLocation.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/NavigationLocation.java @@ -21,7 +21,7 @@ */ public abstract class NavigationLocation implements INavigationLocation { - private IWorkbenchPage page; + private final IWorkbenchPage page; private IEditorInput input; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/OpenAndLinkWithEditorHelper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/OpenAndLinkWithEditorHelper.java index 6261726ba32..e386d5ad62b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/OpenAndLinkWithEditorHelper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/OpenAndLinkWithEditorHelper.java @@ -32,7 +32,7 @@ */ public abstract class OpenAndLinkWithEditorHelper { - private StructuredViewer viewer; + private final StructuredViewer viewer; private boolean isLinkingEnabled; @@ -51,15 +51,17 @@ public void open(OpenEvent event) { @Override public void selectionChanged(SelectionChangedEvent event) { final ISelection selection = event.getSelection(); - if (isLinkingEnabled && !selection.equals(lastOpenSelection) && viewer.getControl().isFocusControl()) + if (isLinkingEnabled && !selection.equals(lastOpenSelection) && viewer.getControl().isFocusControl()) { linkToEditor(selection); + } lastOpenSelection = null; } @Override public void doubleClick(DoubleClickEvent event) { - if (!OpenStrategy.activateOnOpen()) + if (!OpenStrategy.activateOnOpen()) { activate(event.getSelection()); + } } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SaveablesLifecycleEvent.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SaveablesLifecycleEvent.java index 988b5fe8679..f206c1a3108 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SaveablesLifecycleEvent.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SaveablesLifecycleEvent.java @@ -53,11 +53,11 @@ public class SaveablesLifecycleEvent extends EventObject { */ public static final int DIRTY_CHANGED = 4; - private int eventType; + private final int eventType; - private Saveable[] saveables; + private final Saveable[] saveables; - private boolean force; + private final boolean force; private boolean veto = false; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SelectionEnabler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SelectionEnabler.java index 5a0e2272836..0017ea3bbc7 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SelectionEnabler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SelectionEnabler.java @@ -219,8 +219,7 @@ public SelectionEnabler(IConfigurationElement configElement) { @Override public boolean equals(final Object object) { - if (object instanceof SelectionEnabler) { - final SelectionEnabler that = (SelectionEnabler) object; + if (object instanceof final SelectionEnabler that) { return Objects.equals(this.classes, that.classes) && Objects.equals(this.enablementExpression, that.enablementExpression) && this.mode == that.mode; @@ -268,8 +267,7 @@ private boolean isEnabledFor(ISelection sel) { if (classes.isEmpty()) { return true; } - if (obj instanceof IAdaptable) { - IAdaptable element = (IAdaptable) obj; + if (obj instanceof IAdaptable element) { if (!verifyElement(element)) { return false; } @@ -327,8 +325,7 @@ private boolean isEnabledFor(IStructuredSelection ssel) { return true; } for (Object obj : ssel) { - if (obj instanceof IAdaptable) { - IAdaptable element = (IAdaptable) obj; + if (obj instanceof IAdaptable element) { if (!verifyElement(element)) { return false; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SubActionBars.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SubActionBars.java index e86e714395c..429ca4267eb 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SubActionBars.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/SubActionBars.java @@ -88,7 +88,7 @@ public final void collectExpressionInfo(final ExpressionInfo info) { private SubMenuManager menuMgr; - private IActionBars parent; + private final IActionBars parent; /** * A service locator appropriate for this action bar. This value is never @@ -100,7 +100,7 @@ public final void collectExpressionInfo(final ExpressionInfo info) { private SubToolBarManager toolBarMgr; - private Map actionIdByCommandId = new HashMap<>(); + private final Map actionIdByCommandId = new HashMap<>(); /** * Construct a new SubActionBars object. The service locator will @@ -514,8 +514,7 @@ public void setGlobalActionHandler(String actionID, IAction handler) { activationsByActionIdByServiceLocator.put(serviceLocator, activationsByActionId); } else if (activationsByActionId.containsKey(actionID)) { final Object value = activationsByActionId.remove(actionID); - if (value instanceof IHandlerActivation) { - final IHandlerActivation activation = (IHandlerActivation) value; + if (value instanceof final IHandlerActivation activation) { actionIdByCommandId.remove(activation.getCommandId()); if (service != null) { service.deactivateHandler(activation); @@ -524,8 +523,7 @@ public void setGlobalActionHandler(String actionID, IAction handler) { } } else if (commandId != null && actionIdByCommandId.containsKey(commandId)) { final Object value = activationsByActionId.remove(actionIdByCommandId.remove(commandId)); - if (value instanceof IHandlerActivation) { - final IHandlerActivation activation = (IHandlerActivation) value; + if (value instanceof final IHandlerActivation activation) { if (service != null) { service.deactivateHandler(activation); } @@ -566,8 +564,7 @@ public void setGlobalActionHandler(String actionID, IAction handler) { .get(serviceLocator); if ((activationsByActionId != null) && (activationsByActionId.containsKey(actionID))) { final Object value = activationsByActionId.remove(actionID); - if (value instanceof IHandlerActivation) { - final IHandlerActivation activation = (IHandlerActivation) value; + if (value instanceof final IHandlerActivation activation) { actionIdByCommandId.remove(activation.getCommandId()); service.deactivateHandler(activation); activation.getHandler().dispose(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/WorkbenchEncoding.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/WorkbenchEncoding.java index 77be387a06a..c327eb36106 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/WorkbenchEncoding.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/WorkbenchEncoding.java @@ -37,7 +37,7 @@ public class WorkbenchEncoding { private static class EncodingsRegistryReader extends RegistryReader { - private List encodings; + private final List encodings; /** * Create a new instance of the receiver. * diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/XMLMemento.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/XMLMemento.java index 944cfed2a44..2b44e95a927 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/XMLMemento.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/XMLMemento.java @@ -242,8 +242,7 @@ public IMemento getChild(String type) { // Find the first node which is a child of this node. for (int nX = 0; nX < size; nX++) { Node node = nodes.item(nX); - if (node instanceof Element) { - Element element = (Element) node; + if (node instanceof Element element) { if (element.getNodeName().equals(type)) { return new XMLMemento(factory, element); } @@ -268,8 +267,9 @@ public IMemento[] getChildren() { ArrayList list = new ArrayList<>(size); for (int nX = 0; nX < size; nX++) { final Node node = nodes.item(nX); - if (node instanceof Element) + if (node instanceof Element) { list.add((Element) node); + } } // Create a memento for each node. @@ -295,8 +295,7 @@ public IMemento[] getChildren(String type) { ArrayList list = new ArrayList<>(size); for (int nX = 0; nX < size; nX++) { Node node = nodes.item(nX); - if (node instanceof Element) { - Element element = (Element) node; + if (node instanceof Element element) { if (element.getNodeName().equals(type)) { list.add(element); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/CompoundContributionItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/CompoundContributionItem.java index f0cca207c68..ec5973b90f8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/CompoundContributionItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/CompoundContributionItem.java @@ -28,7 +28,7 @@ */ public abstract class CompoundContributionItem extends ContributionItem { - private IMenuListener menuListener = IMenuManager::markDirty; + private final IMenuListener menuListener = IMenuManager::markDirty; private IContributionItem[] oldItems; @@ -109,8 +109,7 @@ public void setParent(IContributionManager parent) { IMenuManager menuMgr = (IMenuManager) getParent(); menuMgr.removeMenuListener(menuListener); } - if (parent instanceof IMenuManager) { - IMenuManager menuMgr = (IMenuManager) parent; + if (parent instanceof IMenuManager menuMgr) { menuMgr.addMenuListener(menuListener); } super.setParent(parent); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/NewWizardAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/NewWizardAction.java index da446820586..85d3eb55a98 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/NewWizardAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/NewWizardAction.java @@ -84,7 +84,7 @@ public class NewWizardAction extends Action implements ActionFactory.IWorkbenchA /** * Tracks perspective activation, to update this action's enabled state. */ - private PerspectiveTracker tracker; + private final PerspectiveTracker tracker; /** * Create a new instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/NewWizardDropDownAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/NewWizardDropDownAction.java index 60627436c47..e6ff75fbadd 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/NewWizardDropDownAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/NewWizardDropDownAction.java @@ -47,13 +47,13 @@ public class NewWizardDropDownAction extends Action implements ActionFactory.IWo /** * Tracks perspective activation, to update this action's enabled state. */ - private PerspectiveTracker tracker; + private final PerspectiveTracker tracker; - private ActionFactory.IWorkbenchAction showDlgAction; + private final ActionFactory.IWorkbenchAction showDlgAction; - private IContributionItem newWizardMenu; + private final IContributionItem newWizardMenu; - private IMenuCreator menuCreator = new IMenuCreator() { + private final IMenuCreator menuCreator = new IMenuCreator() { private MenuManager dropDownMenuMgr; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/OpenPerspectiveAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/OpenPerspectiveAction.java index 3a748981e2b..94c4be4056c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/OpenPerspectiveAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/OpenPerspectiveAction.java @@ -79,6 +79,6 @@ public String getLocalId() { @Override public String getPluginId() { - return descriptor instanceof IPluginContribution ? ((IPluginContribution) descriptor).getPluginId() : null; + return descriptor instanceof IPluginContribution i ? i.getPluginId() : null; } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/PerspectiveMenu.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/PerspectiveMenu.java index daf07bc84b6..81b12671956 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/PerspectiveMenu.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/PerspectiveMenu.java @@ -78,7 +78,7 @@ public abstract class PerspectiveMenu extends ContributionItem { @Deprecated protected static final String SHOW_PERSP_ID = IWorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE; - private IPerspectiveRegistry reg; + private final IPerspectiveRegistry reg; private IWorkbenchWindow window; @@ -86,13 +86,13 @@ public abstract class PerspectiveMenu extends ContributionItem { private boolean dirty = true; - private IMenuListener menuListener = manager -> { + private final IMenuListener menuListener = manager -> { manager.markDirty(); dirty = true; }; - private Comparator comparator = new Comparator<>() { - private Collator collator = Collator.getInstance(); + private final Comparator comparator = new Comparator<>() { + private final Collator collator = Collator.getInstance(); @Override public int compare(IPerspectiveDescriptor ob1, IPerspectiveDescriptor ob2) { @@ -114,14 +114,14 @@ public int compare(IPerspectiveDescriptor ob1, IPerspectiveDescriptor ob2) { * * @since 3.1 */ - private Map actions = new HashMap<>(); + private final Map actions = new HashMap<>(); /** * The action for that allows the user to choose any perspective to open. * * @since 3.1 */ - private Action openOtherAction = new Action(WorkbenchMessages.PerspectiveMenu_otherItem) { + private final Action openOtherAction = new Action(WorkbenchMessages.PerspectiveMenu_otherItem) { @Override public final void runWithEvent(final Event event) { runOther(new SelectionEvent(event)); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/QuickMenuCreator.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/QuickMenuCreator.java index d525bc124b9..43c22be37a8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/QuickMenuCreator.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/QuickMenuCreator.java @@ -93,16 +93,13 @@ protected Point computeMenuLocation(Control focus) { Point cursorLocation = focus.getDisplay().getCursorLocation(); Rectangle clientArea = null; Point result = null; - if (focus instanceof StyledText) { - StyledText styledText = (StyledText) focus; + if (focus instanceof StyledText styledText) { clientArea = styledText.getClientArea(); result = computeMenuLocation(styledText); - } else if (focus instanceof Tree) { - Tree tree = (Tree) focus; + } else if (focus instanceof Tree tree) { clientArea = tree.getClientArea(); result = computeMenuLocation(tree); - } else if (focus instanceof Table) { - Table table = (Table) focus; + } else if (focus instanceof Table table) { clientArea = table.getClientArea(); result = computeMenuLocation(table); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/RetargetAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/RetargetAction.java index d804a16b705..34d3cf07544 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/RetargetAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/RetargetAction.java @@ -55,7 +55,7 @@ public class RetargetAction extends PartEventAction implements ActionFactory.IWo private IAction handler; - private IPropertyChangeListener propertyChangeListener = RetargetAction.this::propagateChange; + private final IPropertyChangeListener propertyChangeListener = RetargetAction.this::propagateChange; /** * Constructs a RetargetAction with the given action id and text. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/SelectionProviderAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/SelectionProviderAction.java index 7112f684c1f..4415114b428 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/SelectionProviderAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/SelectionProviderAction.java @@ -45,7 +45,7 @@ public abstract class SelectionProviderAction extends Action implements ISelecti /** * The selection provider that is the target of this action. */ - private ISelectionProvider provider; + private final ISelectionProvider provider; /** * Creates a new action with the given text that monitors selection changes diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/WorkingSetFilterActionGroup.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/WorkingSetFilterActionGroup.java index 917afa8ee81..4ddeff024ad 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/WorkingSetFilterActionGroup.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/actions/WorkingSetFilterActionGroup.java @@ -139,10 +139,11 @@ protected IContributionItem[] getContributionItems() { public void fillActionBars(IActionBars actionBars) { menuManager = actionBars.getMenuManager(); - if (menuManager.find(IWorkbenchActionConstants.MB_ADDITIONS) != null) + if (menuManager.find(IWorkbenchActionConstants.MB_ADDITIONS) != null) { menuManager.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS, new Separator(WORKING_SET_ACTION_GROUP)); - else + } else { menuManager.add(new Separator(WORKING_SET_ACTION_GROUP)); + } menuManager.appendToGroup(WORKING_SET_ACTION_GROUP, selectWorkingSetAction); menuManager.appendToGroup(WORKING_SET_ACTION_GROUP, clearWorkingSetAction); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivitiesPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivitiesPreferencePage.java index 82a6343404e..1d6b408c202 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivitiesPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivitiesPreferencePage.java @@ -70,7 +70,7 @@ public final class ActivitiesPreferencePage extends PreferencePage private ActivityEnabler enabler; - private Properties strings = new Properties(); + private final Properties strings = new Properties(); private IMutableActivityManager workingCopy; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityCategoryPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityCategoryPreferencePage.java index 1c219bbb88d..4ebc1d23aea 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityCategoryPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityCategoryPreferencePage.java @@ -119,11 +119,11 @@ public final class ActivityCategoryPreferencePage extends PreferencePage private class CategoryLabelProvider extends LabelProvider implements ITableLabelProvider, IActivityManagerListener { - private LocalResourceManager manager = new LocalResourceManager(JFaceResources.getResources()); + private final LocalResourceManager manager = new LocalResourceManager(JFaceResources.getResources()); - private Optional lockDescriptor; + private final Optional lockDescriptor; - private boolean decorate; + private final boolean decorate; /** * @param decorate true if the label image may be decorated @@ -223,7 +223,7 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { private boolean allowAdvanced = false; - private Properties strings = new Properties(); + private final Properties strings = new Properties(); private ActivityEnabler enabler; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityEvent.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityEvent.java index 61fd8ef5e2e..54779b0a650 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityEvent.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityEvent.java @@ -26,21 +26,21 @@ * @see IActivityListener#activityChanged(ActivityEvent) */ public final class ActivityEvent { - private IActivity activity; + private final IActivity activity; - private boolean activityRequirementBindingsChanged; + private final boolean activityRequirementBindingsChanged; - private boolean activityPatternBindingsChanged; + private final boolean activityPatternBindingsChanged; - private boolean definedChanged; + private final boolean definedChanged; - private boolean enabledChanged; + private final boolean enabledChanged; - private boolean defaultEnabledChanged; + private final boolean defaultEnabledChanged; - private boolean nameChanged; + private final boolean nameChanged; - private boolean descriptionChanged; + private final boolean descriptionChanged; /** * Creates a new instance of this class. Since 3.1 this method will assume that diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityManagerEvent.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityManagerEvent.java index 4daf5063735..8b92c86cfe2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityManagerEvent.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/ActivityManagerEvent.java @@ -34,13 +34,13 @@ * @see IActivityManagerListener#activityManagerChanged(ActivityManagerEvent) */ public final class ActivityManagerEvent { - private IActivityManager activityManager; + private final IActivityManager activityManager; - private boolean definedActivityIdsChanged; + private final boolean definedActivityIdsChanged; - private boolean definedCategoryIdsChanged; + private final boolean definedCategoryIdsChanged; - private boolean enabledActivityIdsChanged; + private final boolean enabledActivityIdsChanged; /** * Indicates whether enabled IDs of non-expression-controlled activities have diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/CategoryEvent.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/CategoryEvent.java index 255551e9027..e37aa2b29d0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/CategoryEvent.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/CategoryEvent.java @@ -27,15 +27,15 @@ * @see ICategoryListener#categoryChanged(CategoryEvent) */ public final class CategoryEvent { - private ICategory category; + private final ICategory category; - private boolean categoryActivityBindingsChanged; + private final boolean categoryActivityBindingsChanged; - private boolean definedChanged; + private final boolean definedChanged; - private boolean nameChanged; + private final boolean nameChanged; - private boolean descriptionChanged; + private final boolean descriptionChanged; /** * Creates a new instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/IdentifierEvent.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/IdentifierEvent.java index 54e64a1918b..34ca40ab00e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/IdentifierEvent.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/IdentifierEvent.java @@ -28,11 +28,11 @@ * @see IIdentifierListener#identifierChanged(IdentifierEvent) */ public final class IdentifierEvent { - private boolean activityIdsChanged; + private final boolean activityIdsChanged; - private boolean enabledChanged; + private final boolean enabledChanged; - private IIdentifier identifier; + private final IIdentifier identifier; /** * Creates a new instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/WorkbenchActivityHelper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/WorkbenchActivityHelper.java index 5778900a850..a2258bc97bc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/WorkbenchActivityHelper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/WorkbenchActivityHelper.java @@ -93,8 +93,7 @@ public static boolean allowUseOf(ITriggerPoint triggerPoint, Object object) { if (triggerPoint == null) { return true; } - if (object instanceof IPluginContribution) { - IPluginContribution contribution = (IPluginContribution) object; + if (object instanceof IPluginContribution contribution) { IIdentifier identifier = getIdentifier(contribution); return allow(triggerPoint, identifier); } @@ -197,8 +196,7 @@ private static void enableActivities(Collection activities) { * @see #createUnifiedId(IPluginContribution) */ public static boolean filterItem(Object object) { - if (object instanceof IPluginContribution) { - IPluginContribution contribution = (IPluginContribution) object; + if (object instanceof IPluginContribution contribution) { IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI.getWorkbench().getActivitySupport(); IIdentifier identifier = workbenchActivitySupport.getActivityManager() .getIdentifier(createUnifiedId(contribution)); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/WorkbenchTriggerPointAdvisor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/WorkbenchTriggerPointAdvisor.java index 02527b630f6..af0d28b9bcd 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/WorkbenchTriggerPointAdvisor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/activities/WorkbenchTriggerPointAdvisor.java @@ -69,7 +69,7 @@ public class WorkbenchTriggerPointAdvisor implements ITriggerPointAdvisor, IExec */ public static String NO_DETAILS = "noDetails"; //$NON-NLS-1$ - private Properties strings = new Properties(); + private final Properties strings = new Properties(); /** * Create a new instance of this advisor. @@ -88,10 +88,11 @@ public Set allow(ITriggerPoint triggerPoint, IIdentifier identifier) { String id = iterator.next(); IActivity activity = activityManager.getActivity(id); if (activity.getExpression() != null) { - if (!activity.isEnabled()) + if (!activity.isEnabled()) { // if we have any disabled expression activities we // should disallow immediately return null; + } } } // if we have no disabled expression activities just return the diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/ActionBarAdvisor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/ActionBarAdvisor.java index 51a73ee5d0d..54e9be8d6e6 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/ActionBarAdvisor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/ActionBarAdvisor.java @@ -81,9 +81,9 @@ public class ActionBarAdvisor { */ public static final int FILL_STATUS_LINE = 0x08; - private IActionBarConfigurer actionBarConfigurer; + private final IActionBarConfigurer actionBarConfigurer; - private Map actions = new HashMap<>(); + private final Map actions = new HashMap<>(); private boolean menuCreated; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/WorkbenchAdvisor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/WorkbenchAdvisor.java index 7e4073edcdd..441bc25deaf 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/WorkbenchAdvisor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/WorkbenchAdvisor.java @@ -766,18 +766,20 @@ public void runWithException() throws Throwable { while (true) { if (!display.readAndDispatch()) { - if (initDone) + if (initDone) { break; + } display.sleep(); } } // can only be a runtime or error - if (error[0] instanceof Error) + if (error[0] instanceof Error) { throw (Error) error[0]; - else if (error[0] instanceof RuntimeException) + } else if (error[0] instanceof RuntimeException) { throw (RuntimeException) error[0]; + } return result[0]; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/WorkbenchWindowAdvisor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/WorkbenchWindowAdvisor.java index 5995b0f0ec4..826bbf307af 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/WorkbenchWindowAdvisor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/WorkbenchWindowAdvisor.java @@ -66,7 +66,7 @@ */ public class WorkbenchWindowAdvisor { - private IWorkbenchWindowConfigurer windowConfigurer; + private final IWorkbenchWindowConfigurer windowConfigurer; /** * Creates a new workbench window advisor for configuring a workbench window via diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/browser/AbstractWebBrowser.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/browser/AbstractWebBrowser.java index c7f729e2fad..29e87546515 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/browser/AbstractWebBrowser.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/browser/AbstractWebBrowser.java @@ -21,7 +21,7 @@ * @since 3.1 */ public abstract class AbstractWebBrowser implements IWebBrowser { - private String id; + private final String id; /** * The constructor that accepts the unique browser identifier. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/databinding/typed/WorkbenchProperties.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/databinding/typed/WorkbenchProperties.java index daeb2fcd53c..c7c1112c25c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/databinding/typed/WorkbenchProperties.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/databinding/typed/WorkbenchProperties.java @@ -232,7 +232,7 @@ public static IValueProperty IValueProperty activePartAsEditorReference() { return WorkbenchProperties.activePartReference().value(Properties.convertedValue(IEditorReference.class, - part -> part instanceof IEditorReference ? (IEditorReference) part : null)); + part -> part instanceof IEditorReference i ? i : null)); } /** diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/AbstractElementListSelectionDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/AbstractElementListSelectionDialog.java index af468d2dc44..d75175113e9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/AbstractElementListSelectionDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/AbstractElementListSelectionDialog.java @@ -42,7 +42,7 @@ */ public abstract class AbstractElementListSelectionDialog extends SelectionStatusDialog { - private ILabelProvider fRenderer; + private final ILabelProvider fRenderer; private boolean fIgnoreCase = true; @@ -201,8 +201,9 @@ protected void setListElements(Object[] elements) { protected void handleElementsChanged() { boolean enabled = !fFilteredList.isEmpty(); - if (fMessage != null && !fMessage.isDisposed()) + if (fMessage != null && !fMessage.isDisposed()) { fMessage.setEnabled(enabled); + } fFilteredList.setEnabled(enabled); updateOkState(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/CheckedTreeSelectionDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/CheckedTreeSelectionDialog.java index 53984c6c690..7aba2723823 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/CheckedTreeSelectionDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/CheckedTreeSelectionDialog.java @@ -54,9 +54,9 @@ public class CheckedTreeSelectionDialog extends SelectionStatusDialog { private CheckboxTreeViewer fViewer; - private ILabelProvider fLabelProvider; + private final ILabelProvider fLabelProvider; - private ITreeContentProvider fContentProvider; + private final ITreeContentProvider fContentProvider; private ISelectionStatusValidator fValidator = null; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ContainerCheckedTreeViewer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ContainerCheckedTreeViewer.java index 591d4855bdd..c1184bc168e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ContainerCheckedTreeViewer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ContainerCheckedTreeViewer.java @@ -93,8 +93,7 @@ public void treeExpanded(TreeExpansionEvent event) { */ protected void doCheckStateChanged(Object element) { Widget item = findItem(element); - if (item instanceof TreeItem) { - TreeItem treeItem = (TreeItem) item; + if (item instanceof TreeItem treeItem) { treeItem.setGrayed(false); updateChildrenItems(treeItem); updateParentItems(treeItem.getParentItem()); @@ -113,8 +112,7 @@ private void doCheckStateChanged(Object[] elements) { HashSet parents = new HashSet<>(); for (Object element : elements) { Widget item = findItem(element); - if (item instanceof TreeItem) { - TreeItem treeItem = (TreeItem) item; + if (item instanceof TreeItem treeItem) { treeItem.setGrayed(false); updateChildrenItems(treeItem); TreeItem parentItem = treeItem.getParentItem(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/EditorSelectionDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/EditorSelectionDialog.java index 4c5e5397fb0..4b27db31122 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/EditorSelectionDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/EditorSelectionDialog.java @@ -147,7 +147,7 @@ public boolean hasChildren(Object element) { private IEditorDescriptor[] editorsToFilter; - private DialogListener listener = new DialogListener(); + private final DialogListener listener = new DialogListener(); private ResourceManager resourceManager; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ElementTreeSelectionDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ElementTreeSelectionDialog.java index 96df18b1b24..1b8dded1c01 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ElementTreeSelectionDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ElementTreeSelectionDialog.java @@ -55,9 +55,9 @@ public class ElementTreeSelectionDialog extends SelectionStatusDialog { private TreeViewer fViewer; - private IBaseLabelProvider fLabelProvider; + private final IBaseLabelProvider fLabelProvider; - private ITreeContentProvider fContentProvider; + private final ITreeContentProvider fContentProvider; private ISelectionStatusValidator fValidator = null; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FileEditorMappingLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FileEditorMappingLabelProvider.java index bbf6cd78f49..ca7fd7680b3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FileEditorMappingLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FileEditorMappingLabelProvider.java @@ -46,7 +46,7 @@ public class FileEditorMappingLabelProvider extends LabelProvider implements ITa /** * Images that will require disposal. */ - private List imagesToDispose = new ArrayList<>(); + private final List imagesToDispose = new ArrayList<>(); /** * Creates an instance of this class. The private visibility of this constructor diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FileSystemElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FileSystemElement.java index 6714493f60f..e5bbf62a472 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FileSystemElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FileSystemElement.java @@ -37,7 +37,7 @@ * IWorkbenchAdapter adapter used for navigation and display in the workbench. */ public class FileSystemElement implements IAdaptable { - private String name; + private final String name; private Object fileSystemObject; @@ -54,7 +54,7 @@ public class FileSystemElement implements IAdaptable { private FileSystemElement parent; - private IWorkbenchAdapter workbenchAdapter = new IWorkbenchAdapter() { + private final IWorkbenchAdapter workbenchAdapter = new IWorkbenchAdapter() { /** * Answer the children property of this element */ diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java index a9f4469c386..5da18768f29 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java @@ -181,7 +181,7 @@ public abstract class FilteredItemsSelectionDialog extends SelectionStatusDialog private MenuManager contextMenuManager; - private boolean multi; + private final boolean multi; private ToolBar toolBar; @@ -197,17 +197,17 @@ public abstract class FilteredItemsSelectionDialog extends SelectionStatusDialog private IStatus status; - private RefreshCacheJob refreshCacheJob; + private final RefreshCacheJob refreshCacheJob; - private RefreshProgressMessageJob refreshProgressMessageJob = new RefreshProgressMessageJob(); + private final RefreshProgressMessageJob refreshProgressMessageJob = new RefreshProgressMessageJob(); private Object[] currentSelection; - private ContentProvider contentProvider; + private final ContentProvider contentProvider; - private FilterHistoryJob filterHistoryJob; + private final FilterHistoryJob filterHistoryJob; - private FilterJob filterJob; + private final FilterJob filterJob; private ItemsFilter filter; @@ -394,10 +394,12 @@ public boolean close() { showViewHandler.getHandler().dispose(); showViewHandler = null; } - if (menuManager != null) + if (menuManager != null) { menuManager.dispose(); - if (contextMenuManager != null) + } + if (contextMenuManager != null) { contextMenuManager.dispose(); + } storeDialog(getDialogSettings()); return super.close(); } @@ -680,8 +682,9 @@ public void keyPressed(KeyEvent e) { break; } } - if (isSelectedHistory) + if (isSelectedHistory) { removeSelectedItems(selectedElements); + } } @@ -693,8 +696,9 @@ public void keyPressed(KeyEvent e) { if (element.equals(tableViewer.getElementAt(0))) { pattern.setFocus(); } - if (tableViewer.getElementAt(tableViewer.getTable().getSelectionIndex() - 1) instanceof ItemsListSeparator) + if (tableViewer.getElementAt(tableViewer.getTable().getSelectionIndex() - 1) instanceof ItemsListSeparator) { tableViewer.getTable().setSelection(tableViewer.getTable().getSelectionIndex() - 1); + } tableViewer.getTable().notifyListeners(SWT.Selection, new Event()); } @@ -702,8 +706,9 @@ public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_DOWN && (e.stateMask & SWT.SHIFT) != 0 && (e.stateMask & SWT.CTRL) != 0) { - if (tableViewer.getElementAt(tableViewer.getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator) + if (tableViewer.getElementAt(tableViewer.getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator) { tableViewer.getTable().setSelection(tableViewer.getTable().getSelectionIndex() + 1); + } tableViewer.getTable().notifyListeners(SWT.Selection, new Event()); } @@ -1055,8 +1060,9 @@ protected StructuredSelection getSelectedItems() { } } - if (itemToRemove == null) + if (itemToRemove == null) { return new StructuredSelection(selectedItems); + } // Create a new selection without the collision List newItems = new ArrayList<>(selectedItems); newItems.remove(itemToRemove); @@ -1190,8 +1196,9 @@ protected SelectionHistory getSelectionHistory() { * @param selectionHistory the history */ protected void setSelectionHistory(SelectionHistory selectionHistory) { - if (this.contentProvider != null) + if (this.contentProvider != null) { this.contentProvider.setSelectionHistory(selectionHistory); + } } /** @@ -1297,8 +1304,9 @@ public RefreshJob() { @Override public IStatus runInUIThread(IProgressMonitor monitor) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return new Status(IStatus.OK, WorkbenchPlugin.PI_WORKBENCH, IStatus.OK, EMPTY_STRING, null); + } if (FilteredItemsSelectionDialog.this != null) { FilteredItemsSelectionDialog.this.refresh(); @@ -1369,7 +1377,7 @@ public void scheduleProgressRefresh(GranualProgressMonitor progressMonitor) { */ private class RefreshCacheJob extends Job { - private RefreshJob refreshJob = new RefreshJob(); + private final RefreshJob refreshJob = new RefreshJob(); /** * Creates a new instance of the class. @@ -1440,7 +1448,7 @@ private class ItemsListLabelProvider extends StyledCellLabelProvider implements private ILabelDecorator selectionDecorator; // Need to keep our own list of listeners - private ListenerList listeners = new ListenerList<>(); + private final ListenerList listeners = new ListenerList<>(); /** * Creates a new instance of the class. @@ -1520,8 +1528,9 @@ private Image getImage(Object element) { private boolean isSelected(Object element) { if (element != null && currentSelection != null) { for (Object entry : currentSelection) { - if (element.equals(entry)) + if (element.equals(entry)) { return true; + } } } return false; @@ -1555,8 +1564,7 @@ private StyledString getStyledText(Object element, IStyledLabelProvider provider public void update(ViewerCell cell) { Object element = cell.getElement(); - if (!(element instanceof ItemsListSeparator) && provider instanceof IStyledLabelProvider) { - IStyledLabelProvider styledLabelProvider = (IStyledLabelProvider) provider; + if (!(element instanceof ItemsListSeparator) && provider instanceof IStyledLabelProvider styledLabelProvider) { StyledString styledString = getStyledText(element, styledLabelProvider); cell.setText(styledString.getString()); @@ -1680,7 +1688,7 @@ public void labelProviderChanged(LabelProviderChangedEvent event) { */ private static class ItemsListSeparator { - private String name; + private final String name; /** * Creates a new instance of the class. @@ -1753,8 +1761,9 @@ public void subTask(String name) { @Override public void beginTask(String name, int totalWork) { super.beginTask(name, totalWork); - if (this.name == null) + if (this.name == null) { this.name = name; + } this.totalWork = totalWork; refreshProgressMessageJob.scheduleProgressRefresh(this); } @@ -1783,8 +1792,9 @@ public void internalWorked(double work) { } private String getMessage() { - if (done) + if (done) { return ""; //$NON-NLS-1$ + } String message; @@ -1795,8 +1805,9 @@ private String getMessage() { : NLS.bind(WorkbenchMessages.FilteredItemsSelectionDialog_subtaskProgressMessage, new Object[] { name, subName }); } - if (totalWork == 0) + if (totalWork == 0) { return message; + } return NLS.bind(WorkbenchMessages.FilteredItemsSelectionDialog_taskProgressMessage, new Object[] { message, Integer.valueOf((int) ((worked * 100) / totalWork)) }); @@ -1834,8 +1845,9 @@ protected IStatus run(IProgressMonitor monitor) { contentProvider.addHistoryItems(itemsFilter); - if (!(lastCompletedFilter != null && lastCompletedFilter.isSubFilter(this.itemsFilter))) + if (!(lastCompletedFilter != null && lastCompletedFilter.isSubFilter(this.itemsFilter))) { contentProvider.refresh(); + } filterJob.schedule(); @@ -1900,8 +1912,9 @@ protected IStatus doRun(GranualProgressMonitor monitor) { */ private void internalRun(GranualProgressMonitor monitor) throws CoreException { try { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return; + } this.itemsFilter = filter; @@ -1909,8 +1922,9 @@ private void internalRun(GranualProgressMonitor monitor) throws CoreException { filterContent(monitor); } - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return; + } contentProvider.refresh(); } finally { @@ -1934,8 +1948,9 @@ protected void filterContent(GranualProgressMonitor monitor) throws CoreExceptio for (int pos = 0; pos < lastCompletedResult.size(); pos++) { Object item = lastCompletedResult.get(pos); - if (monitor.isCanceled()) + if (monitor.isCanceled()) { break; + } contentProvider.add(item, itemsFilter); if ((pos % 500) == 0) { @@ -2256,8 +2271,9 @@ public boolean matchesRawNamePattern(Object item) { String prefix = patternMatcher.getPattern(); String text = getElementName(item); - if (text == null) + if (text == null) { return false; + } int textLength = text.length(); int prefixLength = prefix.length(); @@ -2265,8 +2281,9 @@ public boolean matchesRawNamePattern(Object item) { return false; } for (int i = prefixLength - 1; i >= 0; i--) { - if (Character.toLowerCase(prefix.charAt(i)) != Character.toLowerCase(text.charAt(i))) + if (Character.toLowerCase(prefix.charAt(i)) != Character.toLowerCase(text.charAt(i))) { return false; + } } return true; } @@ -2335,12 +2352,12 @@ private class ContentProvider extends AbstractContentProvider * Standard object flow: * {@code items -> lastSortedItems -> lastFilteredItems} */ - private Set items; + private final Set items; /** * Items that are duplicates. */ - private Set duplicates; + private final Set duplicates; /** * List of ViewerFilters to be used during filtering @@ -2361,7 +2378,7 @@ private class ContentProvider extends AbstractContentProvider * Standard object flow: * {@code items -> lastSortedItems -> lastFilteredItems} */ - private List lastSortedItems; + private final List lastSortedItems; /** * Used for getFilteredItems() method canceling (when the job that @@ -2474,8 +2491,9 @@ public void refresh() { * @return removed item */ public Object removeHistoryElement(Object item) { - if (this.selectionHistory != null) + if (this.selectionHistory != null) { this.selectionHistory.remove(item); + } if (filter == null || filter.getPattern().isEmpty()) { items.remove(item); duplicates.remove(item); @@ -2494,8 +2512,9 @@ public Object removeHistoryElement(Object item) { * @param item to add */ public void addHistoryElement(Object item) { - if (this.selectionHistory != null) + if (this.selectionHistory != null) { this.selectionHistory.accessed(item); + } if (filter == null || !filter.matchItem(item)) { this.items.remove(item); this.duplicates.remove(item); @@ -2527,10 +2546,11 @@ public boolean isHistoryElement(Object item) { */ public void setDuplicateElement(Object item, boolean isDuplicate) { if (this.items.contains(item)) { - if (isDuplicate) + if (isDuplicate) { this.duplicates.add(item); - else + } else { this.duplicates.remove(item); + } } } @@ -2663,8 +2683,9 @@ private void checkDuplicates(IProgressMonitor monitor) { lastFilteredItems.size()); HashMap helperMap = new HashMap<>(); for (Object item : lastFilteredItems) { - if (reset || subMonitor.isCanceled()) + if (reset || subMonitor.isCanceled()) { return; + } if (!(item instanceof ItemsListSeparator)) { Object previousItem = helperMap.put(getElementName(item), item); @@ -2799,14 +2820,14 @@ public void addFilter(ViewerFilter filter) { */ private class DetailsContentViewer extends ContentViewer { - private CLabel label; + private final CLabel label; /** * Unfortunately, it was impossible to delegate displaying border to label. The * ViewForm is used because CLabel displays shadow * when border is present. */ - private ViewForm viewForm; + private final ViewForm viewForm; /** * Constructs a new instance of this class given its parent and a style value diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredList.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredList.java index 1180b1324e6..4ff64cd4df4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredList.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredList.java @@ -86,7 +86,7 @@ public boolean match(Object element) { } } - private Table fList; + private final Table fList; ILabelProvider fLabelProvider; @@ -98,7 +98,7 @@ public boolean match(Object element) { private String fFilter = ""; //$NON-NLS-1$ - private TwoArrayQuickSorter fSorter; + private final TwoArrayQuickSorter fSorter; Object[] fElements = new Object[0]; @@ -175,7 +175,7 @@ public boolean equals(Label label) { } private final class LabelComparator implements Comparator { - private boolean labelIgnoreCase; + private final boolean labelIgnoreCase; LabelComparator(boolean ignoreCase) { labelIgnoreCase = ignoreCase; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredTree.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredTree.java index 051ae9f8a21..a14dcc42d1b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredTree.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/FilteredTree.java @@ -443,8 +443,9 @@ && recursiveExpand(items, monitor, stopTime, new int[] { numVisibleItems })) { if (items.length > 0 && getViewer().getTree().getSelectionCount() == 0) { treeViewer.getTree().setTopItem(items[0]); } - if (quickSelectionMode) + if (quickSelectionMode) { updateTreeSelection(false); + } redrawFalseControl.setRedraw(true); } return Status.OK_STATUS; @@ -583,8 +584,9 @@ public void keyPressed(KeyEvent e) { protected void updateTreeSelection(boolean setFocus) { Tree tree = getViewer().getTree(); if (tree.getItemCount() == 0) { - if (setFocus) + if (setFocus) { Display.getCurrent().beep(); + } } else { // if the initial filter text hasn't changed, do not try // to match @@ -592,10 +594,11 @@ protected void updateTreeSelection(boolean setFocus) { boolean textChanged = !getInitialText().equals(filterText.getText().trim()); if (hasFocus && textChanged && filterText.getText().trim().length() > 0) { TreeItem item; - if (tree.getSelectionCount() > 0) + if (tree.getSelectionCount() > 0) { item = getFirstMatchingItem(tree.getSelection()); - else + } else { item = getFirstMatchingItem(tree.getItems()); + } if (item != null) { tree.setSelection(new TreeItem[] { item }); ISelection sel = getViewer().getSelection(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ListSelectionDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ListSelectionDialog.java index 856f7d12e72..0474dfc15b4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ListSelectionDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/ListSelectionDialog.java @@ -65,12 +65,12 @@ */ public class ListSelectionDialog extends SelectionDialog { // the root element to populate the viewer with - private Object inputElement; + private final Object inputElement; // providers for populating this dialog - private ILabelProvider labelProvider; + private final ILabelProvider labelProvider; - private IStructuredContentProvider contentProvider; + private final IStructuredContentProvider contentProvider; // the visual selection widget group CheckboxTableViewer listViewer; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PatternFilter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PatternFilter.java index 87746c48cb8..82ea5f8282f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PatternFilter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PatternFilter.java @@ -39,12 +39,12 @@ public class PatternFilter extends ViewerFilter { /* * Cache of filtered elements in the tree */ - private Map cache = new HashMap(); + private final Map cache = new HashMap(); /* * Maps parent elements to TRUE or FALSE */ - private Map foundAnyCache = new HashMap(); + private final Map foundAnyCache = new HashMap(); private boolean useCache = false; @@ -168,8 +168,9 @@ public void setPattern(String patternString) { matcher = null; } else { String pattern = patternString; - if (!patternString.endsWith(" ")) //$NON-NLS-1$ + if (!patternString.endsWith(" ")) { //$NON-NLS-1$ pattern += "*"; //$NON-NLS-1$ + } if (includeLeadingWildcard) { pattern = "*" + pattern; //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PreferenceLinkArea.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PreferenceLinkArea.java index 9af8dadfdeb..c8fdad43189 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PreferenceLinkArea.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PreferenceLinkArea.java @@ -35,7 +35,7 @@ */ public class PreferenceLinkArea extends Object { - private Link pageLink; + private final Link pageLink; /** * Create a new instance of the receiver diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PreferencesUtil.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PreferencesUtil.java index c6969fad915..6bacd4f76ef 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PreferencesUtil.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PreferencesUtil.java @@ -254,8 +254,9 @@ public static PreferenceDialog createPropertyDialogOn(Shell shell, final IAdapta public static PreferenceDialog createPropertyDialogOn(Shell shell, final Object element, String propertyPageId, String[] displayedIds, Object data, int options) { FilteredPreferenceDialog dialog = PropertyDialog.createDialogOn(shell, propertyPageId, element); - if (dialog == null) + if (dialog == null) { return null; + } applyOptions(data, displayedIds, dialog, options); return dialog; } @@ -269,8 +270,9 @@ public static PreferenceDialog createPropertyDialogOn(Shell shell, final Object * @since 3.4 */ public static boolean hasPropertiesContributors(Object element) { - if (element == null || !(element instanceof IAdaptable)) + if (element == null || !(element instanceof IAdaptable)) { return false; + } Collection contributors = PropertyPageContributorManager.getManager().getApplicableContributors(element); return contributors != null && contributors.size() > 0; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PropertyDialogAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PropertyDialogAction.java index 948e751e79d..68b232a2699 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PropertyDialogAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/PropertyDialogAction.java @@ -55,7 +55,7 @@ public class PropertyDialogAction extends SelectionProviderAction { /** * Provides the shell in which to open the property dialog. */ - private IShellProvider shellProvider; + private final IShellProvider shellProvider; /** * The id of the page to open up on. @@ -164,8 +164,9 @@ public void run() { * @since 3.1 */ public PreferenceDialog createDialog() { - if (getStructuredSelection().isEmpty()) + if (getStructuredSelection().isEmpty()) { return null; + } return PropertyDialog.createDialogOn(shellProvider.getShell(), initialPageId, getStructuredSelection()); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/SearchPattern.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/SearchPattern.java index b30e9fdf835..0ff694213f0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/SearchPattern.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/SearchPattern.java @@ -130,9 +130,9 @@ public class SearchPattern { private static final char BLANK = ' '; - private int allowedRules; + private final int allowedRules; - private boolean substringSearch; + private final boolean substringSearch; private boolean matchPrefix; @@ -295,11 +295,13 @@ private void initializePatternAndMatchRule(String pattern) { private boolean startsWithIgnoreCase(String text, String prefix) { int textLength = text.length(); int prefixLength = prefix.length(); - if (textLength < prefixLength) + if (textLength < prefixLength) { return false; + } for (int i = prefixLength - 1; i >= 0; i--) { - if (Character.toLowerCase(prefix.charAt(i)) != Character.toLowerCase(text.charAt(i))) + if (Character.toLowerCase(prefix.charAt(i)) != Character.toLowerCase(text.charAt(i))) { return false; + } } return true; } @@ -311,8 +313,9 @@ private boolean startsWithIgnoreCase(String text, String prefix) { private boolean endsWithIgnoreCase(String text, String suffix) { int textLength = text.length(); int suffixLength = suffix.length(); - if (textLength < suffixLength) + if (textLength < suffixLength) { return false; + } return startsWithIgnoreCase(text.substring(textLength - suffixLength), suffix); } @@ -371,10 +374,12 @@ private boolean endsWithIgnoreCase(String text, String suffix) { * @return true if the pattern matches the given name, false otherwise */ private boolean camelCaseMatch(String pattern, String name) { - if (pattern == null) + if (pattern == null) { return true; // null pattern is equivalent to '*' - if (name == null) + } + if (name == null) { return false; // null name cannot match + } return camelCaseMatch(pattern, 0, pattern.length(), name, 0, name.length()); } @@ -480,19 +485,25 @@ private boolean camelCaseMatch(String pattern, String name) { */ private boolean camelCaseMatch(String pattern, int patternStart, int patternEnd, String name, int nameStart, int nameEnd) { - if (name == null) + if (name == null) { return false; // null name cannot match - if (pattern == null) + } + if (pattern == null) { return true; // null pattern is equivalent to '*' - if (patternEnd < 0) + } + if (patternEnd < 0) { patternEnd = pattern.length(); - if (nameEnd < 0) + } + if (nameEnd < 0) { nameEnd = name.length(); + } - if (patternEnd <= patternStart) + if (patternEnd <= patternStart) { return nameEnd <= nameStart; - if (nameEnd <= nameStart) + } + if (nameEnd <= nameStart) { return false; + } // check first pattern char if (name.charAt(nameStart) != pattern.charAt(patternStart)) { // first char must strictly match (upper/lower) @@ -543,8 +554,9 @@ private boolean camelCaseMatch(String pattern, int patternStart, int patternEnd, // If characters are not equals, then it's not a match if // patternChar is lowercase - if (!isPatternCharAllowed(patternChar)) + if (!isPatternCharAllowed(patternChar)) { return false; + } // patternChar is uppercase, so let's find the next patternChar-matching uppercase in // name @@ -559,8 +571,9 @@ private boolean camelCaseMatch(String pattern, int patternStart, int patternEnd, if (Character.isDigit(nameChar)) { // nameChar is digit => break if the digit is current pattern character // otherwise consume it - if (patternChar == nameChar) + if (patternChar == nameChar) { break; + } iName++; } else if (!isNameCharAllowed(nameChar)) { // nameChar is lowercase diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/TwoArrayQuickSorter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/TwoArrayQuickSorter.java index 8f4272b9a05..c73d8402c90 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/TwoArrayQuickSorter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/TwoArrayQuickSorter.java @@ -24,13 +24,13 @@ */ /* package */class TwoArrayQuickSorter { - private Comparator fComparator; + private final Comparator fComparator; /** * Default comparator. */ public static final class StringComparator implements Comparator { - private boolean fIgnoreCase; + private final boolean fIgnoreCase; StringComparator(boolean ignoreCase) { fIgnoreCase = ignoreCase; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/TwoPaneElementSelector.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/TwoPaneElementSelector.java index 1768a343b0c..b43b3c75cf9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/TwoPaneElementSelector.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/TwoPaneElementSelector.java @@ -50,7 +50,7 @@ public class TwoPaneElementSelector extends AbstractElementListSelectionDialog { */ private Comparator fLowerListComparator = null; - private ILabelProvider fQualifierRenderer; + private final ILabelProvider fQualifierRenderer; private Object[] fElements = new Object[0]; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/WorkingSetConfigurationBlock.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/WorkingSetConfigurationBlock.java index 18777e466e8..c31dd33293e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/WorkingSetConfigurationBlock.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/WorkingSetConfigurationBlock.java @@ -104,7 +104,7 @@ public static IWorkingSet[] filter(IWorkingSet[] workingSets, String[] workingSe private Button newButton; private IWorkingSet[] selectedWorkingSets; - private List selectionHistory; + private final List selectionHistory; private final IDialogSettings dialogSettings; private final String[] workingSetTypeIds; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/WorkingSetGroup.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/WorkingSetGroup.java index eed9c1e1904..5ed3b62f6d6 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/WorkingSetGroup.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/dialogs/WorkingSetGroup.java @@ -33,7 +33,7 @@ */ public final class WorkingSetGroup { - private WorkingSetConfigurationBlock workingSetBlock; + private final WorkingSetConfigurationBlock workingSetBlock; /** * Create a new instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/fieldassist/ContentAssistCommandAdapter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/fieldassist/ContentAssistCommandAdapter.java index 9b49b8f8ce0..52a95ae021e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/fieldassist/ContentAssistCommandAdapter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/fieldassist/ContentAssistCommandAdapter.java @@ -72,11 +72,11 @@ public class ContentAssistCommandAdapter extends ContentProposalAdapter { // a platform UI preference. private static final int DEFAULT_AUTO_ACTIVATION_DELAY = 500; - private IHandlerService handlerService; + private final IHandlerService handlerService; private IHandlerActivation activeHandler; - private IHandler proposalHandler = new AbstractHandler() { + private final IHandler proposalHandler = new AbstractHandler() { @Override public Object execute(ExecutionEvent event) { openProposalPopup(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/fieldassist/ContentAssistField.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/fieldassist/ContentAssistField.java index 5f8e1563d55..8d2189919b0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/fieldassist/ContentAssistField.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/fieldassist/ContentAssistField.java @@ -44,7 +44,7 @@ @Deprecated public class ContentAssistField extends DecoratedField { - private ContentAssistCommandAdapter adapter; + private final ContentAssistCommandAdapter adapter; private static final String CONTENT_ASSIST_DECORATION_ID = "org.eclipse.ui.fieldAssist.ContentAssistField"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/HandlerUtil.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/HandlerUtil.java index ce8d43f0699..d11c6fd0aa3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/HandlerUtil.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/HandlerUtil.java @@ -582,10 +582,12 @@ public static Object getShowInInputChecked(ExecutionEvent event) throws Executio */ public static boolean toggleCommandState(Command command) throws ExecutionException { State state = command.getState(RegistryToggleState.STATE_ID); - if (state == null) + if (state == null) { throw new ExecutionException("The command does not have a toggle state"); //$NON-NLS-1$ - if (!(state.getValue() instanceof Boolean)) + } + if (!(state.getValue() instanceof Boolean)) { throw new ExecutionException("The command's toggle state doesn't contain a boolean value"); //$NON-NLS-1$ + } boolean oldValue = ((Boolean) state.getValue()).booleanValue(); state.setValue(Boolean.valueOf(!oldValue)); @@ -607,15 +609,18 @@ public static boolean toggleCommandState(Command command) throws ExecutionExcept public static boolean matchesRadioState(ExecutionEvent event) throws ExecutionException { String parameter = event.getParameter(RadioState.PARAMETER_ID); - if (parameter == null) + if (parameter == null) { throw new ExecutionException("The event does not have the radio state parameter"); //$NON-NLS-1$ + } Command command = event.getCommand(); State state = command.getState(RadioState.STATE_ID); - if (state == null) + if (state == null) { throw new ExecutionException("The command does not have a radio state"); //$NON-NLS-1$ - if (!(state.getValue() instanceof String)) + } + if (!(state.getValue() instanceof String)) { throw new ExecutionException("The command's radio state doesn't contain a String value"); //$NON-NLS-1$ + } return parameter.equals(state.getValue()); } @@ -632,8 +637,9 @@ public static boolean matchesRadioState(ExecutionEvent event) throws ExecutionEx public static void updateRadioState(Command command, String newState) throws ExecutionException { State state = command.getState(RadioState.STATE_ID); - if (state == null) + if (state == null) { throw new ExecutionException("The command does not have a radio state"); //$NON-NLS-1$ + } state.setValue(newState); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RadioState.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RadioState.java index 9990ce1a299..d325de5fbf2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RadioState.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RadioState.java @@ -66,16 +66,16 @@ public void setInitializationData(IConfigurationElement config, String propertyN boolean shouldPersist = true; // persist by default if (data instanceof String) { setValue(data); - } else if (data instanceof Hashtable) { - final Hashtable parameters = (Hashtable) data; + } else if (data instanceof final Hashtable parameters) { final Object defaultObject = parameters.get("default"); //$NON-NLS-1$ if (defaultObject instanceof String) { setValue(defaultObject); } final Object persistedObject = parameters.get("persisted"); //$NON-NLS-1$ - if (persistedObject instanceof String && "false".equalsIgnoreCase(((String) persistedObject))) //$NON-NLS-1$ + if (persistedObject instanceof String && "false".equalsIgnoreCase(((String) persistedObject))) { //$NON-NLS-1$ shouldPersist = false; + } } setShouldPersist(shouldPersist); @@ -83,17 +83,20 @@ public void setInitializationData(IConfigurationElement config, String propertyN @Override public void load(IPreferenceStore store, String preferenceKey) { - if (!shouldPersist()) + if (!shouldPersist()) { return; + } final String value = store.getString(preferenceKey); - if (value.length() != 0) + if (value.length() != 0) { setValue(value); + } } @Override public void save(IPreferenceStore store, String preferenceKey) { - if (!shouldPersist()) + if (!shouldPersist()) { return; + } final Object value = getValue(); if (value instanceof String) { store.setValue(preferenceKey, (String) value); @@ -102,8 +105,9 @@ public void save(IPreferenceStore store, String preferenceKey) { @Override public void setValue(Object value) { - if (!(value instanceof String)) + if (!(value instanceof String)) { return; // we set only String values + } super.setValue(value); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RegistryRadioState.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RegistryRadioState.java index ea6fec5c10f..a8f4b70d472 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RegistryRadioState.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RegistryRadioState.java @@ -82,9 +82,7 @@ public void setInitializationData(final IConfigurationElement configurationEleme setValue(Boolean.FALSE); setShouldPersist(true); - } else if (data instanceof Hashtable) { - final Hashtable parameters = (Hashtable) data; - + } else if (data instanceof final Hashtable parameters) { final Object defaultObject = parameters.get("default"); //$NON-NLS-1$ if (defaultObject instanceof String) { readDefault((String) defaultObject); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RegistryToggleState.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RegistryToggleState.java index 2f75f2f675f..7c0016a369d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RegistryToggleState.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/handlers/RegistryToggleState.java @@ -84,8 +84,7 @@ public void setInitializationData(final IConfigurationElement configurationEleme readDefault((String) data); setShouldPersist(true); - } else if (data instanceof Hashtable) { - final Hashtable parameters = (Hashtable) data; + } else if (data instanceof final Hashtable parameters) { final Object defaultObject = parameters.get("default"); //$NON-NLS-1$ if (defaultObject instanceof String) { readDefault((String) defaultObject); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/AbstractWorkingSetManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/AbstractWorkingSetManager.java index 3a028af510b..f6c96cfbc46 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/AbstractWorkingSetManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/AbstractWorkingSetManager.java @@ -93,15 +93,15 @@ public void handleException(Throwable exception) { } } - private SortedSet workingSets = new TreeSet<>( + private final SortedSet workingSets = new TreeSet<>( (o1, o2) -> o1.getUniqueId().compareTo(o2.getUniqueId())); - private List recentWorkingSets = new ArrayList<>(); + private final List recentWorkingSets = new ArrayList<>(); - private BundleContext bundleContext; - private Map updaters = new HashMap<>(); + private final BundleContext bundleContext; + private final Map updaters = new HashMap<>(); - private Map elementAdapters = new HashMap<>(); + private final Map elementAdapters = new HashMap<>(); private static final IWorkingSetUpdater NULL_UPDATER = new IWorkingSetUpdater() { @Override @@ -876,8 +876,9 @@ public void run() throws Exception { @Override public void setRecentWorkingSetsLength(int length) { - if (length < 1 || length > 99) + if (length < 1 || length > 99) { throw new IllegalArgumentException("Invalid recent working sets length: " + length); //$NON-NLS-1$ + } IPreferenceStore store = PrefUtil.getAPIPreferenceStore(); store.setValue(IWorkbenchPreferenceConstants.RECENTLY_USED_WORKINGSETS_SIZE, length); // adjust length diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionDescriptor.java index 1726e052fc1..b9350ebfa6e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionDescriptor.java @@ -35,19 +35,19 @@ * as view's pulldown and local tool bar. */ public class ActionDescriptor implements IPluginContribution { - private PluginAction action; + private final PluginAction action; - private String toolbarId; + private final String toolbarId; - private String menuPath; + private final String menuPath; - private String id; + private final String id; - private String pluginId; + private final String pluginId; - private String menuGroup; + private final String menuGroup; - private String toolbarGroupId; + private final String toolbarGroupId; private int mode = 0; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionExpression.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionExpression.java index 0a48cf4c123..13efa357248 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionExpression.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionExpression.java @@ -110,8 +110,7 @@ public AndExpression(IConfigurationElement element) throws IllegalStateException @Override public final boolean equals(final Object object) { - if (object instanceof AndExpression) { - final AndExpression that = (AndExpression) object; + if (object instanceof final AndExpression that) { return Objects.equals(this.list, that.list); } @@ -314,8 +313,7 @@ private boolean checkInterfaceHierarchy(Class interfaceToCheck) { @Override public final boolean equals(final Object object) { - if (object instanceof ObjectClassExpression) { - final ObjectClassExpression that = (ObjectClassExpression) object; + if (object instanceof final ObjectClassExpression that) { return Objects.equals(this.className, that.className) && Objects.equals(this.extracted, that.extracted); } @@ -386,9 +384,9 @@ public boolean isEnabledForExpression(Object object, String expressionType) { } private static class ObjectStateExpression extends AbstractExpression { - private String name; + private final String name; - private String value; + private final String value; /** * Creates and populates the expression from the attributes and sub- elements of @@ -411,8 +409,7 @@ public ObjectStateExpression(IConfigurationElement element) throws IllegalStateE @Override public final boolean equals(final Object object) { - if (object instanceof ObjectStateExpression) { - final ObjectStateExpression that = (ObjectStateExpression) object; + if (object instanceof final ObjectStateExpression that) { return Objects.equals(this.name, that.name) && Objects.equals(this.value, that.value); } @@ -510,8 +507,7 @@ public OrExpression(IConfigurationElement element) throws IllegalStateException @Override public final boolean equals(final Object object) { - if (object instanceof OrExpression) { - final OrExpression that = (OrExpression) object; + if (object instanceof final OrExpression that) { return Objects.equals(this.list, that.list); } @@ -532,9 +528,9 @@ public boolean isEnabledFor(Object object) { } private static class PluginStateExpression extends AbstractExpression { - private String id; + private final String id; - private String value; + private final String value; /** * Creates and populates the expression from the attributes and sub- elements of @@ -557,8 +553,7 @@ public PluginStateExpression(IConfigurationElement element) throws IllegalStateE @Override public final boolean equals(final Object object) { - if (object instanceof PluginStateExpression) { - final PluginStateExpression that = (PluginStateExpression) object; + if (object instanceof final PluginStateExpression that) { return Objects.equals(this.id, that.id) && Objects.equals(this.value, that.value); } @@ -639,8 +634,7 @@ public SingleExpression(IConfigurationElement element) throws IllegalStateExcept @Override public final boolean equals(final Object object) { - if (object instanceof SingleExpression) { - final SingleExpression that = (SingleExpression) object; + if (object instanceof final SingleExpression that) { return Objects.equals(this.child, that.child); } @@ -686,9 +680,9 @@ public Collection valuesForExpression(String expressionType) { } private static class SystemPropertyExpression extends AbstractExpression { - private String name; + private final String name; - private String value; + private final String value; /** * Creates and populates the expression from the attributes and sub- elements of @@ -720,8 +714,7 @@ public boolean isEnabledFor(Object object) { @Override public final boolean equals(final Object object) { - if (object instanceof SystemPropertyExpression) { - final SystemPropertyExpression that = (SystemPropertyExpression) object; + if (object instanceof final SystemPropertyExpression that) { return Objects.equals(this.name, that.name) && Objects.equals(this.value, that.value); } @@ -884,8 +877,7 @@ public ActionExpression(String expressionType, String expressionValue) { @Override public final boolean equals(final Object object) { - if (object instanceof ActionExpression) { - final ActionExpression that = (ActionExpression) object; + if (object instanceof final ActionExpression that) { return Objects.equals(this.root, that.root); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionPresentation.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionPresentation.java index 5c8f055244c..aa42d4a8fec 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionPresentation.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionPresentation.java @@ -34,11 +34,11 @@ * Manage the configurable actions for one window. */ public class ActionPresentation { - private WorkbenchWindow window; + private final WorkbenchWindow window; - private Map mapDescToRec = new HashMap<>(3); + private final Map mapDescToRec = new HashMap<>(3); - private Map invisibleBars = new HashMap<>(3); + private final Map invisibleBars = new HashMap<>(3); private static class SetRec { public SetRec(IActionSet set, SubActionBars bars) { @@ -153,8 +153,7 @@ public void setActionSets(IActionSetDescriptor[] newArray) { desc.getId()); rec = new SetRec(set, bars); set.init(window, bars); - if (set instanceof PluginActionSet) { - PluginActionSet pluginActionSet = (PluginActionSet) set; + if (set instanceof PluginActionSet pluginActionSet) { sets.add(pluginActionSet); } else { String pattern = "Ignored unexpected IActionSet implementation for descriptor {0}: {1}"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetActionBars.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetActionBars.java index b783467b423..af4c87373cd 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetActionBars.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetActionBars.java @@ -36,7 +36,7 @@ public class ActionSetActionBars extends SubActionBars2 { private IActionBarConfigurer2 actionBarConfigurer = null; - private String actionSetId; + private final String actionSetId; private ArrayList adjunctContributions = new ArrayList<>(); @@ -94,8 +94,7 @@ public void dispose() { // removeAll since other items from other actions sets may be in // the action bar's cool item for (IContributionItem item : coolItemToolBarMgr.getItems()) { - if (item instanceof PluginActionCoolBarContributionItem) { - PluginActionCoolBarContributionItem actionSetItem = (PluginActionCoolBarContributionItem) item; + if (item instanceof PluginActionCoolBarContributionItem actionSetItem) { if (actionSetItem.getActionSetId().equals(actionSetId)) { coolItemToolBarMgr.remove(item); item.dispose(); @@ -222,9 +221,8 @@ public IToolBarManager getToolBarManager(String actionId) { // tool bar // id then create one. Otherwise retrieve the tool bar contribution // item - if (cbItem instanceof IToolBarContributionItem) { + if (cbItem instanceof IToolBarContributionItem tbcbItem) { - IToolBarContributionItem tbcbItem = (IToolBarContributionItem) cbItem; coolItemToolBarMgr = tbcbItem.getToolBarManager(); // If this not an adjuct type then we can cashe the tool bar // contribution type @@ -279,8 +277,7 @@ protected void setActive(boolean set) { // 1. Need to set visibility for all non-adjunct actions if (coolItemToolBarMgr != null) { for (IContributionItem item : coolItemToolBarMgr.getItems()) { - if (item instanceof PluginActionCoolBarContributionItem) { - PluginActionCoolBarContributionItem actionSetItem = (PluginActionCoolBarContributionItem) item; + if (item instanceof PluginActionCoolBarContributionItem actionSetItem) { // Only if the action set id for this contribution item is // the same // as this object diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetManager.java index 4be6eeb51b0..2a955602ee9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetManager.java @@ -57,8 +57,8 @@ public boolean isEmpty() { } } - private HashMap actionSets = new HashMap(); - private HashSet visibleItems = new HashSet(); + private final HashMap actionSets = new HashMap(); + private final HashSet visibleItems = new HashSet(); public static final int PROP_VISIBLE = 0; public static final int PROP_HIDDEN = 1; @@ -67,10 +67,10 @@ public boolean isEmpty() { public static final int CHANGE_SHOW = 2; public static final int CHANGE_HIDE = 3; - private ListenerList listeners = new ListenerList<>(); + private final ListenerList listeners = new ListenerList<>(); private IPropertyListener contextListener; - private Map activationsById = new HashMap(); - private IContextService contextService; + private final Map activationsById = new HashMap(); + private final IContextService contextService; public ActionSetManager(IServiceLocator locator) { contextService = locator.getService(IContextService.class); @@ -80,8 +80,7 @@ public ActionSetManager(IServiceLocator locator) { private IPropertyListener getContextListener() { if (contextListener == null) { contextListener = (source, propId) -> { - if (source instanceof IActionSetDescriptor) { - IActionSetDescriptor desc = (IActionSetDescriptor) source; + if (source instanceof IActionSetDescriptor desc) { String id = desc.getId(); if (propId == PROP_VISIBLE) { activationsById.put(id, contextService.activateContext(id)); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetMenuManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetMenuManager.java index b9e9424b63a..cf9b887d66e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetMenuManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ActionSetMenuManager.java @@ -23,7 +23,7 @@ * an editor so that they always appear after the action sets. */ public class ActionSetMenuManager extends SubMenuManager { - private String actionSetId; + private final String actionSetId; /** * Constructs a new editor manager. @@ -45,9 +45,8 @@ public IContributionItem find(String id) { item = unwrap(item); } - if (item instanceof IMenuManager) { + if (item instanceof IMenuManager menu) { // if it is a menu manager wrap it before returning - IMenuManager menu = (IMenuManager) item; if (menu instanceof SubMenuManager) { // it it is already wrapped then remover the wrapper and // rewrap. We have a table of wrappers so we reuse wrappers diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/AggregateWorkingSet.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/AggregateWorkingSet.java index 48bd4b46211..5728eaf231b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/AggregateWorkingSet.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/AggregateWorkingSet.java @@ -95,10 +95,12 @@ private void constructElements(boolean fireEvent) { elements.addAll(Arrays.asList(componentElements)); } catch (IllegalStateException e) { // an invalid component; remove it IWorkingSet[] tmp = new IWorkingSet[components.length - 1]; - if (i > 0) + if (i > 0) { System.arraycopy(components, 0, tmp, 0, i); - if (components.length - i - 1 > 0) + } + if (components.length - i - 1 > 0) { System.arraycopy(components, i + 1, tmp, i, components.length - i - 1); + } components = tmp; workingSetMemento = null; // toss cached info fireWorkingSetChanged(IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE, null); @@ -179,8 +181,9 @@ public void connect(IWorkingSetManager manager) { @Override public void disconnect() { IWorkingSetManager connectedManager = getManager(); - if (connectedManager != null) + if (connectedManager != null) { connectedManager.removePropertyChangeListener(this); + } super.disconnect(); } @@ -254,9 +257,7 @@ public boolean equals(Object object) { if (this == object) { return true; } - if (object instanceof AggregateWorkingSet) { - AggregateWorkingSet workingSet = (AggregateWorkingSet) object; - + if (object instanceof AggregateWorkingSet workingSet) { return Objects.equals(workingSet.getName(), getName()) && Arrays.equals(workingSet.getComponentsInternal(), getComponentsInternal()); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/BindingToModelProcessor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/BindingToModelProcessor.java index 15d160e95d5..2ce701a02a2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/BindingToModelProcessor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/BindingToModelProcessor.java @@ -45,10 +45,10 @@ @Component(service = IModelProcessorContribution.class) public class BindingToModelProcessor implements IModelProcessorContribution { - private Map contexts = new HashMap<>(); - private Map commands = new HashMap<>(); - private Map tables = new HashMap<>(); - private Set keys = new HashSet<>(); + private final Map contexts = new HashMap<>(); + private final Map commands = new HashMap<>(); + private final Map tables = new HashMap<>(); + private final Set keys = new HashSet<>(); // define dependencies to CommandToModelProcessor and ContextToModelProcessor to // ensure these two IModelProcessorContributions are registered before this @@ -119,8 +119,7 @@ private void removeBindings() { for (MKeyBinding key : keys) { if (!key.getTags().contains("type:user")) { //$NON-NLS-1$ EObject obj = ((EObject) key).eContainer(); - if (obj instanceof MBindingTable) { - MBindingTable table = (MBindingTable) obj; + if (obj instanceof MBindingTable table) { table.getBindings().remove(key); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CloseAllSavedAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CloseAllSavedAction.java index c8673393f21..cb8db355247 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CloseAllSavedAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CloseAllSavedAction.java @@ -31,7 +31,7 @@ public class CloseAllSavedAction extends PageEventAction implements IPropertyLis * List of parts (element type: IWorkbenchPart) against which this * class has outstanding property listeners registered. */ - private List partsWithListeners = new ArrayList<>(1); + private final List partsWithListeners = new ArrayList<>(1); /** * Create an instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CloseOthersHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CloseOthersHandler.java index 4550b742184..cba6061fffc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CloseOthersHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CloseOthersHandler.java @@ -51,8 +51,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException { IEditorReference[] otherEditors = new IEditorReference[refArray.length - 1]; IEditorReference activeEditor = (IEditorReference) page.getReference(page.getActiveEditor()); for (int i = 0; i < refArray.length; i++) { - if (refArray[i] != activeEditor) + if (refArray[i] != activeEditor) { continue; + } System.arraycopy(refArray, 0, otherEditors, 0, i); System.arraycopy(refArray, i + 1, otherEditors, i, refArray.length - 1 - i); break; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CommandToModelProcessor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CommandToModelProcessor.java index d295b399c5f..45b97a967a9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CommandToModelProcessor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CommandToModelProcessor.java @@ -40,9 +40,9 @@ @Component(service = { IModelProcessorContribution.class, CommandToModelProcessor.class }) public class CommandToModelProcessor implements IModelProcessorContribution { - private Map categories = new HashMap<>(); + private final Map categories = new HashMap<>(); - private Map commands = new HashMap<>(); + private final Map commands = new HashMap<>(); private EModelService modelService; @@ -87,8 +87,9 @@ private void generateCommands(MApplication application, CommandManager commandMa if (!cmdName.equals(mCommand.getCommandName())) { mCommand.setCommandName(cmdName); String cmdDesc = cmd.getDescription(); - if (cmdDesc != null) + if (cmdDesc != null) { mCommand.setDescription(cmdDesc); + } } } catch (NotDefinedException e) { // Since we asked for defined commands, this shouldn't be an issue diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ConfigurationInfo.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ConfigurationInfo.java index 00e563cd45e..9e6f940af0b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ConfigurationInfo.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ConfigurationInfo.java @@ -94,8 +94,7 @@ private static void appendExtensions(PrintWriter writer) { writer.println( NLS.bind(WorkbenchMessages.SystemSummary_sectionTitle, element.getAttribute("sectionTitle"))); //$NON-NLS-1$ - if (obj instanceof ISystemSummarySection) { - ISystemSummarySection logSection = (ISystemSummarySection) obj; + if (obj instanceof ISystemSummarySection logSection) { logSection.write(writer); } else { writer.println(WorkbenchMessages.SystemSummary_sectionError); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ContextToModelProcessor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ContextToModelProcessor.java index 1b1db7ff996..7d6ab31cc40 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ContextToModelProcessor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ContextToModelProcessor.java @@ -35,7 +35,7 @@ */ @Component(service = { IModelProcessorContribution.class, ContextToModelProcessor.class }) public class ContextToModelProcessor implements IModelProcessorContribution { - private Map contexts = new HashMap<>(); + private final Map contexts = new HashMap<>(); @Execute void process(MApplication application, IEclipseContext context) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CoolBarToTrimManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CoolBarToTrimManager.java index b772351ded7..e87d645ebdc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CoolBarToTrimManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/CoolBarToTrimManager.java @@ -90,12 +90,12 @@ public void dispose() { public static final String OBJECT = "coolbar.object"; //$NON-NLS-1$ private static final String PREV_CHILD_VISIBLE = "prevChildVisible"; //$NON-NLS-1$ private MTrimBar topTrim; - private List workbenchTrimElements; - private List toolbarExtensions; + private final List workbenchTrimElements; + private final List toolbarExtensions; private IRendererFactory rendererFactory; private ToolBarManagerRenderer renderer; - private MApplication application; - private MTrimmedWindow window; + private final MApplication application; + private final MTrimmedWindow window; private IContributionManagerOverrides toolbarOverrides; /** @@ -103,7 +103,7 @@ public void dispose() { * or not. They should only ever be added once. */ private boolean trimBarsAdded; - private EModelService modelService; + private final EModelService modelService; public CoolBarToTrimManager(MApplication app, MTrimmedWindow window, List workbenchTrimElements, IRendererFactory rf) { @@ -143,14 +143,11 @@ private void add(MTrimBar trimBar, int idx, IContributionItem item) { } } - if (item instanceof IToolBarContributionItem) { - IToolBarContributionItem tbc = (IToolBarContributionItem) item; + if (item instanceof IToolBarContributionItem tbc) { IToolBarManager mgr = tbc.getToolBarManager(); - if (!(mgr instanceof ToolBarManager)) { + if (!(mgr instanceof ToolBarManager manager)) { return; } - ToolBarManager manager = (ToolBarManager) mgr; - if (renderer.getToolBarModel(manager) != null) { return; } @@ -327,8 +324,7 @@ public void dispose() { ArrayList toRemove = new ArrayList<>(); for (MTrimElement child : topTrim.getChildren()) { - if (child instanceof MToolBar) { - MToolBar toolbar = (MToolBar) child; + if (child instanceof MToolBar toolbar) { for (MToolBarElement element : toolbar.getChildren()) { if (OpaqueElementUtil.isOpaqueToolItem(element)) { toRemove.add(element); @@ -688,12 +684,11 @@ private boolean fill(MToolBar container, IContributionManager manager) { HandledContributionItem ci = ContextInjectionFactory.make(HandledContributionItem.class, window.getContext()); - if (manager instanceof ContributionManager) { + if (manager instanceof ContributionManager cm) { // set basic attributes to the item before adding to the manager ci.setId(toolItem.getElementId()); ci.setVisible(toolItem.isVisible()); - ContributionManager cm = (ContributionManager) manager; cm.insert(index, ci); cm.remove(item); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/DefaultSaveable.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/DefaultSaveable.java index 17cd87e5f1a..ca164db5be8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/DefaultSaveable.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/DefaultSaveable.java @@ -35,7 +35,7 @@ */ public class DefaultSaveable extends Saveable { - private IWorkbenchPart part; + private final IWorkbenchPart part; /** * Creates a new DefaultSaveable. @@ -92,18 +92,23 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final DefaultSaveable other = (DefaultSaveable) obj; if (part == null) { - if (other.part != null) + if (other.part != null) { return false; - } else if (!part.equals(other.part)) + } + } else if (!part.equals(other.part)) { return false; + } return true; } @@ -114,8 +119,7 @@ public boolean show(IWorkbenchPage page) { page.activate(part); return true; } - if (part instanceof IViewPart) { - IViewPart viewPart = (IViewPart) part; + if (part instanceof IViewPart viewPart) { try { page.showView(viewPart.getViewSite().getId(), viewPart.getViewSite().getSecondaryId(), IWorkbenchPage.VIEW_ACTIVATE); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EarlyStartupRunnable.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EarlyStartupRunnable.java index c6525e2c4ed..8bfcd19b9d7 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EarlyStartupRunnable.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EarlyStartupRunnable.java @@ -32,7 +32,7 @@ */ public class EarlyStartupRunnable extends SafeRunnable { - private IExtension extension; + private final IExtension extension; /** * @param extension must not be null diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorActionBars.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorActionBars.java index 161f07ba9f6..9023973de86 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorActionBars.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorActionBars.java @@ -100,9 +100,9 @@ public Boolean getVisible(IContributionItem item) { private IToolBarContributionItem toolBarContributionItem = null; - private String type; + private final String type; - private WorkbenchPage page; + private final WorkbenchPage page; /** * Constructs the EditorActionBars for an editor. @@ -172,11 +172,9 @@ public void dispose() { if (toolBarContributionItem != null) { // Create a placeholder and place it in the cool bar manager. ICoolBarManager coolBarManager = getCoolBarManager(); - if (coolBarManager instanceof SubContributionManager) { - SubContributionManager subManager = (SubContributionManager) coolBarManager; + if (coolBarManager instanceof SubContributionManager subManager) { IContributionManager manager = subManager.getParent(); - if (manager instanceof CoolBarToTrimManager) { - CoolBarToTrimManager trimManager = (CoolBarToTrimManager) manager; + if (manager instanceof CoolBarToTrimManager trimManager) { trimManager.remove(toolBarContributionItem); } else if (manager instanceof ContributionManager) { final IContributionItem replacementItem = new PlaceholderContributionItem(toolBarContributionItem); @@ -274,8 +272,7 @@ public IToolBarManager getToolBarManager() { } else { coolItemToolBarMgr = new ToolBarManager2(SWT.FLAT); if ((coolBarManager instanceof ContributionManager) - && (foundItem instanceof PlaceholderContributionItem)) { - PlaceholderContributionItem placeholder = (PlaceholderContributionItem) foundItem; + && (foundItem instanceof PlaceholderContributionItem placeholder)) { toolBarContributionItem = createToolBarContributionItem(coolItemToolBarMgr, placeholder); // Restore from a placeholder ((ContributionManager) coolBarManager).replaceItem(type, toolBarContributionItem); @@ -329,8 +326,7 @@ private boolean isVisible() { @Override public void partChanged(IWorkbenchPart part) { super.partChanged(part); - if (part instanceof IEditorPart) { - IEditorPart editor = (IEditorPart) part; + if (part instanceof IEditorPart editor) { if (editorContributor != null) { editorContributor.setActiveEditor(editor); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorActionBuilder.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorActionBuilder.java index b64accb5dc9..77eb89192c3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorActionBuilder.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorActionBuilder.java @@ -85,7 +85,7 @@ public void editorChanged(IEditorPart editor) { * contributions. */ public static class ExternalContributor implements IEditorActionBarContributor { - private ArrayList cache; + private final ArrayList cache; public ExternalContributor(ArrayList cache) { this.cache = cache; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorHistory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorHistory.java index 0c5007e2a43..2cb894b16ca 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorHistory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorHistory.java @@ -36,7 +36,7 @@ public class EditorHistory { /** * The list of editor entries, in FIFO order. */ - private ArrayList fifoList = new ArrayList<>(MAX_SIZE); + private final ArrayList fifoList = new ArrayList<>(MAX_SIZE); /** * Constructs a new history. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorMenuManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorMenuManager.java index d0ae99a1373..c2b9bcae447 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorMenuManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorMenuManager.java @@ -85,7 +85,7 @@ public Boolean getVisible(IContributionItem item) { } } - private Overrides overrides = new Overrides(); + private final Overrides overrides = new Overrides(); /** * Constructs a new editor manager. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorReference.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorReference.java index 2b7bb5a7f8a..3c6c534873f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorReference.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorReference.java @@ -109,8 +109,9 @@ public EditorReference(IEclipseContext windowContext, IWorkbenchPage page, MPart boolean persist() { XMLMemento persistedState = (XMLMemento) getEditorState(); - if (persistedState == null) + if (persistedState == null) { return false; + } StringWriter writer = new StringWriter(); try { @@ -262,18 +263,18 @@ public static IEditorInput createInput(IMemento editorMem) throws PartInitExcept IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryID); if (factory == null) { throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_bad_element_factory, - new Object[] { factoryID, editorId, editorName })); + factoryID, editorId, editorName)); } // Get the input element. input = factory.createElement(inputMem); if (input == null) { throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_create_element_returned_null, - new Object[] { factoryID, editorId, editorName })); + factoryID, editorId, editorName)); } if (!(input instanceof IEditorInput)) { throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_wrong_createElement_result, - new Object[] { factoryID, editorId, editorName })); + factoryID, editorId, editorName)); } return (IEditorInput) input; } @@ -424,8 +425,9 @@ private static EditorActionBars createEditorActionBars(WorkbenchPage page, Edito candidates = new HashSet<>(3); candidates.add(actionBars); actionCache.put(type, candidates); - } else + } else { candidates.add(actionBars); + } // Read base contributor. IEditorActionBarContributor contr = desc.createActionBarContributor(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorSiteDragAndDropServiceImpl.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorSiteDragAndDropServiceImpl.java index 973062c69d2..27abe637fb1 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorSiteDragAndDropServiceImpl.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/EditorSiteDragAndDropServiceImpl.java @@ -66,15 +66,15 @@ public class EditorSiteDragAndDropServiceImpl implements IDragAndDropService, ID * @since 3.3 */ private static class MergedDropTarget { - private DropTarget realDropTarget; + private final DropTarget realDropTarget; - private Transfer[] secondaryTransfers; - private DropTargetListener secondaryListener; - private int secondaryOps; + private final Transfer[] secondaryTransfers; + private final DropTargetListener secondaryListener; + private final int secondaryOps; - private Transfer[] primaryTransfers; - private DropTargetListener primaryListener; - private int primaryOps; + private final Transfer[] primaryTransfers; + private final DropTargetListener primaryListener; + private final int primaryOps; public MergedDropTarget(Control control, int priOps, Transfer[] priTransfers, DropTargetListener priListener, int secOps, Transfer[] secTransfers, DropTargetListener secListener) { @@ -152,8 +152,9 @@ private DropTargetListener getAppropriateListener(DropTargetEvent event, boolean private boolean isSupportedType(Transfer[] transfers, TransferData transferType) { for (Transfer transfer : transfers) { - if (transfer.isSupportedType(transferType)) + if (transfer.isSupportedType(transferType)) { return true; + } } return false; } @@ -199,8 +200,9 @@ public void addMergedDropTarget(Control control, int ops, Transfer[] transfers, * @return The DropTarget for that control (could be null */ private DropTarget getCurrentDropTarget(Control control) { - if (control == null) + if (control == null) { return null; + } Object curDT = control.getData(DND.DROP_TARGET_KEY); return (DropTarget) curDT; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ExtensionEventHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ExtensionEventHandler.java index da324545a91..4b738ede5a5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ExtensionEventHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ExtensionEventHandler.java @@ -43,9 +43,9 @@ class ExtensionEventHandler implements IRegistryChangeListener { - private Workbench workbench; + private final Workbench workbench; - private List changeList = new ArrayList<>(10); + private final List changeList = new ArrayList<>(10); public ExtensionEventHandler(Workbench workbench) { this.workbench = workbench; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/FilteredTableBaseHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/FilteredTableBaseHandler.java index 58e10c7493a..e4ba6e74a87 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/FilteredTableBaseHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/FilteredTableBaseHandler.java @@ -151,10 +151,12 @@ public void openDialog(WorkbenchPage page, IWorkbenchPart activePart) { Shell shell = null; selection = null; - if (activePart != null) + if (activePart != null) { shell = activePart.getSite().getShell(); - if (shell == null) + } + if (shell == null) { shell = window.getShell(); + } dialog = new Shell(shell, SWT.MODELESS); dialog.setBackground(getBackground()); dialog.setMinimumSize(new Point(120, 50)); @@ -338,7 +340,7 @@ private Image createSeparatorBgImage() { * the listener check if focus is still on one of the active components. If not, * closes the dialog. */ - private FocusAdapter fAdapter = new FocusAdapter() { + private final FocusAdapter fAdapter = new FocusAdapter() { @Override public void focusLost(FocusEvent e) { PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { @@ -713,8 +715,7 @@ protected void activate(IWorkbenchPage page, Object selectedItem) { // the if conditions below do not need to be checked then return; } - if (selectedItem instanceof IPerspectiveDescriptor) { - IPerspectiveDescriptor persp = (IPerspectiveDescriptor) selectedItem; + if (selectedItem instanceof IPerspectiveDescriptor persp) { page.setPerspective(persp); IWorkbenchPart activePart = page.getActivePart(); if (activePart != null) { @@ -836,8 +837,7 @@ public String getText(Object element) { return ((FilteredTableItem) element).text; } else if (element instanceof WorkbenchPartReference) { return getWorkbenchPartReferenceText((WorkbenchPartReference) element); - } else if (element instanceof IPerspectiveDescriptor) { - IPerspectiveDescriptor desc = (IPerspectiveDescriptor) element; + } else if (element instanceof IPerspectiveDescriptor desc) { String text = getPerspectiveLabelProvider().getText(desc); return (text == null) ? "" : text; //$NON-NLS-1$ } @@ -850,8 +850,7 @@ public Image getImage(Object element) { return ((FilteredTableItem) element).image; } else if (element instanceof WorkbenchPartReference) { return ((WorkbenchPartReference) element).getTitleImage(); - } else if (element instanceof IPerspectiveDescriptor) { - IPerspectiveDescriptor desc = (IPerspectiveDescriptor) element; + } else if (element instanceof IPerspectiveDescriptor desc) { return getPerspectiveLabelProvider().getImage(desc); } return super.getImage(element); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/HeapStatus.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/HeapStatus.java index 099d57530ad..e5c15f63132 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/HeapStatus.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/HeapStatus.java @@ -50,11 +50,19 @@ public class HeapStatus extends Composite { private boolean armed; - private Image gcImage; + private final Image gcImage; private Image disabledGcImage; - private Color bgCol, usedMemCol, lowMemCol, freeMemCol, topLeftCol, bottomRightCol, sepCol, textCol, markCol, - armCol; - private Canvas canvas; + private Color bgCol; + private final Color usedMemCol; + private final Color lowMemCol; + private final Color freeMemCol; + private Color topLeftCol; + private final Color bottomRightCol; + private final Color sepCol; + private Color textCol; + private Color markCol; + private Color armCol; + private final Canvas canvas; private IPreferenceStore prefStore; private int updateInterval; private boolean showMax; @@ -67,9 +75,9 @@ public class HeapStatus extends Composite { // start with 12x12 private Rectangle imgBounds = new Rectangle(0, 0, 12, 12); private final long maxMem; - private boolean maxMemKnown; - private float lowMemThreshold = 0.05f; - private boolean showLowMemThreshold = true; + private final boolean maxMemKnown; + private final float lowMemThreshold = 0.05f; + private final boolean showLowMemThreshold = true; private boolean updateTooltip = false; protected volatile boolean isInGC = false; @@ -168,8 +176,9 @@ public HeapStatus(Composite parent, IPreferenceStore prefStore) { if (event.widget == HeapStatus.this) { setMark(); } else if (event.widget == canvas) { - if (!isInGC) + if (!isInGC) { arm(true); + } } } break; @@ -502,7 +511,7 @@ private void updateToolTip() { String maxStr = maxMemKnown ? convertToMegString(maxMem) : WorkbenchMessages.HeapStatus_maxUnknown; String markStr = mark == -1 ? WorkbenchMessages.HeapStatus_noMark : convertToMegString(mark); String toolTip = NLS.bind(WorkbenchMessages.HeapStatus_memoryToolTip, - new Object[] { usedStr, totalStr, maxStr, markStr }); + usedStr, totalStr, maxStr, markStr); if (!toolTip.equals(getToolTipText())) { setToolTipText(toolTip); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/KeyBindingService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/KeyBindingService.java index 5f2f898e882..c5a00749a93 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/KeyBindingService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/KeyBindingService.java @@ -64,13 +64,13 @@ public final class KeyBindingService implements INestableKeyBindingService { * The site within the workbench at which this service is provided. This value * should not be null. */ - private IWorkbenchPartSite workbenchPartSite; + private final IWorkbenchPartSite workbenchPartSite; - private KeyBindingService parent; + private final KeyBindingService parent; private IKeyBindingService activeService; - private Map actionToProxy = new HashMap<>(); + private final Map actionToProxy = new HashMap<>(); /** * Constructs a new instance of KeyBindingService on a given diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LargeFileLimitsPreferenceHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LargeFileLimitsPreferenceHandler.java index f89bdac8fe4..f74bf4d28f7 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LargeFileLimitsPreferenceHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LargeFileLimitsPreferenceHandler.java @@ -227,8 +227,7 @@ public static boolean isPromptPreferenceValue(String editorId) { * for the given document type */ public Optional getEditorForInput(IEditorInput editorInput) { - if (editorInput instanceof IPathEditorInput) { - IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput; + if (editorInput instanceof IPathEditorInput pathEditorInput) { try { IPath inputPath = pathEditorInput.getPath(); return getEditorForPath(inputPath); @@ -308,8 +307,9 @@ protected IDialogSettings getDialogSettings() { * {@link IPreferenceConstants#LARGE_DOC_SIZE_FOR_EDITORS} */ boolean isLargeDocumentFromLegacy(IPath path) { - if (!legacyCheckDocumentSize) + if (!legacyCheckDocumentSize) { return false; + } try { File file = new File(path.toOSString()); @@ -477,7 +477,7 @@ private static String[] splitPreferenceValues(String preferenceName, String pref if (values.length % 2 != 0) { String errorMessage = NLS.bind( "Expected pairs of values separated by \"{0}\" for preference \"{1}\" but got: \"{2}\"", //$NON-NLS-1$ - new String[] { PREFERENCE_VALUE_SEPARATOR, preferenceName, Arrays.toString(values) }); + PREFERENCE_VALUE_SEPARATOR, preferenceName, Arrays.toString(values)); WorkbenchPlugin.log(new IllegalArgumentException(errorMessage)); values = new String[0]; } @@ -496,7 +496,7 @@ private static List parsePreferenceValues(String preferenceName, Stri } catch (NumberFormatException e) { String errorMessage = NLS.bind( "Skipped invalid file size value \"{0}\" stored in preference \"{1}\" with value \"{2}\"", //$NON-NLS-1$ - new String[] { sizeString, preferenceName, Arrays.toString(preferenceValues) }); + sizeString, preferenceName, Arrays.toString(preferenceValues)); WorkbenchPlugin.log(new IllegalArgumentException(errorMessage, e)); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LegacyResourceSupport.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LegacyResourceSupport.java index a920091fc77..e093e4eba33 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LegacyResourceSupport.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LegacyResourceSupport.java @@ -403,8 +403,7 @@ public static Object getAdaptedContributorResource(Object object) { if (resourceClass.isInstance(object)) { return null; } - if (object instanceof IAdaptable) { - IAdaptable adaptable = (IAdaptable) object; + if (object instanceof IAdaptable adaptable) { Class contributorResourceAdapterClass = LegacyResourceSupport.getIContributorResourceAdapterClass(); if (contributorResourceAdapterClass == null) { return adaptable.getAdapter(resourceClass); @@ -441,7 +440,7 @@ private static Method getContributorResourceAdapterGetAdaptedResourceMethod() { Class c = getIContributorResourceAdapterClass(); if (c != null) { try { - getAdaptedResourceMethod = c.getDeclaredMethod("getAdaptedResource", new Class[] { IAdaptable.class }); //$NON-NLS-1$ + getAdaptedResourceMethod = c.getDeclaredMethod("getAdaptedResource", IAdaptable.class); //$NON-NLS-1$ return getAdaptedResourceMethod; } catch (SecurityException | NoSuchMethodException e) { // shouldn't happen - but play it safe @@ -461,7 +460,7 @@ private static Method getContributorResourceAdapter2GetAdaptedResourceMappingMet if (c != null) { try { getAdaptedResourceMappingMethod = c.getDeclaredMethod("getAdaptedResourceMapping", //$NON-NLS-1$ - new Class[] { IAdaptable.class }); + IAdaptable.class); return getAdaptedResourceMappingMethod; } catch (SecurityException | NoSuchMethodException e) { // do nothing - play it safe @@ -492,8 +491,7 @@ public static Object getAdaptedContributorResourceMapping(Object object) { if (resourceMappingClass.isInstance(object)) { return null; } - if (object instanceof IAdaptable) { - IAdaptable adaptable = (IAdaptable) object; + if (object instanceof IAdaptable adaptable) { Class contributorResourceAdapterClass = LegacyResourceSupport.getIContributorResourceAdapterClass(); if (contributorResourceAdapterClass == null) { return adaptable.getAdapter(resourceMappingClass); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LegacyTrim.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LegacyTrim.java index 6698b34745a..5583f1794e9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LegacyTrim.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/LegacyTrim.java @@ -39,8 +39,9 @@ public class LegacyTrim { @PostConstruct void createWidget(IWorkbenchWindow iwbw, Composite parent, MToolControl toolControl) { IConfigurationElement ice = ((WorkbenchWindow) iwbw).getICEFor(toolControl); - if (ice == null) + if (ice == null) { return; + } parent = new Composite(parent, SWT.NONE); parent.setLayout(new RowLayout()); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistory.java index 5184a146485..3551bd19f21 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistory.java @@ -49,11 +49,11 @@ public class NavigationHistory implements INavigationHistory { private int ignoreEntries; - private ArrayList history = new ArrayList<>(CAPACITY); + private final ArrayList history = new ArrayList<>(CAPACITY); Map perTabHistoryMap = new HashMap<>(); - private ArrayList editors = new ArrayList<>(CAPACITY); + private final ArrayList editors = new ArrayList<>(CAPACITY); private IWorkbenchPage page; @@ -165,8 +165,9 @@ private void updateNavigationHistory(IWorkbenchPartReference partRef, boolean pa * Promote the entry of the last closed editor to be the active one, see: * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154431 */ - if (!isEntryDisposed && page.getActiveEditor() == null && activeEntry < history.size()) + if (!isEntryDisposed && page.getActiveEditor() == null && activeEntry < history.size()) { activeEntry++; + } updateActions(); } @@ -672,8 +673,7 @@ private void setNewCurrentEntryForTab(PerTabHistory perTabHistory, NavigationHis private Object getCookieForTab(IEditorPart part) { if (part != null) { IWorkbenchPartSite site = part.getSite(); - if (site instanceof PartSite) { - PartSite partSite = (PartSite) site; + if (site instanceof PartSite partSite) { WorkbenchPartReference ref = (WorkbenchPartReference) partSite.getPartReference(); if (!ref.isDisposed()) { return partSite.getModel().getWidget(); @@ -884,23 +884,29 @@ private void removeEntriesForTab(LinkedList entries) { public boolean updateActive(IEditorPart editor) { NavigationHistoryEntry e = getEntry(activeEntry); - if (e == null) + if (e == null) { return false; + } // 1) check if editor ID matches IWorkbenchPartSite site = editor.getSite(); - if (site == null) // might happen if site has not being initialized yet + if (site == null) { // might happen if site has not being initialized yet return false; + } String editorID = site.getId(); - if (editorID == null) // should not happen for an editor + if (editorID == null) { // should not happen for an editor return false; - if (!editorID.equals(e.editorInfo.editorID)) + } + if (!editorID.equals(e.editorInfo.editorID)) { return false; + } // 2) check that input matches IEditorInput input = editor.getEditorInput(); - if (input == null) + if (input == null) { return false; - if (!input.equals(e.editorInfo.editorInput)) + } + if (!input.equals(e.editorInfo.editorInput)) { return false; + } updateEntry(e); return true; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistoryAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistoryAction.java index 5e8df242026..a479c47e012 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistoryAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistoryAction.java @@ -39,11 +39,11 @@ public class NavigationHistoryAction extends PageEventAction { private boolean recreateMenu; - private boolean forward; + private final boolean forward; private Menu historyMenu; - private int MAX_HISTORY_LENGTH = 9; + private final int MAX_HISTORY_LENGTH = 9; private class MenuCreator implements IMenuCreator { @Override diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistoryEntry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistoryEntry.java index cfd6478ddde..6d37df0426d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistoryEntry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/NavigationHistoryEntry.java @@ -28,7 +28,7 @@ */ public class NavigationHistoryEntry { - private IWorkbenchPage page; + private final IWorkbenchPage page; NavigationHistoryEditorInfo editorInfo; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectActionContributor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectActionContributor.java index c5273c81588..e9b38e0531e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectActionContributor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectActionContributor.java @@ -44,13 +44,13 @@ public class ObjectActionContributor extends PluginActionBuilder implements IObj private static final String P_TRUE = "true"; //$NON-NLS-1$ - private IConfigurationElement config; + private final IConfigurationElement config; private boolean configRead = false; private boolean adaptable = false; - private String objectClass; + private final String objectClass; /** * The constructor. @@ -111,11 +111,9 @@ public boolean contributeObjectActions(final IWorkbenchPart part, IMenuManager m // Get a structured selection. ISelection sel = selProv.getSelection(); - if ((sel == null) || !(sel instanceof IStructuredSelection)) { + if ((sel == null) || !(sel instanceof IStructuredSelection ssel)) { return false; } - IStructuredSelection ssel = (IStructuredSelection) sel; - if (canAdapt()) { IStructuredSelection newSelection = LegacyResourceSupport.adaptSelection(ssel, getObjectClass()); if (newSelection.size() != ssel.size()) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectContributorManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectContributorManager.java index 8efb09cbb06..5aa1dc1f3a9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectContributorManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectContributorManager.java @@ -373,7 +373,7 @@ protected List getContributors(Object object) { // Fetch the unique adapters List adapters = new ArrayList( Arrays.asList(Platform.getAdapterManager().computeAdapterTypes(object.getClass()))); - removeCommonAdapters(adapters, Arrays.asList(new Class[] { object.getClass() })); + removeCommonAdapters(adapters, Arrays.asList(object.getClass())); List contributors = new ArrayList(); @@ -543,8 +543,7 @@ private List filterOnlyAdaptableContributors(List contributors) { @Override public void removeExtension(IExtension source, Object[] objects) { for (Object object : objects) { - if (object instanceof ContributorRecord) { - ContributorRecord contributorRecord = (ContributorRecord) object; + if (object instanceof ContributorRecord contributorRecord) { unregisterContributor((contributorRecord).contributor, (contributorRecord).objectClassName); contributorRecordSet.remove(contributorRecord); } @@ -782,8 +781,9 @@ private List getCommonClasses(List objects, List commonAdapters) { */ private boolean allSameClass(List objects) { int size = objects.size(); - if (size <= 1) + if (size <= 1) { return true; + } Class clazz = objects.get(0).getClass(); for (int i = 1; i < size; ++i) { if (!objects.get(i).getClass().equals(clazz)) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectPluginAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectPluginAction.java index 2089feb78a7..46102aa04a4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectPluginAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ObjectPluginAction.java @@ -40,7 +40,7 @@ public class ObjectPluginAction extends PluginAction implements IPartListener2 { */ public static final String ATT_OVERRIDE_ACTION_ID = "overrideActionId";//$NON-NLS-1$ - private String overrideActionId; + private final String overrideActionId; private IWorkbenchPart activePart; @@ -56,8 +56,7 @@ public void partBroughtToTop(IWorkbenchPartReference partRef) { public void partClosed(IWorkbenchPartReference partRef) { IWorkbenchPart part = partRef.getPart(false); // FIX 543745 - if (part instanceof MultiPageEditorPart && activePart instanceof IEditorPart) { - MultiPageEditorPart mulitPageEditorPart = (MultiPageEditorPart) part; + if (part instanceof MultiPageEditorPart mulitPageEditorPart && activePart instanceof IEditorPart) { IEditorPart[] editorsForActivePart = mulitPageEditorPart .findEditors(((IEditorPart) activePart).getEditorInput()); if (editorsForActivePart != null && editorsForActivePart.length > 0) { @@ -115,8 +114,7 @@ public ObjectPluginAction(IConfigurationElement actionElement, String id, int st protected void initDelegate() { super.initDelegate(); final IActionDelegate actionDelegate = getDelegate(); - if (actionDelegate instanceof IObjectActionDelegate && activePart != null) { - final IObjectActionDelegate objectActionDelegate = (IObjectActionDelegate) actionDelegate; + if (actionDelegate instanceof final IObjectActionDelegate objectActionDelegate && activePart != null) { final ISafeRunnable runnable = new ISafeRunnable() { @Override public void run() throws Exception { @@ -152,8 +150,7 @@ public void setActivePart(IWorkbenchPart targetPart) { } activePart = targetPart; IActionDelegate delegate = getDelegate(); - if (delegate instanceof IObjectActionDelegate && activePart != null) { - final IObjectActionDelegate objectActionDelegate = (IObjectActionDelegate) delegate; + if (delegate instanceof final IObjectActionDelegate objectActionDelegate && activePart != null) { final ISafeRunnable runnable = new ISafeRunnable() { @Override public void run() throws Exception { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/OpenPerspectivePropertyTester.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/OpenPerspectivePropertyTester.java index 533c6c4fe07..251e5e14074 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/OpenPerspectivePropertyTester.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/OpenPerspectivePropertyTester.java @@ -28,8 +28,7 @@ public class OpenPerspectivePropertyTester extends PropertyTester { @Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (args.length == 0 && receiver instanceof WorkbenchWindow) { - final WorkbenchWindow window = (WorkbenchWindow) receiver; + if (args.length == 0 && receiver instanceof final WorkbenchWindow window) { if (PROPERTY_IS_PERSPECTIVE_OPEN.equals(property)) { IWorkbenchPage page = window.getActivePage(); if (page != null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartService.java index 0382062786b..6963e224d54 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartService.java @@ -27,8 +27,8 @@ public class PartService implements IPageChangedListener, IPartListener, IPartListener2, IPartService { - private ListenerList partListeners = new ListenerList<>(); - private ListenerList partListeners2 = new ListenerList<>(); + private final ListenerList partListeners = new ListenerList<>(); + private final ListenerList partListeners2 = new ListenerList<>(); private WorkbenchPage page; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartSite.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartSite.java index 27a719222c5..e0f0e255d5a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartSite.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartSite.java @@ -126,7 +126,7 @@ public static final void registerContextMenu(final String menuId, final MenuMana } } - private IWorkbenchPartReference partReference; + private final IWorkbenchPartReference partReference; private IWorkbenchPart part; @@ -154,7 +154,7 @@ public static final void registerContextMenu(final String menuId, final MenuMana protected MPart model; - private IConfigurationElement element; + private final IConfigurationElement element; private IEclipseContext e4Context; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartTaggedAsEditorPropertyTester.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartTaggedAsEditorPropertyTester.java index 78acda39cae..948724e1523 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartTaggedAsEditorPropertyTester.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PartTaggedAsEditorPropertyTester.java @@ -34,8 +34,7 @@ public class PartTaggedAsEditorPropertyTester extends PropertyTester { @Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (receiver instanceof E4PartWrapper) { - E4PartWrapper partWrapper = (E4PartWrapper) receiver; + if (receiver instanceof E4PartWrapper partWrapper) { if (partWrapper.wrappedPart != null) { List partTags = partWrapper.wrappedPart.getTags(); return partTags == null || partTags.isEmpty() ? false diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PerspectiveAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PerspectiveAction.java index 785896c1591..9e68b18a779 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PerspectiveAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PerspectiveAction.java @@ -37,7 +37,7 @@ public abstract class PerspectiveAction extends Action implements ActionFactory. /** * Tracks perspective activation, to update this action's enabled state. */ - private PerspectiveTracker tracker; + private final PerspectiveTracker tracker; /** * Constructs a new perspective action for the given window. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PerspectiveListenerList.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PerspectiveListenerList.java index b5ac0fa7afb..c8a199b97a8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PerspectiveListenerList.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PerspectiveListenerList.java @@ -83,8 +83,7 @@ public void run() { */ public void firePerspectivePreDeactivate(final IWorkbenchPage page, final IPerspectiveDescriptor perspective) { for (Object listener : getListeners()) { - if (listener instanceof IPerspectiveListener4) { - final IPerspectiveListener4 perspectiveListener = (IPerspectiveListener4) listener; + if (listener instanceof final IPerspectiveListener4 perspectiveListener) { fireEvent(new SafeRunnable() { @Override public void run() { @@ -102,8 +101,7 @@ public void run() { */ public void firePerspectiveDeactivated(final IWorkbenchPage page, final IPerspectiveDescriptor perspective) { for (Object listener : getListeners()) { - if (listener instanceof IPerspectiveListener3) { - final IPerspectiveListener3 perspectiveListener = (IPerspectiveListener3) listener; + if (listener instanceof final IPerspectiveListener3 perspectiveListener) { fireEvent(new SafeRunnable() { @Override public void run() { @@ -138,8 +136,7 @@ public void run() { public void firePerspectiveChanged(final IWorkbenchPage page, final IPerspectiveDescriptor perspective, final IWorkbenchPartReference partRef, final String changeId) { for (Object listener : getListeners()) { - if (listener instanceof IPerspectiveListener2) { - final IPerspectiveListener2 perspectiveListener = (IPerspectiveListener2) listener; + if (listener instanceof final IPerspectiveListener2 perspectiveListener) { fireEvent(new SafeRunnable() { @Override public void run() { @@ -157,8 +154,7 @@ public void run() { */ public void firePerspectiveClosed(final IWorkbenchPage page, final IPerspectiveDescriptor perspective) { for (Object listener : getListeners()) { - if (listener instanceof IPerspectiveListener3) { - final IPerspectiveListener3 perspectiveListener = (IPerspectiveListener3) listener; + if (listener instanceof final IPerspectiveListener3 perspectiveListener) { fireEvent(new SafeRunnable() { @Override public void run() { @@ -176,8 +172,7 @@ public void run() { */ public void firePerspectiveOpened(final IWorkbenchPage page, final IPerspectiveDescriptor perspective) { for (Object listener : getListeners()) { - if (listener instanceof IPerspectiveListener3) { - final IPerspectiveListener3 perspectiveListener = (IPerspectiveListener3) listener; + if (listener instanceof final IPerspectiveListener3 perspectiveListener) { fireEvent(new SafeRunnable() { @Override public void run() { @@ -196,8 +191,7 @@ public void run() { public void firePerspectiveSavedAs(final IWorkbenchPage page, final IPerspectiveDescriptor oldPerspective, final IPerspectiveDescriptor newPerspective) { for (Object listener : getListeners()) { - if (listener instanceof IPerspectiveListener3) { - final IPerspectiveListener3 perspectiveListener = (IPerspectiveListener3) listener; + if (listener instanceof final IPerspectiveListener3 perspectiveListener) { fireEvent(new SafeRunnable() { @Override public void run() { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PlatformUIPreferenceListener.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PlatformUIPreferenceListener.java index cff9a8b8cf8..d6f80d8c239 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PlatformUIPreferenceListener.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PlatformUIPreferenceListener.java @@ -81,8 +81,7 @@ public void preferenceChange(PreferenceChangeEvent event) { // Update the file associations if they have changed due to an import if (IPreferenceConstants.RESOURCES.equals(propertyName)) { IEditorRegistry registry = WorkbenchPlugin.getDefault().getEditorRegistry(); - if (registry instanceof EditorRegistry) { - EditorRegistry editorRegistry = (EditorRegistry) registry; + if (registry instanceof EditorRegistry editorRegistry) { IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore(); String xmlString = store.getString(IPreferenceConstants.RESOURCES); if (xmlString != null && xmlString.length() > 0) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginAction.java index 4d27cd4d0c6..d9a844e5d2d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginAction.java @@ -61,9 +61,9 @@ public abstract class PluginAction extends Action private ISelection selection; - private IConfigurationElement configElement; + private final IConfigurationElement configElement; - private String pluginId; + private final String pluginId; private String runAttribute = IWorkbenchRegistryConstants.ATT_CLASS; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginActionSet.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginActionSet.java index 8974ddf2b3e..842bc9247b0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginActionSet.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginActionSet.java @@ -28,9 +28,9 @@ * PluginAction for each action and does the required cleanup on dispose. */ public class PluginActionSet implements IActionSet { - private ActionSetDescriptor desc; + private final ActionSetDescriptor desc; - private ArrayList pluginActions = new ArrayList<>(4); + private final ArrayList pluginActions = new ArrayList<>(4); private ActionSetActionBars bars; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginActionSetBuilder.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginActionSetBuilder.java index 5d6a92ee4a8..63bfd42d9ff 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginActionSetBuilder.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PluginActionSetBuilder.java @@ -44,7 +44,7 @@ public class PluginActionSetBuilder extends PluginActionBuilder { private IWorkbenchWindow window; - private ArrayList adjunctContributions = new ArrayList<>(0); + private final ArrayList adjunctContributions = new ArrayList<>(0); /** * Used by the workbench window extension handler to unhook action sets from @@ -280,9 +280,9 @@ private void registerBinding(final PluginActionSet set) { * element. */ private static class ActionSetContribution extends BasicContribution { - private String actionSetId; + private final String actionSetId; - private WorkbenchWindow window; + private final WorkbenchWindow window; protected ArrayList adjunctActions = new ArrayList<>(0); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PopupMenuExtender.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PopupMenuExtender.java index 5876d28e76c..43650920dbc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PopupMenuExtender.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/PopupMenuExtender.java @@ -93,15 +93,15 @@ public class PopupMenuExtender implements IMenuListener2, IRegistryChangeListene */ private int bitSet = 0; - private ArrayList actionContributionCache = new ArrayList<>(); + private final ArrayList actionContributionCache = new ArrayList<>(); private boolean cleanupNeeded = false; - private MPart modelPart; + private final MPart modelPart; /** * The context that will be used to create the popup menu's context under. */ - private IEclipseContext context; + private final IEclipseContext context; /** * Construct a new menu extender. @@ -262,8 +262,7 @@ public void addSelectionChangedListener(ISelectionChangedListener listener) { @Override public ISelection getSelection() { - if (part instanceof IEditorPart) { - final IEditorPart editorPart = (IEditorPart) part; + if (part instanceof final IEditorPart editorPart) { return new StructuredSelection(new Object[] { editorPart.getEditorInput() }); } @@ -337,13 +336,11 @@ public void menuAboutToShow(IMenuManager mgr) { final IWorkbenchPartSite site = part.getSite(); if (site != null) { final IWorkbench workbench = site.getWorkbenchWindow().getWorkbench(); - if (workbench instanceof Workbench) { - final Workbench realWorkbench = (Workbench) workbench; + if (workbench instanceof final Workbench realWorkbench) { runCleanUp(realWorkbench); ISelection input = null; if ((bitSet & INCLUDE_EDITOR_INPUT) != 0) { - if (part instanceof IEditorPart) { - final IEditorPart editorPart = (IEditorPart) part; + if (part instanceof final IEditorPart editorPart) { input = new StructuredSelection(new Object[] { editorPart.getEditorInput() }); } } @@ -374,8 +371,7 @@ public void menuAboutToShow(IMenuManager mgr) { private void addMenuContributions() { IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class); AbstractPartRenderer obj = factory.getRenderer(menuModel, null); - if (obj instanceof MenuManagerRenderer) { - MenuManagerRenderer renderer = (MenuManagerRenderer) obj; + if (obj instanceof MenuManagerRenderer renderer) { renderer.reconcileManagerToModel(menu, menuModel); renderer.processContributions(menuModel, menuModel.getElementId(), false, true); // double cast because we're bad people @@ -447,8 +443,7 @@ private void cleanUpContributionCache() { IRendererFactory factory = modelContext.get(IRendererFactory.class); if (factory != null) { AbstractPartRenderer obj = factory.getRenderer(menuModel, null); - if (obj instanceof MenuManagerRenderer) { - MenuManagerRenderer renderer = (MenuManagerRenderer) obj; + if (obj instanceof MenuManagerRenderer renderer) { renderer.cleanUp(menuModel); } } @@ -509,8 +504,7 @@ public void dispose() { // unlink ourselves from the renderer IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class); AbstractPartRenderer obj = factory.getRenderer(menuModel, null); - if (obj instanceof MenuManagerRenderer) { - MenuManagerRenderer renderer = (MenuManagerRenderer) obj; + if (obj instanceof MenuManagerRenderer renderer) { unlink(renderer, menuModel); renderer.clearModelToManager(menuModel, menu); } @@ -535,8 +529,7 @@ private void unlink(MenuManagerRenderer renderer, MMenu menu) { renderer.clearModelToContribution(menuElement, (IContributionItem) item); OpaqueElementUtil.clearOpaqueItem(menuElement); } - } else if (menuElement instanceof MMenu) { - MMenu subMenu = (MMenu) menuElement; + } else if (menuElement instanceof MMenu subMenu) { unlink(renderer, subMenu); MenuManager manager = renderer.getManager(subMenu); if (manager != null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ProductInfo.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ProductInfo.java index 2286d5eb8a2..bfa790ce113 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ProductInfo.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ProductInfo.java @@ -24,7 +24,7 @@ * @since 3.0 */ public class ProductInfo { - private IProduct product; + private final IProduct product; private String productName; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ReopenEditorMenu.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ReopenEditorMenu.java index dc665ce5e2d..db6be26c0af 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ReopenEditorMenu.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ReopenEditorMenu.java @@ -42,7 +42,7 @@ public class ReopenEditorMenu extends ContributionItem { private EditorHistory history; - private boolean showSeparator; + private final boolean showSeparator; // the maximum length for a file name; must be >= 4 private static final int MAX_TEXT_LENGTH = 40; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SaveableHelper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SaveableHelper.java index cea4f35e7f8..582e336be34 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SaveableHelper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SaveableHelper.java @@ -260,8 +260,9 @@ static boolean runProgressMonitorOperation(String opName, final IRunnableWithPro IRunnableWithProgress runnable = monitor -> { progressOp.run(monitor); // Only indicate success if the monitor wasn't canceled - if (!monitor.isCanceled()) + if (!monitor.isCanceled()) { success[0] = true; + } }; try { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SaveablesList.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SaveablesList.java index b067cafeae9..7b58f101b41 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SaveablesList.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SaveablesList.java @@ -68,18 +68,18 @@ */ public class SaveablesList implements ISaveablesLifecycleListener { - private ListenerList listeners = new ListenerList<>(); + private final ListenerList listeners = new ListenerList<>(); // event source (mostly ISaveablesSource) -> Set of Saveable - private Map> modelMap = new LinkedHashMap<>(); + private final Map> modelMap = new LinkedHashMap<>(); // reference counting map - private Map modelRefCounts = new LinkedHashMap<>(); + private final Map modelRefCounts = new LinkedHashMap<>(); // lists contain "equal" saveables as many times as we have counted them above - private Map> equalKeys = new IdentityHashMap<>(); + private final Map> equalKeys = new IdentityHashMap<>(); - private Set nonPartSources = new HashSet<>(); + private final Set nonPartSources = new HashSet<>(); /** * Returns the list of open models managed by this model manager. @@ -464,8 +464,7 @@ private Object preCloseParts(List partsToClose, boolean addNonPa } } Saveable[] saveables = getSaveables(part); - if (save && saveable instanceof ISaveablePart2) { - ISaveablePart2 saveablePart2 = (ISaveablePart2) saveable; + if (save && saveable instanceof ISaveablePart2 saveablePart2) { // TODO show saveablePart2 before prompting, see // EditorManager.saveAll boolean confirm = true; @@ -733,8 +732,9 @@ protected int getShellStyle() { if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) { int result = dlg.open(); // Just return null to prevent the operation continuing - if (result == IDialogConstants.CANCEL_ID) + if (result == IDialogConstants.CANCEL_ID) { return true; + } if (dlg.getCheckboxValue()) { apiPreferenceStore.setValue(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN, @@ -796,8 +796,9 @@ public boolean saveModels(final List finalModels, final IShellProvider continue; } SaveableHelper.doSaveModel(model, subMonitor.split(1), shellProvider, blockUntilSaved); - if (subMonitor.isCanceled()) + if (subMonitor.isCanceled()) { break; + } } monitorWrap.done(); }; @@ -807,11 +808,11 @@ public boolean saveModels(final List finalModels, final IShellProvider } private static class PostCloseInfo { - private List partsClosing = new ArrayList<>(); + private final List partsClosing = new ArrayList<>(); - private Map modelsDecrementing = new HashMap<>(); + private final Map modelsDecrementing = new HashMap<>(); - private Set modelsClosing = new HashSet<>(); + private final Set modelsClosing = new HashSet<>(); } public void postClose(Object postCloseInfoObject) { @@ -844,8 +845,7 @@ public void postClose(Object postCloseInfoObject) { * @return the saveable models */ private Saveable[] getSaveables(IWorkbenchPart part) { - if (part instanceof ISaveablesSource) { - ISaveablesSource source = (ISaveablesSource) part; + if (part instanceof ISaveablesSource source) { return source.getSaveables(); } else if (SaveableHelper.isSaveable(part)) { return new Saveable[] { new DefaultSaveable(part) }; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SelectionAdapterFactory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SelectionAdapterFactory.java index 2d37812b3fc..e9eec218bc7 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SelectionAdapterFactory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SelectionAdapterFactory.java @@ -65,8 +65,7 @@ private Object countable(final ISelection sel) { if (sel.isEmpty()) { return ICOUNT_0; } - if (sel instanceof IStructuredSelection) { - final IStructuredSelection ss = (IStructuredSelection) sel; + if (sel instanceof final IStructuredSelection ss) { return (ICountable) ss::size; } return ICOUNT_1; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowInMenu.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowInMenu.java index be3643a6b57..81068c7bd0d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowInMenu.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowInMenu.java @@ -79,7 +79,7 @@ public class ShowInMenu extends ContributionItem implements IWorkbenchContributi private boolean dirty = true; - private IMenuListener menuListener = manager -> { + private final IMenuListener menuListener = manager -> { manager.markDirty(); dirty = true; }; @@ -317,8 +317,9 @@ private ArrayList getShowInPartIds(IWorkbenchPart sourcePart) { protected IWorkbenchPart getSourcePart() { IWorkbenchWindow window = getWindow(); - if (window == null) + if (window == null) { return null; + } IWorkbenchPage page = window.getActivePage(); return page != null ? page.getActivePart() : null; @@ -377,8 +378,9 @@ public void initialize(IServiceLocator serviceLocator) { } protected IWorkbenchWindow getWindow() { - if (locator == null) + if (locator == null) { return null; + } IWorkbenchLocationService wls = locator.getService(IWorkbenchLocationService.class); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowPartPaneMenuHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowPartPaneMenuHandler.java index 2db87e498a7..8111763cac9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowPartPaneMenuHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowPartPaneMenuHandler.java @@ -57,8 +57,7 @@ public Object execute(ExecutionEvent event) { if (partContainer != null) { Composite parent = partContainer.getParent(); while (parent != null) { - if (parent instanceof CTabFolder) { - CTabFolder ctf = (CTabFolder) parent; + if (parent instanceof CTabFolder ctf) { final CTabItem item = ctf.getSelection(); if (item != null) { final Display disp = item.getDisplay(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowViewMenu.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowViewMenu.java index 1c32242be9d..c030266b8ac 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowViewMenu.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowViewMenu.java @@ -73,24 +73,24 @@ public class ShowViewMenu extends ContributionItem { private static final String NO_TARGETS_MSG = WorkbenchMessages.Workbench_showInNoTargets; - private Comparator actionComparator = (o1, o2) -> { + private final Comparator actionComparator = (o1, o2) -> { if (collator == null) { collator = Collator.getInstance(); } return collator.compare(o1.label, o2.label); }; - private Action showDlgAction; + private final Action showDlgAction; - private Map actions = new HashMap<>(21); + private final Map actions = new HashMap<>(21); // Maps pages to a list of opened views - private Map> openedViews = new HashMap<>(); + private final Map> openedViews = new HashMap<>(); private MenuManager menuManager; - private IMenuListener menuListener = IMenuManager::markDirty; - private boolean makeFast; + private final IMenuListener menuListener = IMenuManager::markDirty; + private final boolean makeFast; private static Collator collator; @@ -206,8 +206,8 @@ private void fillMenu(IMenuManager innerMgr) { static class PluginCCIP extends CommandContributionItemParameter implements IPluginContribution { - private String localId; - private String pluginId; + private final String localId; + private final String pluginId; public PluginCCIP(IViewDescriptor v, IServiceLocator serviceLocator, String id, String commandId, int style) { super(serviceLocator, id, commandId, style); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowViewMenuHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowViewMenuHandler.java index 950d52ad713..96781840831 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowViewMenuHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ShowViewMenuHandler.java @@ -66,13 +66,11 @@ public Object execute(ExecutionEvent event) { if (partContainer != null) { Composite parent = partContainer.getParent(); while (parent != null) { - if (parent instanceof CTabFolder) { - CTabFolder ctf = (CTabFolder) parent; + if (parent instanceof CTabFolder ctf) { final Control topRight = ctf.getTopRight(); if (topRight instanceof Composite) { for (Control child : ((Composite) topRight).getChildren()) { - if (child instanceof ToolBar && "ViewMenu".equals(child.getData())) { //$NON-NLS-1$ - ToolBar tb = (ToolBar) child; + if (child instanceof ToolBar tb && "ViewMenu".equals(child.getData())) { //$NON-NLS-1$ ToolItem ti = tb.getItem(0); Event sevent = new Event(); sevent.type = SWT.Selection; @@ -116,8 +114,9 @@ private void showStandaloneViewMenu(ExecutionEvent event, MPart model, MMenu men menu.setVisible(true); while (!menu.isDisposed() && menu.isVisible()) { - if (!display.readAndDispatch()) + if (!display.readAndDispatch()) { display.sleep(); + } } if (!(menu.getData() instanceof MenuManager)) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlavePageService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlavePageService.java index 9325c8b650c..f568110fb3c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlavePageService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlavePageService.java @@ -26,9 +26,9 @@ */ public class SlavePageService implements IPageService, IDisposable { - private IPageService parent; - private ListenerList pageListeners = new ListenerList<>(ListenerList.IDENTITY); - private ListenerList perspectiveListeners = new ListenerList<>(ListenerList.IDENTITY); + private final IPageService parent; + private final ListenerList pageListeners = new ListenerList<>(ListenerList.IDENTITY); + private final ListenerList perspectiveListeners = new ListenerList<>(ListenerList.IDENTITY); public SlavePageService(IPageService parent) { if (parent == null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlavePartService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlavePartService.java index c6869459b82..654d9f3166d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlavePartService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlavePartService.java @@ -39,9 +39,9 @@ public class SlavePartService implements IPartService, IDisposable { * The parent part service to which all listeners are routed. This value is * never null. */ - private IPartService parent; + private final IPartService parent; - private ListenerList listeners = new ListenerList(ListenerList.IDENTITY); + private final ListenerList listeners = new ListenerList(ListenerList.IDENTITY); /** * Constructs a new instance. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlaveSelectionService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlaveSelectionService.java index 4c961c96b01..ac4d92978ff 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlaveSelectionService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SlaveSelectionService.java @@ -28,12 +28,12 @@ */ public class SlaveSelectionService implements ISelectionService, IDisposable { - private ListenerList postListeners = new ListenerList<>(ListenerList.IDENTITY); - private ListenerList listeners = new ListenerList<>(ListenerList.IDENTITY); - private Map listenersToPartId = new HashMap<>(); - private Map postListenersToPartId = new HashMap<>(); + private final ListenerList postListeners = new ListenerList<>(ListenerList.IDENTITY); + private final ListenerList listeners = new ListenerList<>(ListenerList.IDENTITY); + private final Map listenersToPartId = new HashMap<>(); + private final Map postListenersToPartId = new HashMap<>(); - private ISelectionService parentSelectionService; + private final ISelectionService parentSelectionService; public SlaveSelectionService(ISelectionService parentSelectionService) { if (parentSelectionService == null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SplitHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SplitHandler.java index d51beeb6a54..c2c96fd0581 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SplitHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SplitHandler.java @@ -43,12 +43,14 @@ public class SplitHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { // Only works for the active editor IEditorPart activeEditor = HandlerUtil.getActiveEditor(event); - if (activeEditor == null) + if (activeEditor == null) { return null; + } MPart editorPart = activeEditor.getSite().getService(MPart.class); - if (editorPart == null) + if (editorPart == null) { return null; + } window = HandlerUtil.getActiveWorkbenchWindowChecked(event); @@ -56,8 +58,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException { modelService = editorPart.getContext().get(EModelService.class); MPartStack stack = getStackFor(editorPart); - if (stack == null) + if (stack == null) { return null; + } window.getShell().setRedraw(false); try { @@ -92,8 +95,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException { private MPartStack getStackFor(MPart part) { MUIElement presentationElement = part.getCurSharedRef() == null ? part : part.getCurSharedRef(); MUIElement parent = presentationElement.getParent(); - while (parent != null && !(parent instanceof MPartStack)) + while (parent != null && !(parent instanceof MPartStack)) { parent = parent.getParent(); + } return (MPartStack) parent; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SplitValues.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SplitValues.java index 4b42d1b4ed7..d8cfa30a025 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SplitValues.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SplitValues.java @@ -25,7 +25,7 @@ */ public class SplitValues implements IParameterValues { - private HashMap values = new HashMap<>(); + private final HashMap values = new HashMap<>(); public SplitValues() { values.put(WorkbenchMessages.SplitValues_Horizontal, "true"); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SwitchToWindowMenu.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SwitchToWindowMenu.java index 7dab7674ab9..e4615c831cd 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SwitchToWindowMenu.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/SwitchToWindowMenu.java @@ -31,7 +31,7 @@ public class SwitchToWindowMenu extends ContributionItem { private IWorkbenchWindow workbenchWindow; - private boolean showSeparator; + private final boolean showSeparator; /** * Creates a new instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/UISynchronizer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/UISynchronizer.java index 5e018e33294..c6d1397ac05 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/UISynchronizer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/UISynchronizer.java @@ -48,8 +48,9 @@ protected Boolean initialValue() { @Override public void set(Boolean value) { - if (value != Boolean.TRUE && value != Boolean.FALSE) + if (value != Boolean.TRUE && value != Boolean.FALSE) { throw new IllegalArgumentException(); + } super.set(value); } }; @@ -62,8 +63,9 @@ protected Boolean initialValue() { @Override public void set(Boolean value) { - if (value != Boolean.TRUE && value != Boolean.FALSE) + if (value != Boolean.TRUE && value != Boolean.FALSE) { throw new IllegalArgumentException(); + } if (value == Boolean.TRUE && startupThread.get().booleanValue()) { throw new IllegalStateException(); } @@ -78,8 +80,9 @@ public UISynchronizer(Display display, UILockListener lock) { public void started() { synchronized (this) { - if (!isStarting) + if (!isStarting) { throw new IllegalStateException(); + } isStarting = false; for (Iterator i = pendingStartup.iterator(); i.hasNext();) { Runnable runnable = i.next(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewIntroAdapterPart.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewIntroAdapterPart.java index 578a19f4909..b0a12fc1a19 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewIntroAdapterPart.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewIntroAdapterPart.java @@ -53,16 +53,19 @@ public final class ViewIntroAdapterPart extends ViewPart { private IEventBroker eventBroker; - private EventHandler zoomChangeListener = event -> { - if (!handleZoomEvents) + private final EventHandler zoomChangeListener = event -> { + if (!handleZoomEvents) { return; + } Object changedObj = event.getProperty(EventTags.ELEMENT); - if (!(changedObj instanceof MPartStack)) + if (!(changedObj instanceof MPartStack)) { return; + } - if (changedObj != getIntroStack()) + if (changedObj != getIntroStack()) { return; + } if (UIEvents.isADD(event) && UIEvents.contains(event, UIEvents.EventTags.NEW_VALUE, IPresentationEngine.MAXIMIZED)) { @@ -79,8 +82,9 @@ public final class ViewIntroAdapterPart extends ViewPart { private void addZoomListener() { ViewSite site = (ViewSite) getViewSite(); MPart introModelPart = site.getModel(); - if (introModelPart == null || introModelPart.getContext() == null) + if (introModelPart == null || introModelPart.getContext() == null) { return; + } eventBroker = introModelPart.getContext().get(IEventBroker.class); eventBroker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS, zoomChangeListener); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewIntroAdapterSite.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewIntroAdapterSite.java index a4938df7949..eb563cdd7ed 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewIntroAdapterSite.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewIntroAdapterSite.java @@ -31,9 +31,9 @@ * @since 3.0 */ final class ViewIntroAdapterSite implements IIntroSite { - private IntroDescriptor descriptor; + private final IntroDescriptor descriptor; - private IViewSite viewSite; + private final IViewSite viewSite; public ViewIntroAdapterSite(IViewSite viewSite, IntroDescriptor descriptor) { this.viewSite = viewSite; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewPluginAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewPluginAction.java index 139aa5e71ab..525d8f11a19 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewPluginAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewPluginAction.java @@ -26,7 +26,7 @@ * with the view part in which the action is intended to run. */ public final class ViewPluginAction extends PartPluginAction { - private IViewPart viewPart; + private final IViewPart viewPart; /** * This class adds the requirement that action delegates loaded on demand diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewReference.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewReference.java index df3d0676b17..61e60508ece 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewReference.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewReference.java @@ -36,7 +36,7 @@ public class ViewReference extends WorkbenchPartReference implements IViewReference { - private ViewDescriptor descriptor; + private final ViewDescriptor descriptor; private IMemento memento; public ViewReference(IEclipseContext windowContext, IWorkbenchPage page, MPart part, ViewDescriptor descriptor) { @@ -78,8 +78,9 @@ public String getSecondaryId() { MPart part = getModel(); int colonIndex = part.getElementId().indexOf(':'); - if (colonIndex == -1 || colonIndex == (part.getElementId().length() - 1)) + if (colonIndex == -1 || colonIndex == (part.getElementId().length() - 1)) { return null; + } return part.getElementId().substring(colonIndex + 1); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewSite.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewSite.java index 0ad58dc5d64..79f265d459d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewSite.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewSite.java @@ -43,8 +43,9 @@ public String getSecondaryId() { MPart part = getModel(); int colonIndex = part.getElementId().indexOf(':'); - if (colonIndex == -1 || colonIndex == (part.getElementId().length() - 1)) + if (colonIndex == -1 || colonIndex == (part.getElementId().length() - 1)) { return null; + } return part.getElementId().substring(colonIndex + 1); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewerActionBuilder.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewerActionBuilder.java index bd13f8cc7a6..1e3ec9325f6 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewerActionBuilder.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ViewerActionBuilder.java @@ -105,7 +105,7 @@ public boolean readViewerContributions(String id, ISelectionProvider prov, IWork * element. */ private static class ViewerContribution extends BasicContribution implements ISelectionChangedListener { - private ISelectionProvider selProvider; + private final ISelectionProvider selProvider; private ActionExpression visibilityTest; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WWinActionBars.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WWinActionBars.java index fdb78125907..55d8b0f215d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WWinActionBars.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WWinActionBars.java @@ -24,7 +24,7 @@ import org.eclipse.ui.services.IServiceLocator; public class WWinActionBars implements IActionBars2 { - private WorkbenchWindow window; + private final WorkbenchWindow window; /** * PerspActionBars constructor comment. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WWinPluginPulldown.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WWinPluginPulldown.java index 9d9550a6ddc..91e93297f40 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WWinPluginPulldown.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WWinPluginPulldown.java @@ -149,8 +149,7 @@ public Menu getMenu(Control parent) { public Menu getMenu(Menu parent) { IWorkbenchWindowPulldownDelegate delegate = getPulldownDelegate(); - if (delegate instanceof IWorkbenchWindowPulldownDelegate2) { - IWorkbenchWindowPulldownDelegate2 delegate2 = (IWorkbenchWindowPulldownDelegate2) delegate; + if (delegate instanceof IWorkbenchWindowPulldownDelegate2 delegate2) { final MenuLoader menuLoader = new MenuLoader(delegate2, parent); SafeRunner.run(menuLoader); return menuLoader.getMenu(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java index 26cfc7a20e3..5bc2f90cb1c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java @@ -306,7 +306,7 @@ public final class Workbench extends EventManager implements IWorkbench, org.ecl private static final class StartupProgressBundleListener implements ServiceListener { private final SubMonitor subMonitor; - private Display displayForStartupListener; + private final Display displayForStartupListener; StartupProgressBundleListener(IProgressMonitor progressMonitor, Display display) { displayForStartupListener = display; @@ -364,7 +364,7 @@ public void serviceChanged(ServiceEvent event) { * * @since 3.0 */ - private Display display; + private final Display display; private boolean workbenchAutoSave = true; @@ -393,7 +393,7 @@ public void serviceChanged(ServiceEvent event) { * * @since 3.0 */ - private WorkbenchAdvisor advisor; + private final WorkbenchAdvisor advisor; /** * Object for configuring the workbench. Lazily initialized to an instance @@ -407,7 +407,7 @@ public void serviceChanged(ServiceEvent event) { /** * ExtensionEventHandler handles extension life-cycle events. */ - private ExtensionEventHandler extensionEventHandler; + private final ExtensionEventHandler extensionEventHandler; /** * A count of how many large updates are going on. This tracks nesting of @@ -428,17 +428,17 @@ public void serviceChanged(ServiceEvent event) { /** * Listener list for registered IWorkbenchListeners . */ - private ListenerList workbenchListeners = new ListenerList<>(ListenerList.IDENTITY); + private final ListenerList workbenchListeners = new ListenerList<>(ListenerList.IDENTITY); private ServiceRegistration workbenchService; - private MApplication application; + private final MApplication application; - private IEclipseContext e4Context; + private final IEclipseContext e4Context; - private IEventBroker eventBroker; + private final IEventBroker eventBroker; - private IExtensionRegistry registry; + private final IExtensionRegistry registry; boolean initializationDone = false; @@ -448,7 +448,7 @@ public void serviceChanged(ServiceEvent event) { private Job autoSaveJob; - private String id; + private final String id; private ServiceRegistration e4WorkbenchService; // flag used to identify if the application model needs to be saved @@ -599,8 +599,7 @@ public static int createAndRunWorkbench(final Display display, final WorkbenchAd int orientation = store.getInt(IPreferenceConstants.LAYOUT_DIRECTION); Window.setDefaultOrientation(orientation); } - if (obj instanceof E4Application) { - E4Application e4app = (E4Application) obj; + if (obj instanceof E4Application e4app) { E4Workbench e4Workbench = e4app.createE4Workbench(getApplicationContext(), display); MApplication appModel = e4Workbench.getApplication(); @@ -748,8 +747,9 @@ static Object getApplication(@SuppressWarnings("unused") String[] args) { if (runs.length > 0) { Object runnable; runnable = runs[0].createExecutableExtension("class");//$NON-NLS-1$ - if (runnable instanceof IApplication) + if (runnable instanceof IApplication) { return runnable; + } } } } catch (CoreException e) { @@ -828,10 +828,12 @@ public void run() throws Exception { if (splashShell == null) { splashShell = WorkbenchPlugin.getSplashShell(display); - if (splashShell == null) + if (splashShell == null) { return; - if (background != null) + } + if (background != null) { splashShell.setBackgroundImage(background); + } } Dictionary properties = new Hashtable<>(); @@ -842,11 +844,13 @@ public void run() throws Exception { @Override public void applicationRunning() { - if (background != null) + if (background != null) { background.dispose(); + } registration[0].unregister(); // unregister ourself - if (splash != null) + if (splash != null) { splash.dispose(); + } WorkbenchPlugin.unsetSplashShell(display); } @@ -867,8 +871,9 @@ public void handleException(Throwable e) { .handle(StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH, "Could not instantiate splash", e)); //$NON-NLS-1$ createSplash = false; splash = null; - if (background != null) + if (background != null) { background.dispose(); + } } }; @@ -934,17 +939,20 @@ private static Image getImage(Display display, InputStream input) { * @since 3.3 */ private static AbstractSplashHandler getSplash() { - if (!createSplash) + if (!createSplash) { return null; + } if (splash == null) { IProduct product = Platform.getProduct(); - if (product != null) + if (product != null) { splash = SplashHandlerFactory.findSplashHandlerFor(product); + } - if (splash == null) + if (splash == null) { splash = new EclipseSplashHandler(); + } } return splash; } @@ -1525,8 +1533,9 @@ IWorkbenchWindow createWorkbenchWindow(IAdaptable input, IPerspectiveDescriptor } WorkbenchWindow result = (WorkbenchWindow) windowContext.get(IWorkbenchWindow.class); if (result == null) { - if (windowBeingCreated != null) + if (windowBeingCreated != null) { return windowBeingCreated; + } try { result = new WorkbenchWindow(input, descriptor); @@ -1819,8 +1828,9 @@ public void runWithException() throws Throwable { } }); - if (bail[0]) + if (bail[0]) { return false; + } } finally { UIStats.end(UIStats.RESTORE_WORKBENCH, this, "Workbench"); //$NON-NLS-1$ @@ -2018,8 +2028,7 @@ private void initializeE4Services() { eventBroker.subscribe(UIEvents.UIElement.TOPIC_TOBERENDERED, event -> { if (Boolean.TRUE.equals(event.getProperty(UIEvents.EventTags.NEW_VALUE))) { Object element = event.getProperty(UIEvents.EventTags.ELEMENT); - if (element instanceof MPart) { - MPart part = (MPart) element; + if (element instanceof MPart part) { createReference(part); } } @@ -2029,8 +2038,7 @@ private void initializeE4Services() { // to inject the ViewReference/EditorReference into the context eventBroker.subscribe(UIEvents.Context.TOPIC_CONTEXT, event -> { Object element = event.getProperty(UIEvents.EventTags.ELEMENT); - if (element instanceof MPart) { - MPart part = (MPart) element; + if (element instanceof MPart part) { IEclipseContext context = part.getContext(); if (context != null) { setReference(part, context); @@ -2040,10 +2048,9 @@ private void initializeE4Services() { eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_CHILDREN, event -> { Object element = event.getProperty(UIEvents.EventTags.ELEMENT); - if (!(element instanceof MApplication)) { + if (!(element instanceof MApplication app)) { return; } - MApplication app = (MApplication) element; if (UIEvents.isREMOVE(event)) { if (app.getChildren().isEmpty()) { Object oldValue = event.getProperty(UIEvents.EventTags.OLD_VALUE); @@ -2227,8 +2234,8 @@ public Object compute(IEclipseContext context, String contextKey) { WorkbenchPlugin.getDefault().initializeContext(e4Context); } - private ArrayList commandsToRemove = new ArrayList<>(); - private ArrayList categoriesToRemove = new ArrayList<>(); + private final ArrayList commandsToRemove = new ArrayList<>(); + private final ArrayList categoriesToRemove = new ArrayList<>(); private CommandService initializeCommandService(IEclipseContext appContext) { CommandService service = new CommandService(commandManager, appContext); @@ -2239,7 +2246,7 @@ private CommandService initializeCommandService(IEclipseContext appContext) { return service; } - private Map bindingContexts = new HashMap<>(); + private final Map bindingContexts = new HashMap<>(); public MBindingContext getBindingContext(String id) { // cache @@ -2675,8 +2682,9 @@ private static String buildCommandLine(String workspace) { StringBuilder result = new StringBuilder(512); String userData = System.getProperty(IApplicationContext.EXIT_DATA_PROPERTY); - if (userData != null && !userData.isBlank()) + if (userData != null && !userData.isBlank()) { result.append(userData); + } result.append(CMD_DATA); result.append('\n'); @@ -2841,8 +2849,9 @@ private int runUI() { display.setSynchronizer(synchronizer); // declare the main thread to be a startup thread. UISynchronizer.startupThread.set(Boolean.TRUE); - } else + } else { synchronizer = null; + } // ModalContext should not spin the event loop (there is no UI yet to block) ModalContext.setAllowReadAndDispatch(false); @@ -2940,8 +2949,9 @@ public void run() { ModalContext.setAllowReadAndDispatch(true); isStarting = false; - if (synchronizer != null) + if (synchronizer != null) { synchronizer.started(); + } } returnCode = PlatformUI.RETURN_OK; if (!initOK[0]) { @@ -3252,8 +3262,7 @@ private void updateActiveWorkbenchWindowMenuManager(boolean textOnly) { final IWorkbenchWindow workbenchWindow = getActiveWorkbenchWindow(); - if (workbenchWindow instanceof WorkbenchWindow) { - WorkbenchWindow activeWorkbenchWindow = (WorkbenchWindow) workbenchWindow; + if (workbenchWindow instanceof WorkbenchWindow activeWorkbenchWindow) { if (activeWorkbenchWindow.isClosing()) { return; } @@ -3318,7 +3327,7 @@ public void setIntroDescriptor(IntroDescriptor descriptor) { */ private IntroDescriptor introDescriptor; - private IRegistryChangeListener startupRegistryListener = event -> { + private final IRegistryChangeListener startupRegistryListener = event -> { final IExtensionDelta[] deltas = event.getExtensionDeltas(PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_STARTUP); if (deltas.length == 0) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchConfigurer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchConfigurer.java index 81f3f9d83b0..7f74bf72ee2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchConfigurer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchConfigurer.java @@ -47,7 +47,7 @@ public final class WorkbenchConfigurer implements IWorkbenchConfigurer { * * @see #setData */ - private Map extraData = new HashMap(); + private final Map extraData = new HashMap(); /** * Indicates whether workbench state should be saved on close and restored on diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchIntroManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchIntroManager.java index 741a3a889ba..89ebca29018 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchIntroManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchIntroManager.java @@ -192,14 +192,16 @@ public void setIntroStandby(IIntroPart part, boolean standby) { } MPartStack introStack = getIntroStack(viewIntroAdapterPart); - if (introStack == null) + if (introStack == null) { return; + } boolean isMaximized = isIntroMaximized(viewIntroAdapterPart); - if (!isMaximized && !standby) + if (!isMaximized && !standby) { introStack.getTags().add(IPresentationEngine.MAXIMIZED); - else if (isMaximized && standby) + } else if (isMaximized && standby) { introStack.getTags().remove(IPresentationEngine.MAXIMIZED); + } } private MPartStack getIntroStack(ViewIntroAdapterPart introAdapter) { @@ -218,8 +220,9 @@ private MPartStack getIntroStack(ViewIntroAdapterPart introAdapter) { private boolean isIntroMaximized(ViewIntroAdapterPart introAdapter) { MPartStack introStack = getIntroStack(introAdapter); - if (introStack == null) + if (introStack == null) { return false; + } return introStack.getTags().contains(IPresentationEngine.MAXIMIZED); } @@ -251,14 +254,14 @@ public IIntroPart getIntro() { for (IWorkbenchWindow iWorkbenchWindow : this.workbench.getWorkbenchWindows()) { WorkbenchWindow window = (WorkbenchWindow) iWorkbenchWindow; MUIElement introPart = window.modelService.find(IIntroConstants.INTRO_VIEW_ID, window.getModel()); - if (introPart instanceof MPlaceholder) { - MPlaceholder introPH = (MPlaceholder) introPart; + if (introPart instanceof MPlaceholder introPH) { MPart introModelPart = (MPart) introPH.getRef(); CompatibilityView compatView = (CompatibilityView) introModelPart.getObject(); if (compatView != null) { Object obj = compatView.getPart(); - if (obj instanceof ViewIntroAdapterPart) + if (obj instanceof ViewIntroAdapterPart) { return (ViewIntroAdapterPart) obj; + } } } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchLayoutSettingsTransfer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchLayoutSettingsTransfer.java index c7ba4cccdc1..1228391dc24 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchLayoutSettingsTransfer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchLayoutSettingsTransfer.java @@ -45,9 +45,10 @@ public IStatus transferSettings(IPath newWorkspaceRoot) { IPath currentLocation = getNewWorkbenchStateLocation(Platform.getLocation()); File workspaceFile = createFileAndDirectories(newWorkspaceRoot); - if (workspaceFile == null) + if (workspaceFile == null) { return new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, WorkbenchMessages.WorkbenchSettings_CouldNotCreateDirectories); + } File deltas = new File(currentLocation.toOSString(), "deltas.xml"); //$NON-NLS-1$ if (deltas.exists()) { @@ -96,8 +97,9 @@ private File createFileAndDirectories(IPath newWorkspaceRoot) { IPath newWorkspaceLocation = getNewWorkbenchStateLocation(newWorkspaceRoot); File workspaceFile = new File(newWorkspaceLocation.toOSString()); if (!workspaceFile.exists()) { - if (!workspaceFile.mkdirs()) + if (!workspaceFile.mkdirs()) { return null; + } } return workspaceFile; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPage.java index d8afe4ba902..878fadbdda0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPage.java @@ -262,7 +262,7 @@ public void partVisible(MPart part) { private MPerspectiveStack _perspectiveStack; /** Ids of parts used as Show In targets, maintained in MRU order */ - private List mruShowInPartIds = new ArrayList<>(); + private final List mruShowInPartIds = new ArrayList<>(); /** * Deactivate the last editor's action bars if another type of editor has // * @@ -508,13 +508,13 @@ private int lastIndexOfContainer(MElementContainer parent) { return -1; } - private List viewReferences = new ArrayList<>(); - private List editorReferences = new ArrayList<>(); + private final List viewReferences = new ArrayList<>(); + private final List editorReferences = new ArrayList<>(); - private List sortedPerspectives = new ArrayList<>(); + private final List sortedPerspectives = new ArrayList<>(); - private ListenerList partListenerList = new ListenerList<>(); - private ListenerList partListener2List = new ListenerList<>(); + private final ListenerList partListenerList = new ListenerList<>(); + private final ListenerList partListener2List = new ListenerList<>(); /** * A listener that forwards page change events to our part listeners. @@ -532,7 +532,7 @@ public void run() throws Exception { } }; - private E4PartListener e4PartListener = new E4PartListener(); + private final E4PartListener e4PartListener = new E4PartListener(); protected WorkbenchWindow legacyWindow; @@ -544,7 +544,7 @@ public void run() throws Exception { private Composite composite; - private ListenerList propertyChangeListeners = new ListenerList<>(); + private final ListenerList propertyChangeListeners = new ListenerList<>(); private IActionBars actionBars; @@ -575,7 +575,7 @@ public void run() throws Exception { } }; - private ActionSwitcher actionSwitcher = new ActionSwitcher(); + private final ActionSwitcher actionSwitcher = new ActionSwitcher(); private IExtensionTracker tracker; @@ -849,17 +849,18 @@ private boolean updateActionSets(List newActionSets) { installAreaDropSupport((Control) newValue); } } - } else if (element instanceof MPart && newValue == null) { + } else if (element instanceof MPart changedPart && newValue == null) { // If it's a 'e4' part then remove the reference for it - MPart changedPart = (MPart) element; Object impl = changedPart.getObject(); if (impl != null && !(impl instanceof CompatibilityPart)) { EditorReference eRef = getEditorReference(changedPart); - if (eRef != null) + if (eRef != null) { editorReferences.remove(eRef); + } ViewReference vRef = getViewReference(changedPart); - if (vRef != null) + if (vRef != null) { viewReferences.remove(vRef); + } } } }; @@ -869,32 +870,33 @@ private boolean updateActionSets(List newActionSets) { private void handleMinimizedStacks(@UIEventTopic(UIEvents.ApplicationElement.TOPIC_TAGS) Event event) { Object changedObj = event.getProperty(EventTags.ELEMENT); - if (!(changedObj instanceof MToolControl)) + if (!(changedObj instanceof final MToolControl minimizedStack)) { return; + } - final MToolControl minimizedStack = (MToolControl) changedObj; - - if (!(minimizedStack.getObject() instanceof TrimStack)) + if (!(minimizedStack.getObject() instanceof TrimStack)) { return; + } TrimStack ts = (TrimStack) minimizedStack.getObject(); - if (!(ts.getMinimizedElement() instanceof MPartStack)) + if (!(ts.getMinimizedElement() instanceof MPartStack)) { return; + } MPartStack stack = (MPartStack) ts.getMinimizedElement(); MUIElement stackSel = stack.getSelectedElement(); MPart thePart = null; if (stackSel instanceof MPart) { thePart = (MPart) stackSel; - } else if (stackSel instanceof MPlaceholder) { - MPlaceholder ph = (MPlaceholder) stackSel; + } else if (stackSel instanceof MPlaceholder ph) { if (ph.getRef() instanceof MPart) { thePart = (MPart) ph.getRef(); } } - if (thePart == null) + if (thePart == null) { return; + } if (UIEvents.isADD(event)) { if (UIEvents.contains(event, UIEvents.EventTags.NEW_VALUE, @@ -1186,8 +1188,9 @@ MPartDescriptor findDescriptor(String id) { */ private MPart findPart(String viewId, int searchFlags) { List parts = modelService.findElements(getWindowModel(), viewId, MPart.class, null, searchFlags); - if (!parts.isEmpty()) + if (!parts.isEmpty()) { return parts.get(0); + } return null; } @@ -1272,11 +1275,11 @@ private MPart showPart(int mode, MPart part) { // Report the visibility of the created part MStackElement sElement = part; - if (part.getCurSharedRef() != null) + if (part.getCurSharedRef() != null) { sElement = part.getCurSharedRef(); + } MUIElement parentElement = sElement.getParent(); - if (parentElement instanceof MPartStack) { - MPartStack partStack = (MPartStack) parentElement; + if (parentElement instanceof MPartStack partStack) { if (partStack.getSelectedElement() == sElement && !partStack.getTags().contains(IPresentationEngine.MINIMIZED)) { firePartVisible(part); @@ -1368,9 +1371,7 @@ public boolean closeEditors(IEditorReference[] refArray, boolean save) { return false; } - if (reference instanceof WorkbenchPartReference) { - WorkbenchPartReference ref = (WorkbenchPartReference) reference; - + if (reference instanceof WorkbenchPartReference ref) { // If we're being asked to close a part that is disposed (ie: // already closed), // skip it and proceed with closing the remaining parts. @@ -1390,10 +1391,12 @@ public boolean closeEditors(IEditorReference[] refArray, boolean save) { // navigation positions.) for (IEditorReference ref : editorRefs) { IEditorPart oldPart = ref.getEditor(false); - if (oldPart == null) + if (oldPart == null) { continue; - if (navigationHistory.updateActive(oldPart)) + } + if (navigationHistory.updateActive(oldPart)) { break; // updated - skip the rest + } } // notify the model manager before the close @@ -1951,8 +1954,9 @@ public IViewReference findViewReference(String viewId) { @Override public IViewReference findViewReference(String viewId, String secondaryId) { String compoundId = viewId; - if (secondaryId != null && secondaryId.length() > 0) + if (secondaryId != null && secondaryId.length() > 0) { compoundId += ":" + secondaryId; //$NON-NLS-1$ + } return findViewReference(compoundId); } @@ -2041,8 +2045,7 @@ public IEditorPart getActiveEditor() { List editors = modelService.findElements(area, CompatibilityEditor.MODEL_ELEMENT_ID, MPart.class); for (MPart model : editors) { Object object = model.getObject(); - if (object instanceof CompatibilityEditor) { - CompatibilityEditor editor = (CompatibilityEditor) object; + if (object instanceof CompatibilityEditor editor) { // see bug 308492 if (!editor.isBeingDisposed() && isInArea(area, model)) { return ((CompatibilityEditor) object).getEditor(); @@ -2060,8 +2063,7 @@ public IEditorPart getActiveEditor() { null); for (MPart part : parts) { Object object = part.getObject(); - if (object instanceof CompatibilityEditor) { - CompatibilityEditor editor = (CompatibilityEditor) object; + if (object instanceof CompatibilityEditor editor) { // see bug 308492 if (!editor.isBeingDisposed()) { if (isValid(perspective, part) || isValid(window, part)) { @@ -2098,8 +2100,7 @@ private IEditorPart findActiveEditor() { } Object object = model.getObject(); - if (object instanceof CompatibilityEditor) { - CompatibilityEditor editor = (CompatibilityEditor) object; + if (object instanceof CompatibilityEditor editor) { // see bug 308492 if (!editor.isBeingDisposed() && isInArea(area, model)) { return ((CompatibilityEditor) object).getEditor(); @@ -2112,8 +2113,7 @@ private IEditorPart findActiveEditor() { MPerspective perspective = getPerspectiveStack().getSelectedElement(); for (MPart model : activationList) { Object object = model.getObject(); - if (object instanceof CompatibilityEditor) { - CompatibilityEditor editor = (CompatibilityEditor) object; + if (object instanceof CompatibilityEditor editor) { // see bug 308492 if (!editor.isBeingDisposed()) { if (isValid(perspective, model) || isValid(window, model)) { @@ -2397,8 +2397,9 @@ public String getLabel() { public IPerspectiveDescriptor getPerspective() { MPerspectiveStack ps = getPerspectiveStack(); MPerspective curPersp = ps.getSelectedElement(); - if (curPersp == null) + if (curPersp == null) { return null; + } return getPerspectiveDesc(curPersp.getElementId()); } @@ -2461,10 +2462,12 @@ public void sortShowInPartIds(ArrayList partIds) { partIds.sort((ob1, ob2) -> { int index1 = mruShowInPartIds.indexOf(ob1); int index2 = mruShowInPartIds.indexOf(ob2); - if (index1 != -1 && index2 == -1) + if (index1 != -1 && index2 == -1) { return -1; - if (index1 == -1 && index2 != -1) + } + if (index1 == -1 && index2 != -1) { return 1; + } return index1 - index2; }); } @@ -2565,8 +2568,9 @@ public IWorkingSet getWorkingSet() { @Override public void hideActionSet(String actionSetID) { MPerspective mpersp = getCurrentPerspective(); - if (mpersp == null) + if (mpersp == null) { return; + } Perspective persp = getActivePerspective(); if (persp != null) { @@ -2645,8 +2649,7 @@ public void setup(MApplication application, EModelService modelService, IEventBr for (MPlaceholder placeholder : placeholders) { if (placeholder.isToBeRendered()) { MUIElement ref = placeholder.getRef(); - if (ref instanceof MPart) { - MPart part = (MPart) ref; + if (ref instanceof MPart part) { String uri = part.getContributionURI(); if (CompatibilityPart.COMPATIBILITY_VIEW_URI.equals(uri)) { createViewReferenceForPart(part, part.getElementId()); @@ -3312,14 +3315,16 @@ public void removePostSelectionListener(String partId, ISelectionListener listen public void resetPerspective() { MPerspectiveStack perspStack = getPerspectiveStack(); MPerspective persp = perspStack.getSelectedElement(); - if (persp == null) + if (persp == null) { return; + } // HACK!! the 'perspective' field doesn't match reality... IPerspectiveDescriptor desc = PlatformUI.getWorkbench().getPerspectiveRegistry() .findPerspectiveWithId(persp.getElementId()); - if (desc == null) + if (desc == null) { return; + } // send out reset notification legacyWindow.firePerspectiveChanged(this, desc, CHANGE_RESET); @@ -3379,8 +3384,7 @@ public void resetPerspective() { } boolean revert = false; - if (desc instanceof PerspectiveDescriptor) { - PerspectiveDescriptor perspectiveDescriptor = (PerspectiveDescriptor) desc; + if (desc instanceof PerspectiveDescriptor perspectiveDescriptor) { revert = perspectiveDescriptor.isPredefined() && !perspectiveDescriptor.hasCustomDefinition(); } @@ -3746,8 +3750,7 @@ private static List convertToSaveables(List parts, boo * @return the saveable models */ private static Saveable[] getSaveables(IWorkbenchPart part) { - if (part instanceof ISaveablesSource) { - ISaveablesSource source = (ISaveablesSource) part; + if (part instanceof ISaveablesSource source) { return source.getSaveables(); } return new Saveable[] { new DefaultSaveable(part) }; @@ -3891,7 +3894,7 @@ public void setEditorAreaVisible(boolean showEditorArea) { } } - private HashMap modelToPerspectiveMapping = new HashMap<>(); + private final HashMap modelToPerspectiveMapping = new HashMap<>(); private Perspective getPerspective(MPerspective mperspective) { if (mperspective == null) { @@ -4072,8 +4075,9 @@ private void replacePlaceholder(MPlaceholder ph) { private String getLabel(String str) { int index = str.lastIndexOf('.'); - if (index == -1) + if (index == -1) { return str; + } return str.substring(index + 1); } @@ -4263,8 +4267,9 @@ public MUIElement getActiveElement(IWorkbenchPartReference ref) { MUIElement element = null; MPerspective curPersp = modelService.getActivePerspective(window); - if (curPersp == null) + if (curPersp == null) { return null; + } MPlaceholder eaPH = (MPlaceholder) modelService.find(IPageLayout.ID_EDITOR_AREA, curPersp); MPart model = ((WorkbenchPartReference) ref).getModel(); @@ -4422,13 +4427,13 @@ public IViewPart[] getViewStack(IViewPart part) { if (parent instanceof MPartStack) { MStackElement selectedElement = ((MPartStack) parent).getSelectedElement(); - final MUIElement topPart = selectedElement instanceof MPlaceholder - ? ((MPlaceholder) selectedElement).getRef() + final MUIElement topPart = selectedElement instanceof MPlaceholder m + ? m.getRef() : null; List stack = new ArrayList<>(); for (Object child : parent.getChildren()) { - MPart siblingPart = child instanceof MPart ? (MPart) child + MPart siblingPart = child instanceof MPart m ? m : (MPart) ((MPlaceholder) child).getRef(); // Bug 398433 - guard against NPE Object siblingObject = siblingPart != null ? siblingPart.getObject() : null; @@ -4448,17 +4453,21 @@ public IViewPart[] getViewStack(IViewPart part) { * we can't set/know the order for inactive stacks. This workaround makes sure * that the topmost part is at least at the first position. */ - if (model1 == topPart) + if (model1 == topPart) { return Integer.MIN_VALUE; - if (model2 == topPart) + } + if (model2 == topPart) { return Integer.MAX_VALUE; + } int pos1 = activationList.indexOf(model1); int pos2 = activationList.indexOf(model2); - if (pos1 == -1) + if (pos1 == -1) { pos1 = Integer.MAX_VALUE; - if (pos2 == -1) + } + if (pos2 == -1) { pos2 = Integer.MAX_VALUE; + } return pos1 - pos2; }); @@ -4488,8 +4497,9 @@ public IExtensionTracker getExtensionTracker() { private String[] getArrayForTag(String tagPrefix) { List id = getCollectionForTag(tagPrefix); - if (id == null) + if (id == null) { return EMPTY_STRING_ARRAY; + } return id.toArray(new String[id.size()]); } @@ -4723,13 +4733,13 @@ public IEditorReference[] openEditors(IEditorInput[] inputs, String[] editorIDs, MPart editor = partService.createPart(CompatibilityEditor.MODEL_ELEMENT_ID); references[i] = createEditorReferenceForPart(editor, curInput, curEditorID, null); - if (i == activationIndex) + if (i == activationIndex) { editorToActivate = editor; + } // Set the information in the supplied IMemento into the // editor's model - if (curMemento instanceof XMLMemento) { - XMLMemento memento = (XMLMemento) curMemento; + if (curMemento instanceof XMLMemento memento) { StringWriter writer = new StringWriter(); try { memento.save(writer); @@ -4747,14 +4757,14 @@ public IEditorReference[] openEditors(IEditorInput[] inputs, String[] editorIDs, // Use the existing editor, update the state if it has *not* // been rendered EditorReference ee = (EditorReference) existingEditors[0]; - if (i == activationIndex) + if (i == activationIndex) { editorToActivate = ee.getModel(); + } if (ee.getModel().getWidget() == null) { // Set the information in the supplied IMemento into the // editor's model - if (curMemento instanceof XMLMemento) { - XMLMemento momento = (XMLMemento) curMemento; + if (curMemento instanceof XMLMemento momento) { StringWriter writer = new StringWriter(); try { momento.save(writer); @@ -4776,11 +4786,13 @@ public IEditorReference[] openEditors(IEditorInput[] inputs, String[] editorIDs, // Must be an externally defined memento, // take the second child IMemento[] kids = curMemento.getChildren(); - if (kids.length == 2) + if (kids.length == 2) { editorMem = kids[1]; + } } - if (editorMem != null) + if (editorMem != null) { pe.restoreState(editorMem); + } } } } @@ -5132,7 +5144,7 @@ public void run() throws Exception { } } - private WeakHashMap partEvents = new WeakHashMap<>(); + private final WeakHashMap partEvents = new WeakHashMap<>(); private static final int FIRE_PART_VISIBLE = 0x1; private static final int FIRE_PART_BROUGHTTOTOP = 0x2; @@ -5158,18 +5170,19 @@ public void run() throws Exception { // ...in this window ? MUIElement changedElement = (MUIElement) changedObj; - if (modelService.getTopLevelWindowFor(changedElement) != window) + if (modelService.getTopLevelWindowFor(changedElement) != window) { return; + } if (UIEvents.isADD(event)) { for (Object o : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) { - if (!(o instanceof MUIElement)) + if (!(o instanceof MUIElement element)) { continue; + } // We have to iterate through the new elements to see if any // contain (or are) MParts (e.g. we may have dragged a split // editor which contains two editors, both with EditorRefs) - MUIElement element = (MUIElement) o; List addedParts = modelService.findElements(element, null, MPart.class, null); for (MPart part : addedParts) { IWorkbenchPartReference ref = (IWorkbenchPartReference) part.getTransientData() @@ -5319,8 +5332,9 @@ private IEditorReference openExternalEditor(final EditorDescriptor desc, IEditor } private IPathEditorInput getPathEditorInput(IEditorInput input) { - if (input instanceof IPathEditorInput) + if (input instanceof IPathEditorInput) { return (IPathEditorInput) input; + } return Adapters.adapt(input, IPathEditorInput.class); } @@ -5332,8 +5346,9 @@ private IPathEditorInput getPathEditorInput(IEditorInput input) { */ private void unzoomSharedArea() { MPerspective curPersp = getPerspectiveStack().getSelectedElement(); - if (curPersp == null) + if (curPersp == null) { return; + } MPlaceholder eaPH = (MPlaceholder) modelService.find(IPageLayout.ID_EDITOR_AREA, curPersp); for (MPart part : modelService.findElements(eaPH, null, MPart.class, null)) { @@ -5393,8 +5408,7 @@ private void unzoomSharedArea(MUIElement element) { reference1.unsubscribe(); } } - } else if (element instanceof MPart) { - MPart part = (MPart) element; + } else if (element instanceof MPart part) { // a part has been unrendered, check to see if the shared // area needs to be unzoomed unzoomSharedArea(part); @@ -5410,20 +5424,23 @@ private void unzoomSharedArea(MUIElement element) { public String getHiddenItems() { MPerspective perspective = getCurrentPerspective(); - if (perspective == null) + if (perspective == null) { return ""; //$NON-NLS-1$ + } String result = perspective.getPersistedState().get(ModeledPageLayout.HIDDEN_ITEMS_KEY); - if (result == null) + if (result == null) { return ""; //$NON-NLS-1$ + } return result; } public void addHiddenItems(MPerspective perspective, String id) { String hiddenIDs = perspective.getPersistedState().get(ModeledPageLayout.HIDDEN_ITEMS_KEY); - if (hiddenIDs == null) + if (hiddenIDs == null) { hiddenIDs = ""; //$NON-NLS-1$ + } String persistedID = id + ","; //$NON-NLS-1$ if (!hiddenIDs.contains(persistedID)) { @@ -5434,8 +5451,9 @@ public void addHiddenItems(MPerspective perspective, String id) { public void addHiddenItems(String id) { MPerspective perspective = getCurrentPerspective(); - if (perspective == null) + if (perspective == null) { return; + } addHiddenItems(perspective, id); } @@ -5443,34 +5461,39 @@ public void removeHiddenItems(MPerspective perspective, String id) { String persistedID = id + ","; //$NON-NLS-1$ String hiddenIDs = perspective.getPersistedState().get(ModeledPageLayout.HIDDEN_ITEMS_KEY); - if (hiddenIDs == null) + if (hiddenIDs == null) { return; + } String newValue = hiddenIDs.replaceFirst(persistedID, ""); //$NON-NLS-1$ if (hiddenIDs.length() != newValue.length()) { - if (newValue.isEmpty()) + if (newValue.isEmpty()) { perspective.getPersistedState().remove(ModeledPageLayout.HIDDEN_ITEMS_KEY); - else + } else { perspective.getPersistedState().put(ModeledPageLayout.HIDDEN_ITEMS_KEY, newValue); + } } } public void removeHiddenItems(String id) { MPerspective perspective = getCurrentPerspective(); - if (perspective == null) + if (perspective == null) { return; + } removeHiddenItems(perspective, id); } public void setNewShortcuts(List wizards, String tagPrefix) { MPerspective persp = getCurrentPerspective(); - if (persp == null) + if (persp == null) { return; + } List existingNewWizards = new ArrayList<>(); for (String tag : persp.getTags()) { - if (tag.contains(tagPrefix)) + if (tag.contains(tagPrefix)) { existingNewWizards.add(tag); + } } List newWizards = new ArrayList<>(wizards.size()); @@ -5513,17 +5536,20 @@ private void createPerspectiveBarExtras() { Set perspSet = new LinkedHashSet<>(); for (String part : parts) { part = part.trim(); - if (!part.isEmpty()) + if (!part.isEmpty()) { perspSet.add(part); + } } for (String perspId : perspSet) { MPerspective persp = (MPerspective) modelService.find(perspId, window); - if (persp != null) + if (persp != null) { continue; // already in stack, i.e. has already been added above + } IPerspectiveDescriptor desc = getDescriptorFor(perspId); - if (desc == null) + if (desc == null) { continue; // this perspective does not exist + } persp = createPerspective(desc); persp.setLabel(desc.getLabel()); getPerspectiveStack().getChildren().add(persp); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPartReference.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPartReference.java index 0c495be51a4..38493f6f8cc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPartReference.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPartReference.java @@ -124,7 +124,7 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, * Current state of the reference. Used to detect recursive creation errors, * disposed references, etc. */ - private int state = STATE_LAZY; + private final int state = STATE_LAZY; protected IWorkbenchPart legacyPart; private boolean pinned = false; @@ -132,27 +132,27 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, /** * API listener list */ - private ListenerList propChangeListeners = new ListenerList<>(); + private final ListenerList propChangeListeners = new ListenerList<>(); /** * Internal listener list. Listens to the INTERNAL_PROPERTY_* property change * events that are not yet API. TODO: Make these properties API in 3.2 */ - private ListenerList internalPropChangeListeners = new ListenerList<>(); + private final ListenerList internalPropChangeListeners = new ListenerList<>(); - private ListenerList partChangeListeners = new ListenerList<>(); + private final ListenerList partChangeListeners = new ListenerList<>(); protected Map propertyCache = new HashMap<>(); - private IPropertyListener propertyChangeListener = this::partPropertyChanged; + private final IPropertyListener propertyChangeListener = this::partPropertyChanged; - private IPropertyChangeListener partPropertyChangeListener = this::partPropertyChanged; + private final IPropertyChangeListener partPropertyChangeListener = this::partPropertyChanged; private IWorkbenchPage page; - private MPart part; + private final MPart part; - private IEclipseContext windowContext; + private final IEclipseContext windowContext; private EventHandler contextEventHandler; @@ -292,8 +292,9 @@ public String getTitle() { @Override public String getTitleToolTip() { String toolTip = (String) part.getTransientData().get(IPresentationEngine.OVERRIDE_TITLE_TOOL_TIP_KEY); - if (toolTip == null || toolTip.isEmpty()) + if (toolTip == null || toolTip.isEmpty()) { toolTip = part.getLocalizedTooltip(); + } return Util.safeString(toolTip); } @@ -453,10 +454,11 @@ public void setPinned(boolean newPinned) { pinned = newPinned; immediateFirePropertyChange(IWorkbenchPartConstants.PROP_TITLE); - if (pinned) + if (pinned) { part.getTags().add(IPresentationEngine.ADORNMENT_PIN); - else + } else { part.getTags().remove(IPresentationEngine.ADORNMENT_PIN); + } fireInternalPropertyChange(INTERNAL_PROPERTY_PINNED); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPlugin.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPlugin.java index 7ed2f9875f9..1d4037a9d08 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPlugin.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPlugin.java @@ -148,7 +148,7 @@ public class WorkbenchPlugin extends AbstractUIPlugin { private BundleContext bundleContext; // The set of currently starting bundles - private Collection startingBundles = new HashSet<>(); + private final Collection startingBundles = new HashSet<>(); /** * Global workbench ui plugin flag. Only workbench implementation is allowed to @@ -311,15 +311,18 @@ public static Object createExtension(final IConfigurationElement element, final */ public static boolean hasExecutableExtension(IConfigurationElement element, String extensionName) { - if (element.getAttribute(extensionName) != null) + if (element.getAttribute(extensionName) != null) { return true; + } String elementText = element.getValue(); - if (elementText != null && !elementText.isEmpty()) + if (elementText != null && !elementText.isEmpty()) { return true; + } IConfigurationElement[] children = element.getChildren(extensionName); if (children.length == 1) { - if (children[0].getAttribute(IWorkbenchRegistryConstants.ATT_CLASS) != null) + if (children[0].getAttribute(IWorkbenchRegistryConstants.ATT_CLASS) != null) { return true; + } } return false; } @@ -345,8 +348,9 @@ public static boolean hasExecutableExtension(IConfigurationElement element, Stri public static boolean isBundleLoadedForExecutableExtension(IConfigurationElement element, String extensionName) { Bundle bundle = getBundleForExecutableExtension(element, extensionName); - if (bundle == null) + if (bundle == null) { return true; + } return bundle.getState() == Bundle.ACTIVE; } @@ -375,39 +379,44 @@ public static Bundle getBundleForExecutableExtension(IConfigurationElement eleme String contributorName = null; int i; - if (extensionName != null) + if (extensionName != null) { prop = element.getAttribute(extensionName); - else { + } else { // property not specified, try as element value prop = element.getValue(); if (prop != null) { prop = prop.trim(); - if (prop.isEmpty()) + if (prop.isEmpty()) { prop = null; + } } } if (prop == null) { // property not defined, try as a child element IConfigurationElement[] exec = element.getChildren(extensionName); - if (exec.length != 0) + if (exec.length != 0) { contributorName = exec[0].getAttribute("plugin"); //$NON-NLS-1$ + } } else { // simple property or element value, parse it into its components i = prop.indexOf(':'); - if (i != -1) + if (i != -1) { executable = prop.substring(0, i).trim(); - else + } else { executable = prop; + } i = executable.indexOf('/'); - if (i != -1) + if (i != -1) { contributorName = executable.substring(0, i).trim(); + } } - if (contributorName == null) + if (contributorName == null) { contributorName = element.getContributor().getName(); + } return Platform.getBundle(contributorName); } @@ -662,8 +671,7 @@ public static IStatus newError(String message, Throwable t) { // If this was a CoreException, keep the original plugin ID and error // code - if (t instanceof CoreException) { - CoreException ce = (CoreException) t; + if (t instanceof CoreException ce) { pluginId = ce.getStatus().getPlugin(); errorCode = ce.getStatus().getCode(); } @@ -764,8 +772,9 @@ public void start(BundleContext context) throws Exception { // of the ui bundle. Using the bundle activator class here because it is a // class that needs to be loaded anyway so it should not cause extra classes // to be loaded.s - if (uiBundle != null) + if (uiBundle != null) { uiBundle.start(Bundle.START_TRANSIENT); + } } catch (BundleException e) { WorkbenchPlugin.log("Unable to load UI activator", e); //$NON-NLS-1$ } @@ -867,8 +876,9 @@ private int getDefaultOrientation() { private Boolean isBidiMessageText() { // Check if the user installed the NLS packs for bidi String message = WorkbenchMessages.Startup_Loading_Workbench; - if (message == null) + if (message == null) { return null; + } try { // use qualified class name to avoid import statement @@ -899,18 +909,21 @@ private int checkCommandLineLocale() { // Check if the user property is set. If not, do not rely on the VM. if (System.getProperty(NL_USER_PROPERTY) == null) { Boolean needRTL = isBidiMessageText(); - if (needRTL != null && needRTL.booleanValue()) + if (needRTL != null && needRTL.booleanValue()) { return SWT.RIGHT_TO_LEFT; + } } else { String lang = Locale.getDefault().getLanguage(); boolean bidiLangauage = "iw".equals(lang) || "he".equals(lang) || "ar".equals(lang) || //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ "fa".equals(lang) || "ur".equals(lang); //$NON-NLS-1$ //$NON-NLS-2$ if (bidiLangauage) { Boolean needRTL = isBidiMessageText(); - if (needRTL == null) + if (needRTL == null) { return SWT.RIGHT_TO_LEFT; - if (needRTL.booleanValue()) + } + if (needRTL.booleanValue()) { return SWT.RIGHT_TO_LEFT; + } } } return SWT.NONE; @@ -1210,8 +1223,9 @@ public static Shell getSplashShell(Display display) public static void unsetSplashShell(Display display) { Shell splashShell = (Shell) display.getData(DATA_SPLASH_SHELL); if (splashShell != null) { - if (!splashShell.isDisposed()) + if (!splashShell.isDisposed()) { splashShell.dispose(); + } display.setData(DATA_SPLASH_SHELL, null); } @@ -1389,8 +1403,9 @@ public Object compute(IEclipseContext context, String contextKey) { * Return the debug options service, if available. */ public DebugOptions getDebugOptions() { - if (bundleContext == null) + if (bundleContext == null) { return null; + } if (debugTracker == null) { debugTracker = new ServiceTracker(bundleContext, DebugOptions.class.getName(), null); debugTracker.open(); @@ -1412,8 +1427,9 @@ public DebugOptions getDebugOptions() { * @return TestableObject provided via service or null */ public TestableObject getTestableObject() { - if (bundleContext == null) + if (bundleContext == null) { return null; + } if (testableTracker == null) { testableTracker = new ServiceTracker(bundleContext, TestableObject.class.getName(), null); testableTracker.open(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchWindow.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchWindow.java index 48b0a4a8834..3a87c44d459 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchWindow.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchWindow.java @@ -259,11 +259,11 @@ public class WorkbenchWindow implements IWorkbenchWindow { private MMenu mainMenu; - private PageListenerList pageListeners = new PageListenerList(); + private final PageListenerList pageListeners = new PageListenerList(); - private PerspectiveListenerList perspectiveListeners = new PerspectiveListenerList(); + private final PerspectiveListenerList perspectiveListeners = new PerspectiveListenerList(); - private PartService partService = new WWinPartService(); + private final PartService partService = new WWinPartService(); private WWinActionBars actionBars; @@ -275,9 +275,9 @@ public class WorkbenchWindow implements IWorkbenchWindow { ProgressRegion progressRegion = null; - private List workbenchTrimElements = new ArrayList<>(); + private final List workbenchTrimElements = new ArrayList<>(); - private Map iceMap = new HashMap<>(); + private final Map iceMap = new HashMap<>(); public IConfigurationElement getICEFor(MToolControl mtc) { return iceMap.get(mtc); @@ -311,13 +311,13 @@ public IConfigurationElement getICEFor(MToolControl mtc) { * * @since 3.3 */ - private ListenerList genericPropertyListeners = new ListenerList<>(); + private final ListenerList genericPropertyListeners = new ListenerList<>(); - private IAdaptable input; + private final IAdaptable input; private IPerspectiveDescriptor perspective; - private EventHandler windowWidgetHandler = event -> { + private final EventHandler windowWidgetHandler = event -> { if (event.getProperty(UIEvents.EventTags.ELEMENT) == model && event.getProperty(UIEvents.EventTags.NEW_VALUE) == null) { // HandledContributionItem.toolItemUpdater.removeWindowRunnable(menuUpdater); @@ -710,9 +710,8 @@ private void removeSaveOnCloseNotNeededSplitEditorParts(List parts) { private boolean isSaveOnCloseNotNeededSplitEditorPart(MPart part) { boolean notNeeded = false; - if (part instanceof MCompositePart + if (part instanceof MCompositePart compPart && SplitHost.SPLIT_HOST_CONTRIBUTOR_URI.equals(part.getContributionURI())) { - MCompositePart compPart = (MCompositePart) part; List elements = modelService.findElements(compPart, null, MPart.class); if (elements != null && elements.size() > 1) { elements.remove(0); @@ -1147,10 +1146,9 @@ private static boolean hidesQuickAccessPerDefault() { @Optional private void hideQuickAccess(@UIEventTopic(UIEvents.ApplicationElement.TOPIC_TAGS) Event event) { Object origin = event.getProperty(UIEvents.EventTags.ELEMENT); - if (!(origin instanceof MToolControl)) { + if (!(origin instanceof MToolControl control)) { return; } - MToolControl control = (MToolControl) origin; if (!QUICK_ACCESS_ID.equals(control.getElementId())) { return; } @@ -1186,8 +1184,9 @@ private void quickAccessDefaultVisibilityChanged() { * @param element the element to move */ private void moveControl(MElementContainer elementContainer, MUIElement element) { - if (element == null || elementContainer == null) + if (element == null || elementContainer == null) { return; + } PositionInfo positionInfo = findMovePositionInfo(element); @@ -1253,8 +1252,9 @@ private void moveControl(MElementContainer elementContainer, MUIElem * element wasn't found */ private int indexOfElementWithID(List elements, String id) { - if (elements == null || id == null) + if (elements == null || id == null) { return -1; + } int index = 0; for (MUIElement element : elements) { @@ -1332,8 +1332,9 @@ private void populateTrimContributions(MTrimBar bottomTrim) { } } - if (items.isEmpty()) + if (items.isEmpty()) { return; + } // Iterate over the items until they've all been placed or until // an iteration doesn't place anything @@ -1363,8 +1364,9 @@ private void populateTrimContributions(MTrimBar bottomTrim) { if (orders.length > 0) { boolean isBefore = "before".equals(orders[0].getAttribute("position")); //$NON-NLS-1$//$NON-NLS-2$ String relTo = orders[0].getAttribute("relativeTo"); //$NON-NLS-1$ - if ("status".equals(relTo)) //$NON-NLS-1$ + if ("status".equals(relTo)) { //$NON-NLS-1$ relTo = STATUS_LINE_ID; + } createdTrim = addTrimElement(bottomTrim, item, id, isBefore, relTo, classSpec); } @@ -1395,11 +1397,13 @@ private MToolControl addTrimElement(MTrimBar bottomTrim, IConfigurationElement i int insertIndex = bottomTrim.getChildren().size(); if (relTo != null) { MUIElement foundRel = modelService.find(relTo, bottomTrim); - if (foundRel == null) + if (foundRel == null) { return null; + } insertIndex = bottomTrim.getChildren().indexOf(foundRel); - if (!isBefore) + if (!isBefore) { insertIndex++; + } } MToolControl newTrimElement = modelService.createModelElement(MToolControl.class); @@ -1502,7 +1506,7 @@ protected int perspectiveBarStyle() { * ActionHandler. This map is never null, and is never * empty as long as at least one global action has been registered. */ - private Map globalActionHandlersByCommandId = new HashMap<>(); + private final Map globalActionHandlersByCommandId = new HashMap<>(); /** * The list of handler submissions submitted to the workbench command support. @@ -1537,9 +1541,8 @@ void registerGlobalAction(IAction globalAction) { if (commandId != null) { final Object value = globalActionHandlersByCommandId.remove(commandId); - if (value instanceof ActionHandler) { + if (value instanceof final ActionHandler handler) { // This handler is about to get clobbered, so dispose it. - final ActionHandler handler = (ActionHandler) value; handler.dispose(); } @@ -1970,8 +1973,9 @@ private void hideNonRestorableViews() { List sharedPartsToRemove = new ArrayList<>(); List phList = modelService.findElements(model, null, MPlaceholder.class, null); for (MPlaceholder ph : phList) { - if (!(ph.getRef() instanceof MPart)) + if (!(ph.getRef() instanceof MPart)) { continue; + } String partId = ph.getElementId(); @@ -1985,8 +1989,9 @@ private void hideNonRestorableViews() { MElementContainer phParent = ph.getParent(); if (colonIndex != -1) { // if it's a multi-instance part remove it (and its MPart) - if (!sharedPartsToRemove.contains(ph.getRef())) + if (!sharedPartsToRemove.contains(ph.getRef())) { sharedPartsToRemove.add((MPart) ph.getRef()); + } ph.getParent().getChildren().remove(ph); } else if (ph.isToBeRendered()) { // just hide it (so we remember where to open it again @@ -1996,8 +2001,9 @@ private void hideNonRestorableViews() { // We need to do our own cleanup here... int vc = modelService.countRenderableChildren(phParent); if (vc == 0) { - if (!isLastEditorStack(phParent)) + if (!isLastEditorStack(phParent)) { phParent.setToBeRendered(false); + } } } } @@ -2297,8 +2303,9 @@ public void run(final boolean fork, boolean cancelable, final IRunnableWithProgr enableMainMenu = true; } - if (keyFilterEnabled) + if (keyFilterEnabled) { bs.setKeyFilterEnabled(false); + } // disable all other shells for (Shell childShell : display.getShells()) { @@ -2319,8 +2326,9 @@ public void run(final boolean fork, boolean cancelable, final IRunnableWithProgr MUIElement statusLine = modelService.find(STATUS_LINE_ID, model); Object slCtrl = statusLine != null ? statusLine.getWidget() : null; for (Control bottomCtrl : tpl.bottom.getChildren()) { - if (bottomCtrl != slCtrl) + if (bottomCtrl != slCtrl) { disableControl(bottomCtrl, toEnable); + } } } @@ -2356,13 +2364,15 @@ public void run(final boolean fork, boolean cancelable, final IRunnableWithProgr mainMenu.setEnabled(true); } - if (keyFilterEnabled) + if (keyFilterEnabled) { bs.setKeyFilterEnabled(true); + } // Re-enable any disabled controls for (Control ctrl : toEnable) { - if (!ctrl.isDisposed() && !ctrl.isEnabled()) + if (!ctrl.isDisposed() && !ctrl.isEnabled()) { ctrl.setEnabled(true); + } } MPart activePart = partService.getActivePart(); @@ -2397,7 +2407,7 @@ public void setActivePage(final IWorkbenchPage in) { } } - private Set menuRestrictions = new HashSet<>(); + private final Set menuRestrictions = new HashSet<>(); private Boolean valueOf(boolean result) { return result ? Boolean.TRUE : Boolean.FALSE; @@ -2572,7 +2582,7 @@ public void updateActionSets() { private ListenerList actionSetListeners = null; - private ListenerList backgroundSaveListeners = new ListenerList<>(ListenerList.IDENTITY); + private final ListenerList backgroundSaveListeners = new ListenerList<>(ListenerList.IDENTITY); private SelectionService selectionService; @@ -2995,7 +3005,7 @@ public StatusLineManager getStatusLineManager() { return statusLineManager; } - private CoolBarManager2 oldCBM = new CoolBarManager2(); + private final CoolBarManager2 oldCBM = new CoolBarManager2(); private CoolBarToTrimManager coolbarToTrim; public ICoolBarManager getCoolBarManager2() { @@ -3014,7 +3024,7 @@ public CoolBarManager getCoolBarManager() { static class ToolbarOverrides implements IContributionManagerOverrides { - private WorkbenchPage page; + private final WorkbenchPage page; ToolbarOverrides(WorkbenchPage page) { this.page = page; @@ -3042,17 +3052,20 @@ public String getText(IContributionItem item) { @Override public Boolean getVisible(IContributionItem item) { - if (page == null) + if (page == null) { return null; + } MPerspective curPersp = page.getCurrentPerspective(); - if (curPersp == null) + if (curPersp == null) { return null; + } // Find the command ID String id = CustomizePerspectiveDialog.getIDFromIContributionItem(item); - if (id == null) + if (id == null) { return null; + } String hiddenToolItems = page.getHiddenItems(); if (hiddenToolItems.contains(ModeledPageLayout.HIDDEN_TOOLBAR_PREFIX + id + ",")) { //$NON-NLS-1$ @@ -3076,7 +3089,7 @@ public IMenuManager getMenuBarManager() { static class MenuOverrides implements IContributionManagerOverrides { - private WorkbenchPage page; + private final WorkbenchPage page; MenuOverrides(WorkbenchPage page) { this.page = page; @@ -3104,17 +3117,20 @@ public String getText(IContributionItem item) { @Override public Boolean getVisible(IContributionItem item) { - if (page == null) + if (page == null) { return null; + } MPerspective curPersp = page.getCurrentPerspective(); - if (curPersp == null) + if (curPersp == null) { return null; + } // Find the command ID String id = CustomizePerspectiveDialog.getIDFromIContributionItem(item); - if (id == null) + if (id == null) { return null; + } String hiddenToolItems = page.getHiddenItems(); if (hiddenToolItems.contains(ModeledPageLayout.HIDDEN_MENU_PREFIX + id + ",")) { //$NON-NLS-1$ diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchWindowConfigurer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchWindowConfigurer.java index d33779a41c8..25b9aa9f613 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchWindowConfigurer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchWindowConfigurer.java @@ -60,7 +60,7 @@ public final class WorkbenchWindowConfigurer implements IWorkbenchWindowConfigur /** * The workbench window associated with this configurer. */ - private WorkbenchWindow window; + private final WorkbenchWindow window; /** * The shell style bits to use when the window's shell is being created. @@ -103,12 +103,12 @@ public final class WorkbenchWindowConfigurer implements IWorkbenchWindowConfigur * * @see #setData */ - private Map extraData = new HashMap(1); + private final Map extraData = new HashMap(1); /** * Holds the list drag and drop Transfer for the editor area */ - private ArrayList transferTypes = new ArrayList(3); + private final ArrayList transferTypes = new ArrayList(3); /** * The DropTargetListener implementation for handling a drop into diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbookEditorsHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbookEditorsHandler.java index 8164d4ecffb..a16e7074b8f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbookEditorsHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbookEditorsHandler.java @@ -359,8 +359,7 @@ protected void setLabelProvider(final TableViewerColumn tableViewerColumn) { @Override public void update(ViewerCell cell) { Object element = cell.getElement(); - if (element instanceof WorkbenchPartReference) { - WorkbenchPartReference ref = (WorkbenchPartReference) element; + if (element instanceof WorkbenchPartReference ref) { String text = editorReferenceColumnLabelTexts.get(ref); cell.setText(text); cell.setImage(ref.getTitleImage()); @@ -381,8 +380,7 @@ public void update(ViewerCell cell) { @Override public String getToolTipText(Object element) { - if (element instanceof WorkbenchPartReference) { - WorkbenchPartReference ref = (WorkbenchPartReference) element; + if (element instanceof WorkbenchPartReference ref) { return ref.getTitleToolTip(); } return super.getToolTipText(element); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSet.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSet.java index 26c003868e1..e3fb1684fd4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSet.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSet.java @@ -91,8 +91,7 @@ public boolean equals(Object object) { if (this == object) { return true; } - if (object instanceof WorkingSet) { - WorkingSet workingSet = (WorkingSet) object; + if (object instanceof WorkingSet workingSet) { return Objects.equals(workingSet.getName(), getName()) && Objects.equals(workingSet.getId(), getId()) && Objects.equals(workingSet.getElementsArray(), getElementsArray()); @@ -273,10 +272,12 @@ public boolean isAggregateWorkingSet() { private WorkingSetDescriptor getDescriptor(String defaultId) { WorkingSetRegistry registry = WorkbenchPlugin.getDefault().getWorkingSetRegistry(); String id = getId(); - if (id == null) + if (id == null) { id = defaultId; - if (id == null) + } + if (id == null) { return null; + } return registry.getWorkingSetDescriptor(id); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSetComparator.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSetComparator.java index 6af2b33ab2e..8eeda0bea1b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSetComparator.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSetComparator.java @@ -33,7 +33,7 @@ public static WorkingSetComparator getInstance() { return INSTANCES.get(); } - private Collator fCollator = Collator.getInstance(); + private final Collator fCollator = Collator.getInstance(); /** * Implements Comparator. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSetMenuContributionItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSetMenuContributionItem.java index e4a39ed0721..756c72cf58e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSetMenuContributionItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkingSetMenuContributionItem.java @@ -36,11 +36,11 @@ public class WorkingSetMenuContributionItem extends ContributionItem { private Image image; - private int id; + private final int id; - private IWorkingSet workingSet; + private final IWorkingSet workingSet; - private WorkingSetFilterActionGroup actionGroup; + private final WorkingSetFilterActionGroup actionGroup; /** * Returns the id of this menu contribution item @@ -87,8 +87,9 @@ public void fill(Menu menu, int index) { if (imageDescriptor != null) { image = imageDescriptor.createImage(); mi.addDisposeListener(e -> { - if (image != null && !image.isDisposed()) + if (image != null && !image.isDisposed()) { image.dispose(); + } }); } } @@ -110,8 +111,9 @@ public boolean isDynamic() { */ @Override public void dispose() { - if (image != null && !image.isDisposed()) + if (image != null && !image.isDisposed()) { image.dispose(); + } image = null; super.dispose(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutBundleData.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutBundleData.java index 136dfd6807d..22daa84fc7f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutBundleData.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutBundleData.java @@ -32,9 +32,9 @@ */ public class AboutBundleData extends AboutData { - private Bundle bundle; + private final Bundle bundle; - private ExtendedSigningInfo info; + private final ExtendedSigningInfo info; private boolean isSignedDetermined = false; @@ -103,8 +103,9 @@ public boolean isSignedDetermined() { } public boolean isSigned() throws IllegalStateException { - if (isSignedDetermined) + if (isSignedDetermined) { return isSigned; + } SignedContent signedContent = getSignedContent(); isSigned = signedContent != null && signedContent.isSigned(); if (!isSigned && info != null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutBundleGroupData.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutBundleGroupData.java index 4d951b7b5a2..32b88701c45 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutBundleGroupData.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutBundleGroupData.java @@ -28,7 +28,7 @@ * @since 3.0 */ public class AboutBundleGroupData extends AboutData { - private IBundleGroup bundleGroup; + private final IBundleGroup bundleGroup; private URL licenseUrl; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutData.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutData.java index 4a2bd3ff223..fed86fbd8e9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutData.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutData.java @@ -31,13 +31,13 @@ * @since 3.0 */ public abstract class AboutData { - private String providerName; + private final String providerName; - private String name; + private final String name; - private String version; + private final String version; - private String id; + private final String id; private String versionedId = null; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutFeaturesButtonManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutFeaturesButtonManager.java index c1ea5db41e3..13ec779f3bd 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutFeaturesButtonManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutFeaturesButtonManager.java @@ -24,7 +24,7 @@ * image identity. */ public class AboutFeaturesButtonManager { - private Map> providerMap = new HashMap<>(); + private final Map> providerMap = new HashMap<>(); private static class Key { public String providerName; @@ -41,10 +41,9 @@ public Key(String providerName, Long crc) { @Override public boolean equals(Object o) { - if (!(o instanceof Key)) { + if (!(o instanceof Key other)) { return false; } - Key other = (Key) o; if (!providerName.equals(other.providerName)) { return false; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutFeaturesPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutFeaturesPage.java index 6eef1f36191..be46bcad5a0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutFeaturesPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutFeaturesPage.java @@ -115,11 +115,11 @@ public Image getColumnImage(Object element, int columnIndex) { private Composite infoArea; - private Map cachedImages = new HashMap<>(); + private final Map cachedImages = new HashMap<>(); private AboutBundleGroupData[] bundleGroupInfos; - private String columnTitles[] = { WorkbenchMessages.AboutFeaturesDialog_provider, + private final String columnTitles[] = { WorkbenchMessages.AboutFeaturesDialog_provider, WorkbenchMessages.AboutFeaturesDialog_featureName, WorkbenchMessages.AboutFeaturesDialog_version, WorkbenchMessages.AboutFeaturesDialog_featureId, }; @@ -289,8 +289,9 @@ protected void createTable(Composite parent) { table.addSelectionListener(widgetSelectedAdapter(e -> { // If there is no item, nothing we can do. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=266177 - if (e.item == null) + if (e.item == null) { return; + } AboutBundleGroupData info = (AboutBundleGroupData) e.item.getData(); updateInfoArea(info); updateButtons(info); @@ -492,8 +493,9 @@ private static String[] createRow(AboutBundleGroupData info) { } protected Collection getSelectionValue() { - if (table == null || table.isDisposed()) + if (table == null || table.isDisposed()) { return null; + } TableItem[] items = table.getSelection(); if (items.length <= 0) { return null; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutItem.java index ebe913b612f..7f72c64bbab 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutItem.java @@ -17,11 +17,11 @@ * Holds the information for text appearing in the about dialog */ public class AboutItem { - private String text; + private final String text; - private int[][] linkRanges; + private final int[][] linkRanges; - private String[] hrefs; + private final String[] hrefs; /** * Creates a new about item diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutPluginsPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutPluginsPage.java index d733ee2473a..0036f0a917a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutPluginsPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutPluginsPage.java @@ -91,18 +91,18 @@ public class BundleTableLabelProvider extends LabelProvider implements ITableLab /** * Queue containing bundle signing info to be resolved. */ - private LinkedList resolveQueue = new LinkedList<>(); + private final LinkedList resolveQueue = new LinkedList<>(); /** * Queue containing bundle data that's been resolve and needs updating. */ - private List updateQueue = new ArrayList<>(); + private final List updateQueue = new ArrayList<>(); /* * this job will attempt to discover the signing state of a given bundle and * then send it along to the update job */ - private Job resolveJob = new Job(AboutPluginsPage.class.getName()) { + private final Job resolveJob = new Job(AboutPluginsPage.class.getName()) { { setSystem(true); setPriority(Job.SHORT); @@ -112,18 +112,21 @@ public class BundleTableLabelProvider extends LabelProvider implements ITableLab protected IStatus run(IProgressMonitor monitor) { while (true) { // If the UI has not been created, nothing to do. - if (vendorInfo == null) + if (vendorInfo == null) { return Status.OK_STATUS; + } // If the UI has been disposed since we were asked to // render, nothing to do. Table table = vendorInfo.getTable(); // the table has been disposed since we were asked to render - if (table == null || table.isDisposed()) + if (table == null || table.isDisposed()) { return Status.OK_STATUS; + } AboutBundleData data = null; synchronized (resolveQueue) { - if (resolveQueue.isEmpty()) + if (resolveQueue.isEmpty()) { return Status.OK_STATUS; + } data = resolveQueue.removeFirst(); } try { @@ -147,7 +150,7 @@ protected IStatus run(IProgressMonitor monitor) { * this job is responsible for feeding label change events into the viewer as * they become available from the resolve job */ - private Job updateJob = new WorkbenchJob(PlatformUI.getWorkbench().getDisplay(), + private final Job updateJob = new WorkbenchJob(PlatformUI.getWorkbench().getDisplay(), AboutPluginsPage.class.getName()) { { setSystem(true); @@ -159,12 +162,14 @@ public IStatus runInUIThread(IProgressMonitor monitor) { while (true) { Control page = getControl(); // the page has gone down since we were asked to render - if (page == null || page.isDisposed()) + if (page == null || page.isDisposed()) { return Status.OK_STATUS; + } AboutBundleData[] data = null; synchronized (updateQueue) { - if (updateQueue.isEmpty()) + if (updateQueue.isEmpty()) { return Status.OK_STATUS; + } data = updateQueue.toArray(new AboutBundleData[updateQueue.size()]); updateQueue.clear(); @@ -178,8 +183,7 @@ public IStatus runInUIThread(IProgressMonitor monitor) { @Override public Image getColumnImage(Object element, int columnIndex) { if (columnIndex == 0) { - if (element instanceof AboutBundleData) { - final AboutBundleData data = (AboutBundleData) element; + if (element instanceof final AboutBundleData data) { if (data.isSignedDetermined()) { return WorkbenchImages.getImage(data.isSigned() ? IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_YES : IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_NO); @@ -200,8 +204,7 @@ public void resolve(AboutBundleData data) { @Override public String getColumnText(Object element, int columnIndex) { - if (element instanceof AboutBundleData) { - AboutBundleData data = (AboutBundleData) element; + if (element instanceof AboutBundleData data) { switch (columnIndex) { case 0: if (!data.isSignedDetermined()) { @@ -254,7 +257,7 @@ public String getColumnText(Object element, int columnIndex) { private String helpContextId = IWorkbenchHelpContextIds.ABOUT_PLUGINS_DIALOG; - private String columnTitles[] = { WorkbenchMessages.AboutPluginsDialog_signed, + private final String columnTitles[] = { WorkbenchMessages.AboutPluginsDialog_signed, WorkbenchMessages.AboutPluginsDialog_provider, WorkbenchMessages.AboutPluginsDialog_pluginName, WorkbenchMessages.AboutPluginsDialog_version, WorkbenchMessages.AboutPluginsDialog_pluginId, @@ -283,7 +286,7 @@ protected void handleSigningInfoPressed() { signingArea.setData(bundleInfo); signingArea.createContents(sashForm); - sashForm.setWeights(new int[] { 100 - SIGNING_AREA_PERCENTAGE, SIGNING_AREA_PERCENTAGE }); + sashForm.setWeights(100 - SIGNING_AREA_PERCENTAGE, SIGNING_AREA_PERCENTAGE); signingInfo.setText(WorkbenchMessages.AboutPluginsDialog_signingInfo_hide); } else { @@ -291,7 +294,7 @@ protected void handleSigningInfoPressed() { signingInfo.setText(WorkbenchMessages.AboutPluginsDialog_signingInfo_show); signingArea.dispose(); signingArea = null; - sashForm.setWeights(new int[] { 100 }); + sashForm.setWeights(100); } } @@ -559,8 +562,9 @@ protected void handleMoreInfoPressed() { return; } - if (vendorInfo.getSelection().isEmpty()) + if (vendorInfo.getSelection().isEmpty()) { return; + } AboutBundleData bundleInfo = (AboutBundleData) vendorInfo.getStructuredSelection().getFirstElement(); @@ -585,20 +589,17 @@ class TableComparator extends ViewerComparator { @Override public int compare(Viewer viewer, Object e1, Object e2) { - if (sortColumn == 0 && e1 instanceof AboutBundleData && e2 instanceof AboutBundleData) { - AboutBundleData d1 = (AboutBundleData) e1; - AboutBundleData d2 = (AboutBundleData) e2; + if (sortColumn == 0 && e1 instanceof AboutBundleData d1 && e2 instanceof AboutBundleData d2) { int diff = Long.compare(getSignedSortValue(d1), getSignedSortValue(d2)); // If values are different, or there is no secondary column defined, // we are done - if (diff != 0 || lastSortColumn == 0) + if (diff != 0 || lastSortColumn == 0) { return ascending ? diff : -diff; + } // try a secondary sort - if (viewer instanceof TableViewer) { - TableViewer tableViewer = (TableViewer) viewer; + if (viewer instanceof TableViewer tableViewer) { IBaseLabelProvider baseLabel = tableViewer.getLabelProvider(); - if (baseLabel instanceof ITableLabelProvider) { - ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel; + if (baseLabel instanceof ITableLabelProvider tableProvider) { String e1p = tableProvider.getColumnText(e1, lastSortColumn); String e2p = tableProvider.getColumnText(e2, lastSortColumn); int result = getComparator().compare(e1p, e2p); @@ -608,11 +609,9 @@ public int compare(Viewer viewer, Object e1, Object e2) { // we couldn't determine a secondary sort, call it equal return 0; } - if (viewer instanceof TableViewer) { - TableViewer tableViewer = (TableViewer) viewer; + if (viewer instanceof TableViewer tableViewer) { IBaseLabelProvider baseLabel = tableViewer.getLabelProvider(); - if (baseLabel instanceof ITableLabelProvider) { - ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel; + if (baseLabel instanceof ITableLabelProvider tableProvider) { String e1p = tableProvider.getColumnText(e1, sortColumn); String e2p = tableProvider.getColumnText(e2, sortColumn); int result = getComparator().compare(e1p, e2p); @@ -624,9 +623,7 @@ public int compare(Viewer viewer, Object e1, Object e2) { result = getComparator().compare(e1p, e2p); return lastAscending ? result : (-1) * result; } // secondary sort is by column 0 - if (e1 instanceof AboutBundleData && e2 instanceof AboutBundleData) { - AboutBundleData d1 = (AboutBundleData) e1; - AboutBundleData d2 = (AboutBundleData) e2; + if (e1 instanceof AboutBundleData d1 && e2 instanceof AboutBundleData d2) { int diff = Long.compare(getSignedSortValue(d1), getSignedSortValue(d2)); return lastAscending ? diff : -diff; } @@ -706,8 +703,7 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { return true; } - if (element instanceof AboutBundleData) { - AboutBundleData data = (AboutBundleData) element; + if (element instanceof AboutBundleData data) { return matcher.matchWords(data.getName()) || matcher.matchWords(data.getProviderName()) || matcher.matchWords(data.getId()); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutSystemPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutSystemPage.java index 449b0a5b6d4..aded4462336 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutSystemPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutSystemPage.java @@ -128,8 +128,9 @@ public void copyToClipboard() { try { clipboard = new Clipboard(text.getShell().getDisplay()); String contents = text.getSelectionText(); - if (contents.isEmpty()) + if (contents.isEmpty()) { contents = text.getText(); + } clipboard.setContents(new Object[] { contents }, new Transfer[] { TextTransfer.getInstance() }); } finally { if (clipboard != null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutTextManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutTextManager.java index 260607f3c12..fb2b93e9304 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutTextManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutTextManager.java @@ -56,16 +56,18 @@ public static AboutItem scan(String aboutText) { do { urlOffset--; ch = ' '; - if (urlOffset > -1) + if (urlOffset > -1) { ch = aboutText.charAt(urlOffset); + } startDoubleQuote = ch == '"'; } while (Character.isUnicodeIdentifierStart(ch)); urlOffset++; // Right to "://" StringTokenizer tokenizer = new StringTokenizer(aboutText.substring(urlSeparatorOffset + 3), " \t\n\r\f<>", false); //$NON-NLS-1$ - if (!tokenizer.hasMoreTokens()) + if (!tokenizer.hasMoreTokens()) { return null; + } int urlLength = tokenizer.nextToken().length() + 3 + urlSeparatorOffset - urlOffset; @@ -73,14 +75,16 @@ public static AboutItem scan(String aboutText) { int endOffset = -1; int nextDoubleQuote = aboutText.indexOf('"', urlOffset); int nextWhitespace = aboutText.indexOf(' ', urlOffset); - if (nextDoubleQuote != -1 && nextWhitespace != -1) + if (nextDoubleQuote != -1 && nextWhitespace != -1) { endOffset = Math.min(nextDoubleQuote, nextWhitespace); - else if (nextDoubleQuote != -1) + } else if (nextDoubleQuote != -1) { endOffset = nextDoubleQuote; - else if (nextWhitespace != -1) + } else if (nextWhitespace != -1) { endOffset = nextWhitespace; - if (endOffset != -1) + } + if (endOffset != -1) { urlLength = endOffset - urlOffset; + } } linkRanges.add(new int[] { urlOffset, urlLength }); @@ -92,7 +96,7 @@ else if (nextWhitespace != -1) links.toArray(new String[links.size()])); } - private StyledText styledText; + private final StyledText styledText; private boolean mouseDown = false; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutUtils.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutUtils.java index d14b064ce4f..b9ee563b947 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutUtils.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/AboutUtils.java @@ -68,16 +68,18 @@ public static AboutItem scan(String aboutText) { do { urlOffset--; ch = ' '; - if (urlOffset > -1) + if (urlOffset > -1) { ch = aboutText.charAt(urlOffset); + } startDoubleQuote = ch == '"'; } while (Character.isUnicodeIdentifierStart(ch)); urlOffset++; // Right to "://" StringTokenizer tokenizer = new StringTokenizer(aboutText.substring(urlSeparatorOffset + 3), " \t\n\r\f<>", false); //$NON-NLS-1$ - if (!tokenizer.hasMoreTokens()) + if (!tokenizer.hasMoreTokens()) { return null; + } int urlLength = tokenizer.nextToken().length() + 3 + urlSeparatorOffset - urlOffset; @@ -85,14 +87,16 @@ public static AboutItem scan(String aboutText) { int endOffset = -1; int nextDoubleQuote = aboutText.indexOf('"', urlOffset); int nextWhitespace = aboutText.indexOf(' ', urlOffset); - if (nextDoubleQuote != -1 && nextWhitespace != -1) + if (nextDoubleQuote != -1 && nextWhitespace != -1) { endOffset = Math.min(nextDoubleQuote, nextWhitespace); - else if (nextDoubleQuote != -1) + } else if (nextDoubleQuote != -1) { endOffset = nextDoubleQuote; - else if (nextWhitespace != -1) + } else if (nextWhitespace != -1) { endOffset = nextWhitespace; - if (endOffset != -1) + } + if (endOffset != -1) { urlLength = endOffset - urlOffset; + } } linkRanges.add(new int[] { urlOffset, urlLength }); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/BundleSigningInfo.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/BundleSigningInfo.java index 16df9f35c67..2cf05fbc70d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/BundleSigningInfo.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/BundleSigningInfo.java @@ -118,8 +118,9 @@ public Control createContents(Composite parent) { } private void startJobs() { - if (!isOpen()) + if (!isOpen()) { return; + } certificate.setText(WorkbenchMessages.BundleSigningTray_Working); date.setText(WorkbenchMessages.BundleSigningTray_Working); @@ -127,20 +128,23 @@ private void startJobs() { final Job signerJob = Job.create( NLS.bind(WorkbenchMessages.BundleSigningTray_Determine_Signer_For, myData.getId()), (IJobFunction) monitor -> { - if (myData != data) + if (myData != data) { return Status.OK_STATUS; + } SignedContent signedContent = myData.getSignedContent(); if (signedContent == null) { StatusManager.getManager().handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH, WorkbenchMessages.BundleSigningTray_Cant_Find_Service), StatusManager.LOG); return Status.OK_STATUS; } - if (myData != data) + if (myData != data) { return Status.OK_STATUS; + } SignerInfo[] signers = signedContent.getSignerInfos(); final String signerText, dateText, signingTypeText; - if (!isOpen() && BundleSigningInfo.this.data == myData) + if (!isOpen() && BundleSigningInfo.this.data == myData) { return Status.OK_STATUS; + } if (signers.length == 0) { AboutBundleData.ExtendedSigningInfo info = data.getInfo(); @@ -156,26 +160,28 @@ private void startJobs() { } } else { Properties[] certs = parseCerts(signers[0].getCertificateChain()); - if (certs.length == 0) + if (certs.length == 0) { signerText = WorkbenchMessages.BundleSigningTray_Unknown; - else { + } else { StringBuilder buffer = new StringBuilder(); for (Iterator> i = certs[0].entrySet().iterator(); i.hasNext();) { Entry entry = i.next(); buffer.append(entry.getKey()); buffer.append('='); buffer.append(entry.getValue()); - if (i.hasNext()) + if (i.hasNext()) { buffer.append('\n'); + } } signerText = buffer.toString(); } Date signDate = signedContent.getSigningTime(signers[0]); - if (signDate != null) + if (signDate != null) { dateText = DateFormat.getDateTimeInstance().format(signDate); - else + } else { dateText = WorkbenchMessages.BundleSigningTray_Unknown; + } signingTypeText = WorkbenchMessages.BundleSigningTray_X509Certificate; } @@ -183,8 +189,9 @@ private void startJobs() { // check to see if the tray is still visible // and if // we're still looking at the same item - if (!isOpen() && BundleSigningInfo.this.data != myData) + if (!isOpen() && BundleSigningInfo.this.data != myData) { return; + } certificate.setText(signerText); date.setText(dateText); signingType.setText(signingTypeText); @@ -208,8 +215,9 @@ private Properties[] parseCerts(Certificate[] chain) { continue; } Properties cert = parseCert(((X509Certificate) e).getSubjectX500Principal().getName()); - if (cert != null) + if (cert != null) { certs.add(cert); + } } return certs.toArray(new Properties[certs.size()]); @@ -225,11 +233,13 @@ private Properties parseCert(String certString) { String key = pair.substring(0, idx).trim(); String value = pair.substring(idx + 1).trim(); if (value.length() > 2) { - if (value.charAt(0) == '\"') + if (value.charAt(0) == '\"') { value = value.substring(1); + } - if (value.charAt(value.length() - 1) == '\"') + if (value.charAt(value.length() - 1) == '\"') { value = value.substring(0, value.length() - 1); + } } cert.setProperty(key, value); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/InstallationDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/InstallationDialog.java index 48a9fc2ce00..aed8326a75e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/InstallationDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/InstallationDialog.java @@ -60,7 +60,7 @@ public class InstallationDialog extends TrayDialog implements IInstallationPageContainer { class ButtonManager { - private Composite composite; + private final Composite composite; HashMap> buttonMap = new HashMap<>(); // page id->Collection of page // buttons @@ -74,8 +74,9 @@ public Composite getParent() { } public void update(String currentPageId) { - if (composite == null || composite.isDisposed()) + if (composite == null || composite.isDisposed()) { return; + } GC metricsGC = new GC(composite); FontMetrics metrics = metricsGC.getFontMetrics(); metricsGC.dispose(); @@ -86,9 +87,9 @@ public void update(String currentPageId) { Button closeButton = getButton(IDialogConstants.CLOSE_ID); for (Control control : children) { - if (closeButton == control) + if (closeButton == control) { closeButton.dispose(); - else { + } else { control.setVisible(false); setButtonLayoutData(metrics, control, false); } @@ -140,7 +141,7 @@ public void clear() { private CTabFolder folder; IServiceLocator serviceLocator; private ButtonManager buttonManager; - private Map pageToId = new HashMap<>(); + private final Map pageToId = new HashMap<>(); private Dialog modalParent; public InstallationDialog(Shell parentShell, IServiceLocator locator) { @@ -154,8 +155,9 @@ protected void configureShell(Shell newShell) { super.configureShell(newShell); String productName = ""; //$NON-NLS-1$ IProduct product = Platform.getProduct(); - if (product != null && product.getName() != null) + if (product != null && product.getName() != null) { productName = product.getName(); + } newShell.setText(NLS.bind(WorkbenchMessages.InstallationDialog_ShellTitle, productName)); } @@ -202,16 +204,18 @@ protected Control createContents(Composite parent) { if (folder.getItemCount() > 0) { if (lastSelectedTabId != null) { CTabItem[] items = folder.getItems(); - for (int i = 0; i < items.length; i++) + for (int i = 0; i < items.length; i++) { if (items[i].getData(ID).equals(lastSelectedTabId)) { folder.setSelection(i); tabSelected(items[i]); selected = true; break; } + } } - if (!selected) + if (!selected) { tabSelected(folder.getItem(0)); + } } // need to reapply the dialog font now that we've created new // tab items @@ -317,8 +321,9 @@ protected void releaseContributions() { @Override public void closeModalContainers() { close(); - if (modalParent != null) + if (modalParent != null) { modalParent.close(); + } } @Override diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/InstallationHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/InstallationHandler.java index 26b06bac7ea..31f36d54d60 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/InstallationHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/InstallationHandler.java @@ -24,8 +24,9 @@ public class InstallationHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) { IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); - if (workbenchWindow == null) + if (workbenchWindow == null) { workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + } InstallationDialog dialog = new InstallationDialog(HandlerUtil.getActiveShell(event), workbenchWindow); dialog.open(); return null; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/ProductInfoDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/ProductInfoDialog.java index 156d82fe462..cafc57a8bfd 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/ProductInfoDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/ProductInfoDialog.java @@ -79,8 +79,9 @@ protected void createButtonsForButtonBar(Composite parent) { protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(title); - if (helpContextId != null) + if (helpContextId != null) { PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, helpContextId); + } } @Override diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/ProductInfoPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/ProductInfoPage.java index 970c585dcf2..03e27d059a9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/ProductInfoPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/about/ProductInfoPage.java @@ -53,8 +53,9 @@ public abstract class ProductInfoPage extends InstallationPage implements IShell private String productName; protected IProduct getProduct() { - if (product == null) + if (product == null) { product = Platform.getProduct(); + } return product; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/ClearWorkingSetAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/ClearWorkingSetAction.java index c54f5c7c754..d94a6295ef6 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/ClearWorkingSetAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/ClearWorkingSetAction.java @@ -27,7 +27,7 @@ * @since 2.1 */ public class ClearWorkingSetAction extends Action { - private WorkingSetFilterActionGroup actionGroup; + private final WorkingSetFilterActionGroup actionGroup; /** * Creates a new instance of the receiver. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/EditWorkingSetAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/EditWorkingSetAction.java index 960e8abdb49..d18bba33613 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/EditWorkingSetAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/EditWorkingSetAction.java @@ -34,9 +34,9 @@ * @since 2.1 */ public class EditWorkingSetAction extends Action { - private Shell shell; + private final Shell shell; - private WorkingSetFilterActionGroup actionGroup; + private final WorkingSetFilterActionGroup actionGroup; /** * Creates a new instance of the receiver. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/HelpSearchContributionItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/HelpSearchContributionItem.java index 45a4361b080..8e7e7b202b3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/HelpSearchContributionItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/HelpSearchContributionItem.java @@ -37,11 +37,11 @@ public class HelpSearchContributionItem extends ControlContribution { private static final String ID = "org.eclipse.ui.helpSearch"; //$NON-NLS-1$ - private IWorkbenchWindow window; + private final IWorkbenchWindow window; private Combo combo; - private int MAX_ITEM_COUNT = 10; + private final int MAX_ITEM_COUNT = 10; /** * Creates the contribution item. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/ModifyWorkingSetDelegate.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/ModifyWorkingSetDelegate.java index 3b887e0bf52..fc187bb53f2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/ModifyWorkingSetDelegate.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/ModifyWorkingSetDelegate.java @@ -89,9 +89,9 @@ public void run() { private class ModifyAction extends Action { - private IWorkingSet set; + private final IWorkingSet set; - private IAdaptable[] selectedElements; + private final IAdaptable[] selectedElements; private ModifyAction(IWorkingSet set, IAdaptable[] selectedElements) { super(set.getLabel(), IAction.AS_CHECK_BOX); @@ -116,7 +116,7 @@ public void run() { } } - private QuickMenuCreator contextMenuCreator = new QuickMenuCreator() { + private final QuickMenuCreator contextMenuCreator = new QuickMenuCreator() { @Override protected void fillMenu(IMenuManager menu) { ModifyWorkingSetDelegate.this.fillMenu(menu); @@ -125,7 +125,7 @@ protected void fillMenu(IMenuManager menu) { private boolean add = true; - private IPropertyChangeListener listener = new IPropertyChangeListener() { + private final IPropertyChangeListener listener = new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { @@ -149,8 +149,9 @@ public void run(IAction action) { @Override public void runWithEvent(IAction action, Event event) { - if (event.type == SWT.KeyDown || event.type == SWT.KeyUp) + if (event.type == SWT.KeyDown || event.type == SWT.KeyUp) { run(action); + } } @Override @@ -297,8 +298,9 @@ public void selectionChanged(IAction actionProxy, ISelection selection) { } actionProxy.setEnabled(minimallyOkay); - } else + } else { actionProxy.setEnabled(false); + } } @Override diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/NewWizardShortcutAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/NewWizardShortcutAction.java index 44a44475410..fca60f435ba 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/NewWizardShortcutAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/NewWizardShortcutAction.java @@ -39,7 +39,7 @@ * Opens a specific new wizard. */ public class NewWizardShortcutAction extends Action implements IPluginContribution { - private IWizardDescriptor wizardElement; + private final IWizardDescriptor wizardElement; /** * The wizard dialog width @@ -51,7 +51,7 @@ public class NewWizardShortcutAction extends Action implements IPluginContributi */ private static final int SIZING_WIZARD_HEIGHT = 500; - private IWorkbenchWindow window; + private final IWorkbenchWindow window; /** * Create an instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/SelectWorkingSetAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/SelectWorkingSetAction.java index 4896a3bba18..a5be7be4ff4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/SelectWorkingSetAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/SelectWorkingSetAction.java @@ -33,9 +33,9 @@ * @since 2.1 */ public class SelectWorkingSetAction extends Action { - private Shell shell; + private final Shell shell; - private WorkingSetFilterActionGroup actionGroup; + private final WorkingSetFilterActionGroup actionGroup; /** * Creates a new instance of the receiver. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/SelectWorkingSetsAction.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/SelectWorkingSetsAction.java index 5761d9fb1ba..2dbd3b262c8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/SelectWorkingSetsAction.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/actions/SelectWorkingSetsAction.java @@ -51,7 +51,7 @@ public void run() { } private class ToggleWorkingSetAction extends Action { - private IWorkingSet set; + private final IWorkingSet set; ToggleWorkingSetAction(IWorkingSet set) { super(set.getLabel(), IAction.AS_CHECK_BOX); @@ -72,8 +72,9 @@ public void runWithEvent(Event event) { boolean modified = (event.stateMask & KeyLookupFactory.getDefault().formalModifierLookup(IKeyLookup.M1_NAME)) != 0; - if (modified) + if (modified) { newList.clear(); + } newList.add(set); } else { newList.remove(set); @@ -131,7 +132,7 @@ public void run(IAction action) { class ConfigureWindowWorkingSetsDialog extends SimpleWorkingSetSelectionDialog { - private IWorkbenchWindow window; + private final IWorkbenchWindow window; protected ConfigureWindowWorkingSetsDialog(IWorkbenchWindow window) { super(window.getShell(), null, window.getActivePage().getWorkingSets(), true); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Activity.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Activity.java index 844ddfd0d7d..213eff10ee5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Activity.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Activity.java @@ -51,7 +51,7 @@ final class Activity implements IActivity { private transient int hashCode = HASH_INITIAL; - private String id; + private final String id; private String name; @@ -120,11 +120,10 @@ public int compareTo(IActivity object) { @Override public boolean equals(Object object) { - if (!(object instanceof Activity)) { + if (!(object instanceof final Activity castedObject)) { return false; } - final Activity castedObject = (Activity) object; return Objects.equals(activityRequirementBindings, castedObject.activityRequirementBindings) && Objects.equals(activityPatternBindings, castedObject.activityPatternBindings) && defined == castedObject.defined && enabled == castedObject.enabled diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityDefinition.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityDefinition.java index 6c28a99b632..d1e7c05b083 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityDefinition.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityDefinition.java @@ -79,13 +79,13 @@ static Map> activityDefinitionsByName( private transient int hashCode = HASH_INITIAL; - private String id; + private final String id; - private String name; + private final String name; - private String sourceId; + private final String sourceId; - private String description; + private final String description; private transient String string; @@ -115,11 +115,10 @@ public int compareTo(ActivityDefinition object) { @Override public boolean equals(Object object) { - if (!(object instanceof ActivityDefinition)) { + if (!(object instanceof final ActivityDefinition castedObject)) { return false; } - final ActivityDefinition castedObject = (ActivityDefinition) object; return Objects.equals(id, castedObject.id) && Objects.equals(name, castedObject.name) && Objects.equals(sourceId, castedObject.sourceId); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityPatternBinding.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityPatternBinding.java index 9944f3a30df..1492eaabaf1 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityPatternBinding.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityPatternBinding.java @@ -24,7 +24,7 @@ public final class ActivityPatternBinding implements IActivityPatternBinding { private static final int HASH_INITIAL = ActivityPatternBinding.class.getName().hashCode(); - private String activityId; + private final String activityId; private transient int hashCode = HASH_INITIAL; @@ -32,7 +32,7 @@ public final class ActivityPatternBinding implements IActivityPatternBinding { private String patternString; - private boolean isEqualityPattern; + private final boolean isEqualityPattern; private transient String string; @@ -88,8 +88,9 @@ public int compareTo(IActivityPatternBinding object) { if (compareTo == 0) { compareTo = Util.compare(isEqualityPattern, castedObject.isEqualityPattern); - if (compareTo == 0) + if (compareTo == 0) { compareTo = Util.compare(getPattern().pattern(), castedObject.getPattern().pattern()); + } } return compareTo; @@ -97,11 +98,10 @@ public int compareTo(IActivityPatternBinding object) { @Override public boolean equals(Object object) { - if (!(object instanceof ActivityPatternBinding)) { + if (!(object instanceof final ActivityPatternBinding castedObject)) { return false; } - final ActivityPatternBinding castedObject = (ActivityPatternBinding) object; return Objects.equals(activityId, castedObject.activityId) && isEqualityPattern == castedObject.isEqualityPattern && Objects.equals(getPattern(), castedObject.getPattern()); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityPatternBindingDefinition.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityPatternBindingDefinition.java index c1beb45fd69..80eb96e729f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityPatternBindingDefinition.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityPatternBindingDefinition.java @@ -55,13 +55,13 @@ static Map> activityPattern return map; } - private String activityId; + private final String activityId; private transient int hashCode = HASH_INITIAL; - private String pattern; + private final String pattern; - private String sourceId; + private final String sourceId; private transient String string; @@ -69,7 +69,7 @@ static Map> activityPattern * If the string is taken "as is", without interpreting it as a regular * expression. */ - private boolean isEqualityPattern; + private final boolean isEqualityPattern; public ActivityPatternBindingDefinition(String activityId, String pattern, String sourceId) { this(activityId, pattern, sourceId, false); @@ -93,8 +93,9 @@ public int compareTo(Object object) { if (compareTo == 0) { compareTo = Util.compare(isEqualityPattern, castedObject.isEqualityPattern); - if (compareTo == 0) + if (compareTo == 0) { compareTo = Util.compare(sourceId, castedObject.sourceId); + } } } @@ -103,11 +104,10 @@ public int compareTo(Object object) { @Override public boolean equals(Object object) { - if (!(object instanceof ActivityPatternBindingDefinition)) { + if (!(object instanceof final ActivityPatternBindingDefinition castedObject)) { return false; } - final ActivityPatternBindingDefinition castedObject = (ActivityPatternBindingDefinition) object; return Objects.equals(activityId, castedObject.activityId) && Objects.equals(pattern, castedObject.pattern) && isEqualityPattern == castedObject.isEqualityPattern && Objects.equals(sourceId, castedObject.sourceId); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRegistryEvent.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRegistryEvent.java index 59753996a5d..149545a8dae 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRegistryEvent.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRegistryEvent.java @@ -15,7 +15,7 @@ package org.eclipse.ui.internal.activities; final class ActivityRegistryEvent { - private IActivityRegistry activityRegistry; + private final IActivityRegistry activityRegistry; ActivityRegistryEvent(IActivityRegistry activityRegistry) { if (activityRegistry == null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRequirementBinding.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRequirementBinding.java index 526ba93eb19..c9fa34a1c39 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRequirementBinding.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRequirementBinding.java @@ -23,11 +23,11 @@ public final class ActivityRequirementBinding implements IActivityRequirementBin private static final int HASH_INITIAL = ActivityRequirementBinding.class.getName().hashCode(); - private String requiredActivityId; + private final String requiredActivityId; private transient int hashCode = HASH_INITIAL; - private String activityId; + private final String activityId; private transient String string; @@ -54,11 +54,10 @@ public int compareTo(IActivityRequirementBinding object) { @Override public boolean equals(Object object) { - if (!(object instanceof ActivityRequirementBinding)) { + if (!(object instanceof final ActivityRequirementBinding castedObject)) { return false; } - final ActivityRequirementBinding castedObject = (ActivityRequirementBinding) object; return Objects.equals(requiredActivityId, castedObject.requiredActivityId) && Objects.equals(activityId, castedObject.activityId); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRequirementBindingDefinition.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRequirementBindingDefinition.java index 7f4baea62af..1f17c0a469e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRequirementBindingDefinition.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ActivityRequirementBindingDefinition.java @@ -58,13 +58,13 @@ static Map> activityReq return map; } - private String requiredActivityId; + private final String requiredActivityId; private transient int hashCode = HASH_INITIAL; - private String activityId; + private final String activityId; - private String sourceId; + private final String sourceId; private transient String string; @@ -91,11 +91,10 @@ public int compareTo(Object object) { @Override public boolean equals(Object object) { - if (!(object instanceof ActivityRequirementBindingDefinition)) { + if (!(object instanceof final ActivityRequirementBindingDefinition castedObject)) { return false; } - final ActivityRequirementBindingDefinition castedObject = (ActivityRequirementBindingDefinition) object; return Objects.equals(requiredActivityId, castedObject.requiredActivityId) && Objects.equals(activityId, castedObject.activityId) && Objects.equals(sourceId, castedObject.sourceId); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Category.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Category.java index af3c4311b06..3d51056e505 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Category.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Category.java @@ -43,7 +43,7 @@ final class Category implements ICategory { private transient int hashCode = HASH_INITIAL; - private String id; + private final String id; private String name; @@ -98,11 +98,10 @@ public int compareTo(ICategory object) { @Override public boolean equals(Object object) { - if (!(object instanceof Category)) { + if (!(object instanceof final Category castedObject)) { return false; } - final Category castedObject = (Category) object; return Objects.equals(categoryActivityBindings, castedObject.categoryActivityBindings) && defined == castedObject.defined && Objects.equals(id, castedObject.id) && Objects.equals(name, castedObject.name); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryActivityBinding.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryActivityBinding.java index c401032def5..31c65c6ed6d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryActivityBinding.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryActivityBinding.java @@ -23,9 +23,9 @@ public final class CategoryActivityBinding implements ICategoryActivityBinding { private static final int HASH_INITIAL = CategoryActivityBinding.class.getName().hashCode(); - private String activityId; + private final String activityId; - private String categoryId; + private final String categoryId; private transient int hashCode = HASH_INITIAL; @@ -54,11 +54,10 @@ public int compareTo(ICategoryActivityBinding object) { @Override public boolean equals(Object object) { - if (!(object instanceof CategoryActivityBinding)) { + if (!(object instanceof final CategoryActivityBinding castedObject)) { return false; } - final CategoryActivityBinding castedObject = (CategoryActivityBinding) object; return Objects.equals(activityId, castedObject.activityId) && Objects.equals(categoryId, castedObject.categoryId); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryActivityBindingDefinition.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryActivityBindingDefinition.java index 5fe34aa222e..fc19224a823 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryActivityBindingDefinition.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryActivityBindingDefinition.java @@ -55,13 +55,13 @@ static Map> categoryActivi return map; } - private String activityId; + private final String activityId; - private String categoryId; + private final String categoryId; private transient int hashCode = HASH_INITIAL; - private String sourceId; + private final String sourceId; private transient String string; @@ -88,11 +88,10 @@ public int compareTo(Object object) { @Override public boolean equals(Object object) { - if (!(object instanceof CategoryActivityBindingDefinition)) { + if (!(object instanceof final CategoryActivityBindingDefinition castedObject)) { return false; } - final CategoryActivityBindingDefinition castedObject = (CategoryActivityBindingDefinition) object; return Objects.equals(activityId, castedObject.activityId) && Objects.equals(categoryId, castedObject.categoryId) && Objects.equals(sourceId, castedObject.sourceId); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryDefinition.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryDefinition.java index 56b20e1097c..81c19fd5d02 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryDefinition.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/CategoryDefinition.java @@ -78,15 +78,15 @@ static Map> categoryDefinitionsByName( private transient int hashCode = HASH_INITIAL; - private String id; + private final String id; - private String name; + private final String name; - private String sourceId; + private final String sourceId; private transient String string; - private String description; + private final String description; public CategoryDefinition(String id, String name, String sourceId, String description) { this.id = id; @@ -112,11 +112,10 @@ public int compareTo(CategoryDefinition object) { @Override public boolean equals(Object object) { - if (!(object instanceof CategoryDefinition)) { + if (!(object instanceof final CategoryDefinition castedObject)) { return false; } - final CategoryDefinition castedObject = (CategoryDefinition) object; return Objects.equals(id, castedObject.id) && Objects.equals(name, castedObject.name) && Objects.equals(sourceId, castedObject.sourceId); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ExtensionActivityRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ExtensionActivityRegistry.java index ff26ce5a8af..511167fce06 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ExtensionActivityRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ExtensionActivityRegistry.java @@ -53,7 +53,7 @@ final class ExtensionActivityRegistry extends AbstractActivityRegistry { private List extensionDefaultEnabledActivities; - private IExtensionRegistry extensionRegistry; + private final IExtensionRegistry extensionRegistry; ExtensionActivityRegistry(IExtensionRegistry extensionRegistry) { if (extensionRegistry == null) { @@ -178,11 +178,13 @@ private void load() { for (ActivityDefinition activityDef : extensionActivityDefinitions) { String id = activityDef.getId(); String preferenceKey = createPreferenceKey(id); - if ("".equals(store.getDefaultString(preferenceKey))) //$NON-NLS-1$ + if ("".equals(store.getDefaultString(preferenceKey))) { //$NON-NLS-1$ continue; + } if (store.getDefaultBoolean(preferenceKey)) { - if (!extensionDefaultEnabledActivities.contains(id) && activityDef.getEnabledWhen() == null) + if (!extensionDefaultEnabledActivities.contains(id) && activityDef.getEnabledWhen() == null) { extensionDefaultEnabledActivities.add(id); + } } else { extensionDefaultEnabledActivities.remove(id); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Identifier.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Identifier.java index 64b40bdd8ab..61042fc2d72 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Identifier.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Identifier.java @@ -40,7 +40,7 @@ final class Identifier implements IIdentifier { private transient int hashCode = HASH_INITIAL; - private String id; + private final String id; private ListenerList identifierListeners; @@ -86,11 +86,10 @@ public int compareTo(IIdentifier object) { @Override public boolean equals(Object object) { - if (!(object instanceof Identifier)) { + if (!(object instanceof final Identifier castedObject)) { return false; } - final Identifier castedObject = (Identifier) object; return Objects.equals(activityIds, castedObject.activityIds) && enabled == castedObject.enabled && Objects.equals(id, castedObject.id); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/InternalActivityHelper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/InternalActivityHelper.java index f36101482ca..bfbae6c5bcd 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/InternalActivityHelper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/InternalActivityHelper.java @@ -43,8 +43,9 @@ public static Set getActivityIdsForCategory(IActivityManager activityMan Set activityIds = new HashSet<>(); for (ICategoryActivityBinding binding : bindings) { String id = binding.getActivityId(); - if (activityManager.getActivity(id).getExpression() == null) + if (activityManager.getActivity(id).getExpression() == null) { activityIds.add(id); + } } return activityIds; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/MutableActivityManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/MutableActivityManager.java index b8da7a8755f..23a6a92f0c0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/MutableActivityManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/MutableActivityManager.java @@ -62,7 +62,7 @@ public final class MutableActivityManager extends AbstractActivityManager implements IMutableActivityManager, Cloneable { - private Map activitiesById = new HashMap<>(); + private final Map activitiesById = new HashMap<>(); private Map> activityRequirementBindingsByActivityId = new HashMap<>(); @@ -70,9 +70,9 @@ public final class MutableActivityManager extends AbstractActivityManager private Map> activityPatternBindingsByActivityId = new HashMap<>(); - private IActivityRegistry activityRegistry; + private final IActivityRegistry activityRegistry; - private Map categoriesById = new HashMap<>(); + private final Map categoriesById = new HashMap<>(); private Map> categoryActivityBindingsByCategoryId = new HashMap<>(); @@ -84,7 +84,7 @@ public final class MutableActivityManager extends AbstractActivityManager private Set enabledActivityIds = new HashSet<>(); - private Map identifiersById = new HashMap<>(); + private final Map identifiersById = new HashMap<>(); /** * Avoid endless circular referencing of re-adding activity to evaluation @@ -96,7 +96,7 @@ public final class MutableActivityManager extends AbstractActivityManager * A list of identifiers that need to have their activity sets reconciled in the * background job. */ - private List deferredIdentifiers = Collections.synchronizedList(new LinkedList<>()); + private final List deferredIdentifiers = Collections.synchronizedList(new LinkedList<>()); /** * The identifier update job. Lazily initialized. @@ -105,9 +105,9 @@ public final class MutableActivityManager extends AbstractActivityManager private final IActivityRegistryListener activityRegistryListener = activityRegistryEvent -> readRegistry(false); - private Map refsByActivityDefinition = new HashMap<>(); + private final Map refsByActivityDefinition = new HashMap<>(); - private IEventBroker eventBroker; + private final IEventBroker eventBroker; /** * Create a new instance of this class using the platform extension registry. @@ -607,7 +607,7 @@ private Map updateActivities(Collection activityI return activityEventsByActivityId; } - private IPropertyChangeListener enabledWhenListener = event -> { + private final IPropertyChangeListener enabledWhenListener = event -> { if (addingEvaluationListener || isDisposed()) { return; } @@ -625,7 +625,7 @@ private Map updateActivities(Collection activityI } }; - private ITriggerPointAdvisor advisor; + private final ITriggerPointAdvisor advisor; private ActivityEvent updateActivity(Activity activity) { Set activityRequirementBindings = activityRequirementBindingsByActivityId diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Persistence.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Persistence.java index 0d60b0eccfb..b7940ce612b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Persistence.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/Persistence.java @@ -174,11 +174,11 @@ private Persistence() { } static public void log(IMemento memento, String elementName, String msg) { - if (memento instanceof ConfigurationElementMemento) { - ConfigurationElementMemento cMemento = (ConfigurationElementMemento) memento; + if (memento instanceof ConfigurationElementMemento cMemento) { log(elementName, msg, cMemento.getContributorName(), cMemento.getExtensionID()); - } else + } else { log(elementName, msg, null, null); + } } static public void log(IConfigurationElement element, String elementName, String msg) { @@ -189,10 +189,11 @@ static public void log(IConfigurationElement element, String elementName, String static public void log(String elementName, String msg, String contributorName, String extensionID) { String msgInContext = elementName + ": " + msg; //$NON-NLS-1$ ; - if (contributorName != null && extensionID != null) + if (contributorName != null && extensionID != null) { msgInContext += NLS.bind(fullContextTemplate, contributorName, extensionID); - else if (contributorName != null) + } else if (contributorName != null) { msgInContext += NLS.bind(shortContextTemplate, contributorName); + } WorkbenchPlugin.log(msgInContext); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ProxyActivityManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ProxyActivityManager.java index fe0de34f1d3..0dcbca6f739 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ProxyActivityManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ProxyActivityManager.java @@ -22,7 +22,7 @@ import org.eclipse.ui.activities.IIdentifier; public final class ProxyActivityManager extends AbstractActivityManager { - private IActivityManager activityManager; + private final IActivityManager activityManager; public ProxyActivityManager(IActivityManager activityManager) { if (activityManager == null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityCategoryLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityCategoryLabelProvider.java index 04af55dbc19..fb05a73e75b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityCategoryLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityCategoryLabelProvider.java @@ -34,8 +34,8 @@ */ public class ActivityCategoryLabelProvider extends LabelProvider { - private LocalResourceManager manager; - private Map descriptorMap = new HashMap<>(); + private final LocalResourceManager manager; + private final Map descriptorMap = new HashMap<>(); /** * Create a new instance of this class. @@ -63,14 +63,12 @@ private ImageDescriptor getDescriptor(Object element) { return descriptor; } - if (element instanceof ICategory) { - ICategory category = (ICategory) element; + if (element instanceof ICategory category) { descriptor = PlatformUI.getWorkbench().getActivitySupport().getImageDescriptor(category); if (descriptor != null) { descriptorMap.put(element, descriptor); } - } else if (element instanceof IActivity) { - IActivity activity = (IActivity) element; + } else if (element instanceof IActivity activity) { descriptor = PlatformUI.getWorkbench().getActivitySupport().getImageDescriptor(activity); if (descriptor != null) { descriptorMap.put(element, descriptor); @@ -81,15 +79,13 @@ private ImageDescriptor getDescriptor(Object element) { @Override public String getText(Object element) { - if (element instanceof IActivity) { - IActivity activity = (IActivity) element; + if (element instanceof IActivity activity) { try { return activity.getName(); } catch (NotDefinedException e) { return activity.getId(); } - } else if (element instanceof ICategory) { - ICategory category = ((ICategory) element); + } else if (element instanceof ICategory category) { try { return category.getName(); } catch (NotDefinedException e) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityEnabler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityEnabler.java index 8d82b1a31db..61e99e8a23e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityEnabler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityEnabler.java @@ -70,7 +70,7 @@ public class ActivityEnabler { /** * The Set of activities that belong to at least one category. */ - private Set managedActivities = new HashSet<>(7); + private final Set managedActivities = new HashSet<>(7); /** * The content provider. @@ -82,13 +82,13 @@ public class ActivityEnabler { */ protected Text descriptionText; - private Properties strings; + private final Properties strings; - private IMutableActivityManager activitySupport; + private final IMutableActivityManager activitySupport; private TableViewer dependantViewer; - private ISelectionChangedListener selectionListener = event -> { + private final ISelectionChangedListener selectionListener = event -> { Object element = event.getStructuredSelection().getFirstElement(); try { if (element instanceof ICategory) { @@ -104,7 +104,7 @@ public class ActivityEnabler { /** * Listener that manages the grey/check state of categories. */ - private ICheckStateListener checkListener = new ICheckStateListener() { + private final ICheckStateListener checkListener = new ICheckStateListener() { @Override public void checkStateChanged(CheckStateChangedEvent event) { @@ -423,7 +423,7 @@ protected void toggleTreeEnablement(boolean enabled) { Object[] elements = provider.getElements(activitySupport); // reset grey state to null - dualViewer.setGrayedElements(new Object[0]); + dualViewer.setGrayedElements(); // enable all categories for (Object element : elements) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityLabelProvider.java index ec53a3b1e7d..5e78490aa31 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ActivityLabelProvider.java @@ -28,7 +28,7 @@ */ public class ActivityLabelProvider extends LabelProvider { - private IActivityManager activityManager; + private final IActivityManager activityManager; /** * Create a new instance of the receiver. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/CategorizedActivity.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/CategorizedActivity.java index 55cda7b3741..ddf4c6198c3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/CategorizedActivity.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/CategorizedActivity.java @@ -34,12 +34,12 @@ public class CategorizedActivity implements IActivity { /** * The real IActivity. */ - private IActivity activity; + private final IActivity activity; /** * The ICategory under which this proxy will be rendered. */ - private ICategory category; + private final ICategory category; /** * Create a new instance. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/EnablementDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/EnablementDialog.java index 9546de634a0..70756b253b9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/EnablementDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/EnablementDialog.java @@ -55,9 +55,9 @@ public class EnablementDialog extends Dialog { private Button dontAskButton; - private Set activitiesToEnable = new HashSet<>(7); + private final Set activitiesToEnable = new HashSet<>(7); - private Collection activityIds; + private final Collection activityIds; private boolean dontAsk; @@ -73,7 +73,7 @@ public class EnablementDialog extends Dialog { private Text detailsText; - private Properties strings; + private final Properties strings; /** * Create a new instance of the receiver. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ImageBindingRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ImageBindingRegistry.java index 0de7a25ed11..041d8d66556 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ImageBindingRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/ImageBindingRegistry.java @@ -31,8 +31,8 @@ * @since 3.1 */ public class ImageBindingRegistry implements IExtensionChangeHandler { - private String tag; - private ImageRegistry registry = new ImageRegistry(); + private final String tag; + private final ImageRegistry registry = new ImageRegistry(); public ImageBindingRegistry(String tag) { super(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/RegistryTriggerPoint.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/RegistryTriggerPoint.java index 6fedc27abf0..4a04db0daf0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/RegistryTriggerPoint.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/RegistryTriggerPoint.java @@ -24,9 +24,9 @@ */ public class RegistryTriggerPoint extends AbstractTriggerPoint { - private String id; + private final String id; - private IConfigurationElement element; + private final IConfigurationElement element; private Map hints; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/TriggerPointAdvisorDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/TriggerPointAdvisorDescriptor.java index 1f42871d211..675558df662 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/TriggerPointAdvisorDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/TriggerPointAdvisorDescriptor.java @@ -26,9 +26,9 @@ */ public final class TriggerPointAdvisorDescriptor { - private String id; + private final String id; - private IConfigurationElement element; + private final IConfigurationElement element; /** * Create a new instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/TriggerPointManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/TriggerPointManager.java index daa6bc0984d..2a3fec7ef8c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/TriggerPointManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/TriggerPointManager.java @@ -35,7 +35,7 @@ */ public class TriggerPointManager implements ITriggerPointManager, IExtensionChangeHandler { - private HashMap triggerMap = new HashMap<>(); + private final HashMap triggerMap = new HashMap<>(); public TriggerPointManager() { super(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/WorkbenchActivitySupport.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/WorkbenchActivitySupport.java index 47b62414745..6b51cbdad1e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/WorkbenchActivitySupport.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/activities/ws/WorkbenchActivitySupport.java @@ -107,9 +107,7 @@ public void activityManagerChanged(ActivityManagerEvent activityManagerEvent) { final IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); for (IWorkbenchWindow wWindow : windows) { - if (wWindow instanceof WorkbenchWindow) { - final WorkbenchWindow window = (WorkbenchWindow) wWindow; - + if (wWindow instanceof final WorkbenchWindow window) { final ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell()); final IRunnableWithProgress runnable = new IRunnableWithProgress() { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/application/CompatibilityActionBarAdvisor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/application/CompatibilityActionBarAdvisor.java index da53200b211..d72c900c298 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/application/CompatibilityActionBarAdvisor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/application/CompatibilityActionBarAdvisor.java @@ -25,7 +25,7 @@ */ public class CompatibilityActionBarAdvisor extends ActionBarAdvisor { - private WorkbenchAdvisor wbAdvisor; + private final WorkbenchAdvisor wbAdvisor; /** * Creates a new compatibility action bar advisor. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/application/CompatibilityWorkbenchWindowAdvisor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/application/CompatibilityWorkbenchWindowAdvisor.java index 79b764d0f0b..2fca3afbbed 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/application/CompatibilityWorkbenchWindowAdvisor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/application/CompatibilityWorkbenchWindowAdvisor.java @@ -31,7 +31,7 @@ */ public class CompatibilityWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { - private WorkbenchAdvisor wbAdvisor; + private final WorkbenchAdvisor wbAdvisor; /** * Creates a new compatibility workbench window advisor. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/DefaultWebBrowser.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/DefaultWebBrowser.java index 0cdb178f95d..c58104edc12 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/DefaultWebBrowser.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/DefaultWebBrowser.java @@ -33,7 +33,7 @@ * @since 3.1 */ public class DefaultWebBrowser extends AbstractWebBrowser { - private DefaultWorkbenchBrowserSupport support; + private final DefaultWorkbenchBrowserSupport support; private String webBrowser; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/DefaultWorkbenchBrowserSupport.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/DefaultWorkbenchBrowserSupport.java index f3e0ab4ce33..846a3b6fc6e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/DefaultWorkbenchBrowserSupport.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/DefaultWorkbenchBrowserSupport.java @@ -29,7 +29,7 @@ * @since 3.1 */ public class DefaultWorkbenchBrowserSupport extends AbstractWorkbenchBrowserSupport { - private Map browsers; + private final Map browsers; private static final String DEFAULT_BROWSER_ID_BASE = "org.eclipse.ui.defaultBrowser"; //$NON-NLS-1$ /** @@ -72,8 +72,9 @@ private String getDefaultId() { String id = null; for (int i = 0; i < Integer.MAX_VALUE; i++) { id = DEFAULT_BROWSER_ID_BASE + i; - if (browsers.get(id) == null) + if (browsers.get(id) == null) { break; + } } return id; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/WorkbenchBrowserSupport.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/WorkbenchBrowserSupport.java index 38f820965e3..7d5b45712d7 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/WorkbenchBrowserSupport.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/browser/WorkbenchBrowserSupport.java @@ -48,7 +48,7 @@ public class WorkbenchBrowserSupport extends AbstractWorkbenchBrowserSupport { private String desiredBrowserSupportId; - private IExtensionChangeHandler handler = new IExtensionChangeHandler() { + private final IExtensionChangeHandler handler = new IExtensionChangeHandler() { @Override public void addExtension(IExtensionTracker tracker, IExtension extension) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandImageManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandImageManager.java index 924f8449a0c..a2f105361fc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandImageManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandImageManager.java @@ -119,12 +119,10 @@ public void bind(final String commandId, final int type, final String style, fin if (style == null) { if ((typedImage == null) || (typedImage instanceof ImageDescriptor)) { images[type] = descriptor; - } else if (typedImage instanceof Map) { - final Map styleMap = (Map) typedImage; + } else if (typedImage instanceof final Map styleMap) { styleMap.put(style, descriptor); } - } else if (typedImage instanceof Map) { - final Map styleMap = (Map) typedImage; + } else if (typedImage instanceof final Map styleMap) { styleMap.put(style, descriptor); } else if (typedImage instanceof ImageDescriptor || typedImage == null) { final Map styleMap = new HashMap(); @@ -185,8 +183,7 @@ public String generateUnusedStyle(final String commandId) { for (final Object styledImages : existingImages) { if (styledImages instanceof ImageDescriptor) { existingStyles.add(null); - } else if (styledImages instanceof Map) { - final Map styleMap = (Map) styledImages; + } else if (styledImages instanceof final Map styleMap) { existingStyles.addAll(styleMap.keySet()); } } @@ -265,8 +262,7 @@ public ImageDescriptor getImageDescriptor(final String commandId, final int type return (ImageDescriptor) typedImage; } - if (typedImage instanceof Map) { - final Map styleMap = (Map) typedImage; + if (typedImage instanceof final Map styleMap) { Object styledImage = styleMap.get(style); if (styledImage instanceof ImageDescriptor) { return (ImageDescriptor) styledImage; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandService.java index 10a4f8af911..78f0467985c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandService.java @@ -87,9 +87,9 @@ static String createPreferenceKey(final Command command, final String stateId) { */ private final CommandPersistence commandPersistence; - private IEclipseContext context; + private final IEclipseContext context; - private ICommandHelpService commandHelpService; + private final ICommandHelpService commandHelpService; /** * Constructs a new instance of CommandService using a command @@ -137,8 +137,7 @@ public void dispose() { final String[] stateIds = command.getStateIds(); for (final String stateId : stateIds) { final State state = command.getState(stateId); - if (state instanceof PersistentState) { - final PersistentState persistentState = (PersistentState) state; + if (state instanceof final PersistentState persistentState) { if (persistentState.shouldPersist()) { persistentState.save(PrefUtil.getInternalPreferenceStore(), createPreferenceKey(command, stateId)); @@ -318,8 +317,9 @@ public void registerElement(IElementReference elementReference) { @Override public void unregisterElement(IElementReference elementReference) { - if (commandCallbacks == null) + if (commandCallbacks == null) { return; + } List parameterizedCommands = commandCallbacks.get(elementReference.getCommandId()); if (parameterizedCommands != null) { parameterizedCommands.remove(elementReference); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandStateProxy.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandStateProxy.java index ec1a9eb10b4..fad05aa0e88 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandStateProxy.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/CommandStateProxy.java @@ -55,12 +55,12 @@ public final class CommandStateProxy extends PersistentState { /** * The key in the preference store to locate the persisted state. */ - private String preferenceKey; + private final String preferenceKey; /** * The preference store containing the persisted state, if any. */ - private IPreferenceStore preferenceStore; + private final IPreferenceStore preferenceStore; /** * The real state. This value is null until the proxy is forced to @@ -121,8 +121,7 @@ public void addListener(final IStateListener listener) { public void dispose() { if (state != null) { state.dispose(); - if (state instanceof PersistentState) { - final PersistentState persistableState = (PersistentState) state; + if (state instanceof final PersistentState persistableState) { if (persistableState.shouldPersist() && preferenceStore != null && preferenceKey != null) { persistableState.save(preferenceStore, preferenceKey); } @@ -141,8 +140,7 @@ public Object getValue() { @Override public void load(final IPreferenceStore store, final String preferenceKey) { - if (loadState() && state instanceof PersistentState) { - final PersistentState persistableState = (PersistentState) state; + if (loadState() && state instanceof final PersistentState persistableState) { if (persistableState.shouldPersist() && preferenceStore != null && preferenceKey != null) { persistableState.load(preferenceStore, preferenceKey); } @@ -179,8 +177,7 @@ private boolean loadState(final boolean readPersistence) { configurationElement = null; // Try to load the persistent state, if possible. - if (readPersistence && state instanceof PersistentState) { - final PersistentState persistentState = (PersistentState) state; + if (readPersistence && state instanceof final PersistentState persistentState) { persistentState.setShouldPersist(true); } load(preferenceStore, preferenceKey); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/ElementReference.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/ElementReference.java index a95e675934d..5a185a25dfd 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/ElementReference.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/ElementReference.java @@ -27,8 +27,8 @@ */ public class ElementReference implements IElementReference { - private String commandId; - private UIElement element; + private final String commandId; + private final UIElement element; private HashMap parameters; /** diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/SlaveCommandService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/SlaveCommandService.java index f7edd58f13b..8eaef8f2081 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/SlaveCommandService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/commands/SlaveCommandService.java @@ -51,14 +51,14 @@ */ public class SlaveCommandService implements ICommandService, IUpdateService { - private Collection fExecutionListeners = new ArrayList(); + private final Collection fExecutionListeners = new ArrayList(); /** * The collection of ICallbackReferences added through this service. * * @since 3.3 */ - private Set fCallbackCache = new HashSet(); + private final Set fCallbackCache = new HashSet(); private ICommandService fParentService; @@ -68,7 +68,7 @@ public class SlaveCommandService implements ICommandService, IUpdateService { * * @since 3.3 */ - private String fScopingName; + private final String fScopingName; /** * The object to scope. In theory, the service locator that would find this diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/ContextAuthority.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/ContextAuthority.java index a640cb545bc..bbe852104b1 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/ContextAuthority.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/ContextAuthority.java @@ -607,8 +607,7 @@ protected void sourceChanged(final int sourcePriority) { while (changedContextIdItr.hasNext()) { final String contextId = changedContextIdItr.next(); final Object value = contextActivationsByContextId.get(contextId); - if (value instanceof IContextActivation) { - final IContextActivation activation = (IContextActivation) value; + if (value instanceof final IContextActivation activation) { updateContext(contextId, evaluate(activation)); } else if (value instanceof Collection) { updateContext(contextId, containsActive((Collection) value)); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/ContextService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/ContextService.java index 83e47ba72e3..aea5460e213 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/ContextService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/ContextService.java @@ -45,7 +45,7 @@ */ public final class ContextService implements IContextService { - private HashMap activationToRat = new HashMap<>(); + private final HashMap activationToRat = new HashMap<>(); /** * The central authority for determining which context we should use. @@ -56,7 +56,7 @@ public final class ContextService implements IContextService { * The context manager that supports this service. This value is never * null. */ - private ContextManager contextManager; + private final ContextManager contextManager; @Inject private EContextService contextService; @@ -100,7 +100,7 @@ public IContextActivation activateContext(final String contextId) { private class UpdateExpression extends RunAndTrack { boolean updating = true; - private String contextId; + private final String contextId; private Expression expression; EvaluationResult cached = null; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/LegacyContextListenerWrapper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/LegacyContextListenerWrapper.java index ffebed1465e..31833f57bef 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/LegacyContextListenerWrapper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/LegacyContextListenerWrapper.java @@ -112,13 +112,11 @@ public final void contextManagerChanged(final ContextManagerEvent event) { @Override public final boolean equals(final Object object) { - if (object instanceof LegacyContextListenerWrapper) { - final LegacyContextListenerWrapper other = (LegacyContextListenerWrapper) object; + if (object instanceof final LegacyContextListenerWrapper other) { return wrappedListener.equals(other.wrappedListener); } - if (object instanceof org.eclipse.ui.contexts.IContextListener) { - final org.eclipse.ui.contexts.IContextListener other = (org.eclipse.ui.contexts.IContextListener) object; + if (object instanceof final org.eclipse.ui.contexts.IContextListener other) { return wrappedListener.equals(other); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/SlaveContextService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/SlaveContextService.java index 670a715768b..13bad015242 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/SlaveContextService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/SlaveContextService.java @@ -70,21 +70,21 @@ public class SlaveContextService implements IContextService { * activated/deactivated, but they will be removed when this service is * disposed. */ - private Collection fContextManagerListeners; + private final Collection fContextManagerListeners; /** * A collection of source providers. The listeners are not * activated/deactivated, but they will be removed when this service is * disposed. */ - private Collection fSourceProviders; + private final Collection fSourceProviders; /** * A collection of shells registered through this service. The listeners are not * activated/deactivated, but they will be removed when this service is * disposed. */ - private Collection fRegisteredShells; + private final Collection fRegisteredShells; /** * Construct the new slave. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/WorkbenchContextSupport.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/WorkbenchContextSupport.java index 7b446f1e0b7..d0a2c913633 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/WorkbenchContextSupport.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/contexts/WorkbenchContextSupport.java @@ -47,17 +47,17 @@ public class WorkbenchContextSupport implements IWorkbenchContextSupport { /** * The binding service for the workbench. This value is never null. */ - private IBindingService bindingService; + private final IBindingService bindingService; /** * The context service for the workbench. This value is never null. */ - private IContextService contextService; + private final IContextService contextService; /** * The legacy context manager supported by this application. */ - private ContextManagerLegacyWrapper contextManagerWrapper; + private final ContextManagerLegacyWrapper contextManagerWrapper; /** * The workbench for which context support is being provided. This value must @@ -132,8 +132,7 @@ public final void removeEnabledSubmission(final EnabledSubmission enabledSubmiss } final Object value = activationsBySubmission.remove(enabledSubmission); - if (value instanceof IContextActivation) { - final IContextActivation activation = (IContextActivation) value; + if (value instanceof final IContextActivation activation) { contextService.deactivateContext(activation); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/databinding/AdaptedValueProperty.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/databinding/AdaptedValueProperty.java index 302c4bc80b8..d128d4c86ee 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/databinding/AdaptedValueProperty.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/databinding/AdaptedValueProperty.java @@ -22,8 +22,9 @@ public Object getValueType() { @Override protected T doGetValue(S source) { - if (adapter.isInstance(source)) + if (adapter.isInstance(source)) { return (T) source; + } return adapterManager.getAdapter(source, adapter); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/databinding/ListeningValue.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/databinding/ListeningValue.java index b9371dd2abb..0941ac635d5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/databinding/ListeningValue.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/databinding/ListeningValue.java @@ -38,8 +38,9 @@ protected final T doGetValue() { */ protected final void protectedSetValue(T value) { checkRealm(); - if (!isListening) + if (!isListening) { throw new IllegalStateException(); + } if (this.value != value) { fireValueChange(Diffs.createValueDiff(this.value, this.value = value)); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DeclarativeDecorator.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DeclarativeDecorator.java index 59a5c2c35d4..b6fd3b00f0d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DeclarativeDecorator.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DeclarativeDecorator.java @@ -27,9 +27,9 @@ */ public class DeclarativeDecorator implements ILightweightLabelDecorator { - private String iconLocation; + private final String iconLocation; - private IConfigurationElement configElement; + private final IConfigurationElement configElement; private ImageDescriptor descriptor; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationBuilder.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationBuilder.java index faa88c0f9fb..0bca7b7745d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationBuilder.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationBuilder.java @@ -32,9 +32,9 @@ public class DecorationBuilder implements IDecoration { private static int DECORATOR_ARRAY_SIZE = 6; - private List prefixes = new ArrayList<>(); + private final List prefixes = new ArrayList<>(); - private List suffixes = new ArrayList<>(); + private final List suffixes = new ArrayList<>(); private ImageDescriptor[] descriptors = new ImageDescriptor[DECORATOR_ARRAY_SIZE]; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationResult.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationResult.java index a2191a609ec..4fd2cf797ce 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationResult.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationResult.java @@ -30,17 +30,17 @@ */ public class DecorationResult { - private List prefixes; + private final List prefixes; - private List suffixes; + private final List suffixes; private ImageDescriptor[] descriptors; - private Color foregroundColor; + private final Color foregroundColor; - private Color backgroundColor; + private final Color backgroundColor; - private Font font; + private final Font font; DecorationResult(List prefixList, List suffixList, ImageDescriptor[] imageDescriptors, Color resultForegroundColor, Color resultBackgroundColor, Font resultFont) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationScheduler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationScheduler.java index c0cf9865002..f522fcaca22 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationScheduler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecorationScheduler.java @@ -159,7 +159,7 @@ void sleep(long timeoutMillis) throws InterruptedException { private UIJob updateJob; - private Collection removedListeners = Collections.synchronizedSet(new HashSet<>()); + private final Collection removedListeners = Collections.synchronizedSet(new HashSet<>()); private Job clearJob; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorDefinition.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorDefinition.java index 3b442e57102..f2fcd80164a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorDefinition.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorDefinition.java @@ -45,7 +45,7 @@ public abstract class DecoratorDefinition implements IPluginContribution { private boolean defaultEnabled; - private String id; + private final String id; protected IConfigurationElement definingElement; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorManager.java index 7102f76f369..608bb538f84 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorManager.java @@ -77,20 +77,20 @@ public class DecoratorManager implements ILabelProviderListener, IDecoratorManag */ public static final Object FAMILY_DECORATE = new Object(); - private DecorationScheduler scheduler; + private final DecorationScheduler scheduler; private LightweightDecoratorManager lightweightManager; // Hold onto the list of listeners to be told if a change has occurred - private ListenerList listeners = new ListenerList<>(); + private final ListenerList listeners = new ListenerList<>(); // The full definitions read from the registry. // Initialize to an empty collection as this is rarely used now. private FullDecoratorDefinition[] fullDefinitions; - private FullTextDecoratorRunnable fullTextRunnable = new FullTextDecoratorRunnable(); + private final FullTextDecoratorRunnable fullTextRunnable = new FullTextDecoratorRunnable(); - private FullImageDecoratorRunnable fullImageRunnable = new FullImageDecoratorRunnable(); + private final FullImageDecoratorRunnable fullImageRunnable = new FullImageDecoratorRunnable(); private static final FullDecoratorDefinition[] EMPTY_FULL_DEF = new FullDecoratorDefinition[0]; @@ -1010,8 +1010,7 @@ public void removeExtension(IExtension source, Object[] objects) { boolean shouldClear = false; for (Object object : objects) { - if (object instanceof DecoratorDefinition) { - DecoratorDefinition definition = (DecoratorDefinition) object; + if (object instanceof DecoratorDefinition definition) { if (definition.isFull()) { int idx = getFullDecoratorDefinitionIdx(definition.getId()); if (idx != -1) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorRegistryReader.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorRegistryReader.java index 39071beb293..500c4e518c7 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorRegistryReader.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/DecoratorRegistryReader.java @@ -29,9 +29,9 @@ public class DecoratorRegistryReader extends RegistryReader { // The registry values are the ones read from the registry - private Collection values = new ArrayList<>(); + private final Collection values = new ArrayList<>(); - private Collection ids = new HashSet<>(); + private final Collection ids = new HashSet<>(); /** * Constructor for DecoratorRegistryReader. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/LightweightActionDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/LightweightActionDescriptor.java index 7f7e7307faf..4c57ba8e869 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/LightweightActionDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/LightweightActionDescriptor.java @@ -33,11 +33,11 @@ public class LightweightActionDescriptor implements IAdaptable, IWorkbenchAdapter { private static final Object[] NO_CHILDREN = new Object[0]; - private String id; + private final String id; - private String label; + private final String label; - private String description; + private final String description; private ImageDescriptor image; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/LightweightDecoratorManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/LightweightDecoratorManager.java index 8c4a56b6146..6b4cd49e2ec 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/LightweightDecoratorManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/decorators/LightweightDecoratorManager.java @@ -117,7 +117,7 @@ void clearReferences() { } } - private LightweightRunnable runnable = new LightweightRunnable(); + private final LightweightRunnable runnable = new LightweightRunnable(); // The lightweight definitions read from the registry private LightweightDecoratorDefinition[] lightweightDefinitions; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutDialog.java index 8674f34e1f4..f8fd1425f6b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutDialog.java @@ -78,13 +78,13 @@ public class AboutDialog extends TrayDialog { private String productName; - private IProduct product; + private final IProduct product; - private AboutBundleGroupData[] bundleGroupInfos; + private final AboutBundleGroupData[] bundleGroupInfos; - private ArrayList images = new ArrayList<>(); + private final ArrayList images = new ArrayList<>(); - private AboutFeaturesButtonManager buttonManager = new AboutFeaturesButtonManager(); + private final AboutFeaturesButtonManager buttonManager = new AboutFeaturesButtonManager(); private StyledText text; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutFeaturesDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutFeaturesDialog.java index 87d672d18fa..02afbe561f2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutFeaturesDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutFeaturesDialog.java @@ -45,10 +45,11 @@ public AboutFeaturesDialog(Shell parentShell, String productName, AboutBundleGro page.setBundleGroupInfos(bundleGroupInfos); page.setInitialSelection(initialSelection); String title; - if (productName != null) + if (productName != null) { title = NLS.bind(WorkbenchMessages.AboutFeaturesDialog_shellTitle, productName); - else + } else { title = WorkbenchMessages.AboutFeaturesDialog_SimpleTitle; + } initializeDialog(page, title, IWorkbenchHelpContextIds.ABOUT_FEATURES_DIALOG); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutPluginsDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutPluginsDialog.java index 547d2ffdd0a..2d57d94434d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutPluginsDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AboutPluginsDialog.java @@ -35,8 +35,9 @@ public AboutPluginsDialog(Shell parentShell, String productName, Bundle[] bundle page.setHelpContextId(helpContextId); page.setBundles(bundles); page.setMessage(message); - if (title == null && page.getProductName() != null) + if (title == null && page.getProductName() != null) { title = NLS.bind(WorkbenchMessages.AboutPluginsDialog_shellTitle, productName); + } initializeDialog(page, title, helpContextId); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AbstractWorkingSetDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AbstractWorkingSetDialog.java index dbc577d30c5..5d7514784b3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AbstractWorkingSetDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AbstractWorkingSetDialog.java @@ -82,7 +82,7 @@ public abstract class AbstractWorkingSetDialog extends SelectionDialog implement private Set workingSetIds; - private boolean canEdit; + private final boolean canEdit; protected AbstractWorkingSetDialog(Shell parentShell, String[] workingSetIds, boolean canEdit) { super(parentShell); @@ -334,8 +334,9 @@ protected void updateButtonAvailability() { newButton.setEnabled(registry.hasNewPageWorkingSetDescriptor()); - if (canEdit) + if (canEdit) { removeButton.setEnabled(hasSelection); + } IWorkingSet selectedWorkingSet = null; if (hasSelection) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AdaptableForwarder.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AdaptableForwarder.java index 2918407feaa..41f7e0c9817 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AdaptableForwarder.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/AdaptableForwarder.java @@ -25,7 +25,7 @@ */ public class AdaptableForwarder implements IAdaptable { - private Object element; + private final Object element; /** * Create a new instance of the receiver. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ContentTypeFilenameAssociationDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ContentTypeFilenameAssociationDialog.java index 39936b94c36..e32009a0ba3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ContentTypeFilenameAssociationDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ContentTypeFilenameAssociationDialog.java @@ -49,9 +49,9 @@ public class ContentTypeFilenameAssociationDialog extends TitleAreaDialog { private Button okButton; - private String title; + private final String title; - private String helpContextId; + private final String helpContextId; private final String headerTitle; @@ -206,8 +206,9 @@ protected IDialogSettings getDialogBoundsSettings() { .getDialogSettingsProvider(FrameworkUtil.getBundle(ContentTypeFilenameAssociationDialog.class)) .getDialogSettings(); IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION); - if (section == null) + if (section == null) { section = settings.addNewSection(DIALOG_SETTINGS_SECTION); + } return section; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java index 755a6178288..d9b7c9bd1c8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java @@ -114,7 +114,7 @@ public ContentTypesPreferencePage() { private Button addEditorAssociationButton; - private Collection disposableEditorIcons = new ArrayList<>(); + private final Collection disposableEditorIcons = new ArrayList<>(); private static class Spec { /** @@ -381,10 +381,9 @@ private void createEditors(Composite parent) { addEditorAssociationButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - if (editorRegistry instanceof EditorRegistry) { + if (editorRegistry instanceof EditorRegistry registry) { EditorSelectionDialog dialog = new EditorSelectionDialog(getShell()); dialog.setEditorsToFilter(getAssociatedEditors()); - EditorRegistry registry = (EditorRegistry) editorRegistry; IContentType contentType = (IContentType) editorAssociationsViewer.getInput(); if (dialog.open() == IDialogConstants.OK_ID) { registry.addUserAssociation(contentType, dialog.getSelectedEditor()); @@ -397,8 +396,7 @@ public void widgetSelected(SelectionEvent e) { removeEditorButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - if (editorRegistry instanceof EditorRegistry) { - EditorRegistry registry = (EditorRegistry) editorRegistry; + if (editorRegistry instanceof EditorRegistry registry) { IEditorDescriptor editor = (IEditorDescriptor) editorAssociationsViewer.getStructuredSelection() .getFirstElement(); IContentType contentType = (IContentType) editorAssociationsViewer.getInput(); @@ -410,8 +408,7 @@ public void widgetSelected(SelectionEvent e) { removeEditorButton.setText(WorkbenchMessages.ContentTypes_editorAssociationRemoveLabel); setButtonLayoutData(removeEditorButton); editorAssociationsViewer.addSelectionChangedListener(event -> { - if (editorRegistry instanceof EditorRegistry) { - EditorRegistry registry = (EditorRegistry) editorRegistry; + if (editorRegistry instanceof EditorRegistry registry) { IEditorDescriptor editor = (IEditorDescriptor) editorAssociationsViewer.getStructuredSelection() .getFirstElement(); IContentType contentType = (IContentType) editorAssociationsViewer.getInput(); @@ -511,8 +508,9 @@ public void keyReleased(KeyEvent e) { String errorMessage = null; String text = charsetField.getText(); try { - if (text.length() != 0 && !Charset.isSupported(text)) + if (text.length() != 0 && !Charset.isSupported(text)) { errorMessage = WorkbenchMessages.ContentTypes_unsupportedEncoding; + } } catch (IllegalCharsetNameException ex) { errorMessage = WorkbenchMessages.ContentTypes_unsupportedEncoding; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/DecoratorsPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/DecoratorsPreferencePage.java index fbdd51efcba..6c6825d2f03 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/DecoratorsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/DecoratorsPreferencePage.java @@ -120,7 +120,7 @@ public String getText(Object element) { checkboxViewer.setContentProvider(new IStructuredContentProvider() { private final Comparator comparer = new Comparator() { - private Collator collator = Collator.getInstance(); + private final Collator collator = Collator.getInstance(); @Override public int compare(Object arg0, Object arg1) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/EditorsPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/EditorsPreferencePage.java index 11807871b86..1aca9a93217 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/EditorsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/EditorsPreferencePage.java @@ -66,7 +66,7 @@ public class EditorsPreferencePage extends PreferencePage implements IWorkbenchP private IntegerFieldEditor recentFilesEditor; - private IPropertyChangeListener validityChangeListener = event -> { + private final IPropertyChangeListener validityChangeListener = event -> { if (event.getProperty().equals(FieldEditor.IS_VALID)) { updateValidState(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/FileExtensionDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/FileExtensionDialog.java index ab7ff02a2dc..d66334f451d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/FileExtensionDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/FileExtensionDialog.java @@ -48,9 +48,9 @@ public class FileExtensionDialog extends TitleAreaDialog { private Button okButton; - private String title; + private final String title; - private String helpContextId; + private final String helpContextId; private final String headerTitle; @@ -236,8 +236,9 @@ protected IDialogSettings getDialogBoundsSettings() { IDialogSettings settings = PlatformUI .getDialogSettingsProvider(FrameworkUtil.getBundle(FileExtensionDialog.class)).getDialogSettings(); IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION); - if (section == null) + if (section == null) { section = settings.addNewSection(DIALOG_SETTINGS_SECTION); + } return section; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/FilteredPreferenceDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/FilteredPreferenceDialog.java index 6e3b7e15fa9..ece0dac34d7 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/FilteredPreferenceDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/FilteredPreferenceDialog.java @@ -155,7 +155,7 @@ protected void clearText() { IWorkingCopyManager workingCopyManager; - private Collection updateJobs = new ArrayList<>(); + private final Collection updateJobs = new ArrayList<>(); /** * The preference page history. @@ -211,8 +211,9 @@ protected TreeViewer createTreeViewer(Composite parent) { filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); tree = filteredTree.getViewer(); - } else + } else { tree = new TreeViewer(parent, styleBits); + } setContentAndLabelProviders(tree); tree.setInput(getPreferenceManager()); @@ -344,9 +345,7 @@ protected Control createHelpControl(Composite parent) { protected void addButtonsToHelpControl(Control control) { Composite parent = control.getParent(); - if (control instanceof ToolBar) { - ToolBar toolBar = (ToolBar) control; - + if (control instanceof ToolBar toolBar) { ToolItem importButton = new ToolItem(toolBar, SWT.PUSH); importImage = WorkbenchImages.getImageDescriptor(IWorkbenchGraphicConstants.IMG_PREF_IMPORT).createImage(); importButton.setImage(importImage); @@ -554,10 +553,9 @@ public String getText() { void activeKeyScrolling() { if (keyScrollingFilter == null) { Composite pageParent = getPageContainer().getParent(); - if (!(pageParent instanceof ScrolledComposite)) { + if (!(pageParent instanceof final ScrolledComposite sc)) { return; } - final ScrolledComposite sc = (ScrolledComposite) pageParent; keyScrollingFilter = event -> { if (!keyScrollingEnabled || sc.isDisposed()) { return; @@ -632,10 +630,12 @@ public boolean close() { } removeKeyScrolling(); history.dispose(); - if (importImage != null) + if (importImage != null) { importImage.dispose(); - if (exportImage != null) + } + if (exportImage != null) { exportImage.dispose(); + } return super.close(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/GlobalizationPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/GlobalizationPreferencePage.java index 1663d97b922..e92a3e880ab 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/GlobalizationPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/GlobalizationPreferencePage.java @@ -105,7 +105,7 @@ private void createNlsExtensionsGroup(Composite parent) { private void createBidiPreferencesGroup(Composite composite) { layoutDirectionCombo = addComboBox(composite, WorkbenchMessages.GlobalizationPreference_layoutDirection, 0); - layoutDirectionCombo.setItems(new String[] { DEFAULT_DIR, LTR_DIR, RTL_DIR }); + layoutDirectionCombo.setItems(DEFAULT_DIR, LTR_DIR, RTL_DIR); layoutDirectionCombo.select(getLayoutDirectionIndex(layoutDirection)); layoutDirectionCombo.addSelectionListener(widgetSelectedAdapter( e -> layoutDirection = getLayoutDirectionInteger(layoutDirectionCombo.getSelectionIndex()))); @@ -121,7 +121,7 @@ private void createBidiPreferencesGroup(Composite composite) { textDirectionCombo = addComboBox(composite, WorkbenchMessages.GlobalizationPreference_textDirection, LayoutConstants.getIndent()); - textDirectionCombo.setItems(new String[] { DEFAULT_DIR, LTR_DIR, AUTO_DIR, RTL_DIR }); + textDirectionCombo.setItems(DEFAULT_DIR, LTR_DIR, AUTO_DIR, RTL_DIR); textDirectionCombo.setEnabled(bidiSupport); textDirectionCombo.select(getTextDirectionIndex(textDirection)); textDirectionCombo.addSelectionListener(widgetSelectedAdapter( diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ImportExportPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ImportExportPage.java index b4655735bee..d14289f40c4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ImportExportPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ImportExportPage.java @@ -62,8 +62,8 @@ public abstract class ImportExportPage extends WorkbenchWizardSelectionPage { protected static class CategorizedWizardSelectionTree { private static final int SIZING_LISTS_HEIGHT = 200; - private IWizardCategory wizardCategories; - private String message; + private final IWizardCategory wizardCategories; + private final String message; private TreeViewer viewer; /** @@ -277,8 +277,7 @@ protected void listSelectionChanged(ISelection selection) { setErrorMessage(null); IStructuredSelection ss = (IStructuredSelection) selection; Object sel = ss.getFirstElement(); - if (sel instanceof WorkbenchWizardElement) { - WorkbenchWizardElement currentWizardSelection = (WorkbenchWizardElement) sel; + if (sel instanceof WorkbenchWizardElement currentWizardSelection) { updateSelectedNode(currentWizardSelection); } else { updateSelectedNode(null); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewContentTypeDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewContentTypeDialog.java index 485e61eb792..2d76e68186d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewContentTypeDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewContentTypeDialog.java @@ -41,7 +41,7 @@ public class NewContentTypeDialog extends TitleAreaDialog { private String name; - private IContentTypeManager manager; + private final IContentTypeManager manager; private ControlDecoration decorator; protected NewContentTypeDialog(Shell parentShell, IContentTypeManager manager, IContentType parent) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewWizardNewPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewWizardNewPage.java index 9b75c8fd162..2935cf10b46 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewWizardNewPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewWizardNewPage.java @@ -73,14 +73,14 @@ class NewWizardNewPage implements ISelectionChangedListener { private static final String STORE_SELECTED_ID = DIALOG_SETTING_SECTION_NAME + "STORE_SELECTED_ID"; //$NON-NLS-1$ - private NewWizardSelectionPage page; + private final NewWizardSelectionPage page; private FilteredTree filteredTree; private WizardPatternFilter filteredTreeFilter; // Keep track of the wizards we have previously selected - private Hashtable selectedWizards = new Hashtable<>(); + private final Hashtable selectedWizards = new Hashtable<>(); private IDialogSettings settings; @@ -92,17 +92,17 @@ class NewWizardNewPage implements ISelectionChangedListener { private CLabel descImageCanvas; - private Map imageTable = new HashMap<>(); + private final Map imageTable = new HashMap<>(); private IWizardDescriptor selectedElement; - private WizardActivityFilter filter = new WizardActivityFilter(); + private final WizardActivityFilter filter = new WizardActivityFilter(); private boolean needShowAll; - private boolean projectsOnly; + private final boolean projectsOnly; - private ViewerFilter projectFilter = new WizardTagFilter(new String[] { WorkbenchWizardElement.TAG_PROJECT }); + private final ViewerFilter projectFilter = new WizardTagFilter(new String[] { WorkbenchWizardElement.TAG_PROJECT }); /** * Create an instance of this class diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewWizardSelectionPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewWizardSelectionPage.java index 1fc475163f2..e82b1e1d142 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewWizardSelectionPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/NewWizardSelectionPage.java @@ -35,14 +35,14 @@ * currently aware of activity categories. */ class NewWizardSelectionPage extends WorkbenchWizardSelectionPage { - private IWizardCategory wizardCategories; + private final IWizardCategory wizardCategories; // widgets private NewWizardNewPage newResourcePage; - private IWizardDescriptor[] primaryWizards; + private final IWizardDescriptor[] primaryWizards; - private boolean projectsOnly; + private final boolean projectsOnly; private boolean canFinishEarly = false, hasPages = true; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PerspectivesPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PerspectivesPreferencePage.java index 499dd70b4c3..ecebc3de17d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PerspectivesPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PerspectivesPreferencePage.java @@ -77,9 +77,9 @@ public class PerspectivesPreferencePage extends PreferencePage implements IWorkb private String defaultPerspectiveId; - private ArrayList perspToDelete = new ArrayList<>(); + private final ArrayList perspToDelete = new ArrayList<>(); - private ArrayList perspToRevert = new ArrayList<>(); + private final ArrayList perspToRevert = new ArrayList<>(); private Table perspectivesTable; @@ -106,8 +106,8 @@ public class PerspectivesPreferencePage extends PreferencePage implements IWorkb /** * Comparator to compare two perspective descriptors */ - private Comparator comparator = new Comparator<>() { - private Collator collator = Collator.getInstance(); + private final Comparator comparator = new Comparator<>() { + private final Collator collator = Collator.getInstance(); @Override public int compare(IPerspectiveDescriptor d1, IPerspectiveDescriptor d2) { @@ -407,8 +407,9 @@ private boolean canDeletePerspective(IPerspectiveDescriptor desc) { MApplication application = ((Workbench) workbench).getApplication(); EModelService modelService = application.getContext().get(EModelService.class); - if (modelService.findElements(application, desc.getId(), MPerspective.class).isEmpty()) + if (modelService.findElements(application, desc.getId(), MPerspective.class).isEmpty()) { return true; + } Builder builder = PlainMessageDialog.getBuilder(getShell(), WorkbenchMessages.PerspectivesPreference_perspectiveopen_title); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferenceBoldLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferenceBoldLabelProvider.java index c4dca4b2f36..02c234c8e87 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferenceBoldLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferenceBoldLabelProvider.java @@ -25,9 +25,9 @@ */ public class PreferenceBoldLabelProvider extends PreferenceLabelProvider implements IFontProvider { - private FilteredTree filterTree; + private final FilteredTree filterTree; - private PatternFilter filterForBoldElements; + private final PatternFilter filterForBoldElements; PreferenceBoldLabelProvider(FilteredTree filterTree) { this.filterTree = filterTree; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferenceHistoryEntry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferenceHistoryEntry.java index f38686fbd91..e7d692641c8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferenceHistoryEntry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferenceHistoryEntry.java @@ -22,9 +22,9 @@ * @since 3.1 */ final class PreferenceHistoryEntry { - private String id; - private String label; - private Object argument; + private final String id; + private final String label; + private final Object argument; /** * Creates a new entry. @@ -79,8 +79,7 @@ public String toString() { @Override public boolean equals(Object obj) { - if (obj instanceof PreferenceHistoryEntry) { - PreferenceHistoryEntry other = (PreferenceHistoryEntry) obj; + if (obj instanceof PreferenceHistoryEntry other) { return id.equals(other.id) && Objects.equals(argument, other.argument); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferencePageHistory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferencePageHistory.java index e915c76b6d9..a498e5a1734 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferencePageHistory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferencePageHistory.java @@ -57,7 +57,7 @@ class PreferencePageHistory { * A list of preference history domain elements that stores the history of the * visited preference pages. */ - private List history = new ArrayList<>(); + private final List history = new ArrayList<>(); /** * Stores the current entry into history and @@ -73,7 +73,7 @@ class PreferencePageHistory { /** * The handler submission for these controls. */ - private Set activations = new HashSet<>(); + private final Set activations = new HashSet<>(); /** * Creates a new history for the given dialog. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferencePatternFilter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferencePatternFilter.java index 1d8aea18440..a284270fe03 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferencePatternFilter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PreferencePatternFilter.java @@ -38,7 +38,7 @@ public class PreferencePatternFilter extends PatternFilter { * WorkbenchPreferenceExtensionNode.getKeywordLabels() is expensive. When it * tracks keyword changes effectively than this cache can be removed. */ - private Map> keywordCache = new HashMap<>(); + private final Map> keywordCache = new HashMap<>(); /** * Create a new instance of a PreferencePatternFilter @@ -53,9 +53,7 @@ public PreferencePatternFilter() { * pages. */ private String[] getKeywords(Object element) { - if (element instanceof WorkbenchPreferenceExtensionNode) { - WorkbenchPreferenceExtensionNode workbenchNode = (WorkbenchPreferenceExtensionNode) element; - + if (element instanceof WorkbenchPreferenceExtensionNode workbenchNode) { Collection keywordCollection = keywordCache.get(element); if (keywordCollection == null) { keywordCollection = workbenchNode.getKeywordLabels(); @@ -73,8 +71,9 @@ public boolean isElementSelectable(Object element) { @Override public boolean isElementVisible(Viewer viewer, Object element) { - if (WorkbenchActivityHelper.restrictUseOf(element)) + if (WorkbenchActivityHelper.restrictUseOf(element)) { return false; + } // Preference nodes are not differentiated based on category since // categories are selectable nodes. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyDialog.java index 538e049600c..598111cce77 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyDialog.java @@ -104,10 +104,11 @@ protected void addButtonsToHelpControl(Control control) { */ private static String getName(Object element) { Object[] elements; - if (element instanceof IStructuredSelection) + if (element instanceof IStructuredSelection) { elements = ((IStructuredSelection) element).toArray(); - else + } else { elements = new Object[] { element }; + } StringBuilder sb = new StringBuilder(); // Print at most 3 entries... for (int i = 0; i < elements.length; i++) { @@ -118,8 +119,9 @@ private static String getName(Object element) { } IWorkbenchAdapter adapter = Adapters.adapt(element, IWorkbenchAdapter.class); if (adapter != null) { - if (sb.length() > 0) + if (sb.length() > 0) { sb.append(", "); //$NON-NLS-1$ + } sb.append(adapter.getLabel(element)); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java index 9b92e9d752b..1fc7756b6de 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java @@ -85,13 +85,15 @@ public boolean contribute(PropertyPageManager manager, Object object) { Object[] objs = ((IStructuredSelection) object).toArray(); for (Object obj : objs) { List contribs = getContributors(obj); - if (result == null) + if (result == null) { result = new LinkedHashSet(contribs); - else + } else { result.retainAll(contribs); + } } - } else + } else { result = getContributors(object); + } if (result == null || result.isEmpty()) { return false; @@ -125,11 +127,13 @@ public boolean contribute(PropertyPageManager manager, Object object) { while (resultIterator.hasNext()) { CategorizedPageNode next = (CategorizedPageNode) resultIterator.next(); PreferenceNode child = (PreferenceNode) catPageNodeToPages.get(next); - if (child == null) + if (child == null) { continue; + } PreferenceNode parent = null; - if (next.parent != null) + if (next.parent != null) { parent = (PreferenceNode) catPageNodeToPages.get(next.parent); + } if (parent == null) { manager.addToRoot(child); @@ -215,14 +219,16 @@ public void addExtension(IExtensionTracker tracker, IExtension extension) { * @return Collection of PropertyPageContribution */ public Collection getApplicableContributors(Object element) { - if (element instanceof IStructuredSelection) + if (element instanceof IStructuredSelection) { return getApplicableContributors((IStructuredSelection) element); + } Collection contributors = getContributors(element); Collection result = new ArrayList(); for (Iterator iter = contributors.iterator(); iter.hasNext();) { RegistryPageContributor contributor = (RegistryPageContributor) iter.next(); - if (contributor.isApplicableTo(element)) + if (contributor.isApplicableTo(element)) { result.add(contributor); + } } return result; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyPageNode.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyPageNode.java index 109e0482f45..43ed01b0537 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyPageNode.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/PropertyPageNode.java @@ -30,13 +30,13 @@ * when the user selects the page will it be loaded. */ public class PropertyPageNode extends WorkbenchPreferenceExtensionNode { - private RegistryPageContributor contributor; + private final RegistryPageContributor contributor; private IPreferencePage page; private Image icon; - private Object element; + private final Object element; /** * Create a new instance of the receiver. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java index 80a54bcc5d1..c767bcb9727 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java @@ -61,13 +61,13 @@ public class RegistryPageContributor implements IPropertyPageContributor, IAdaptable, IPluginContribution { private static final String CHILD_ENABLED_WHEN = "enabledWhen"; //$NON-NLS-1$ - private String pageId; + private final String pageId; /** * The list of subpages (immediate children) of this node (element type: * RegistryPageContributor). */ - private Collection subPages = new ArrayList<>(); + private final Collection subPages = new ArrayList<>(); private boolean adaptable = false; @@ -76,7 +76,7 @@ public class RegistryPageContributor implements IPropertyPageContributor, IAdapt */ private final boolean supportsMultiSelect; - private IConfigurationElement pageElement; + private final IConfigurationElement pageElement; private SoftReference> filterProperties; @@ -100,8 +100,9 @@ public RegistryPageContributor(String pageId, IConfigurationElement element) { @Override public PreferenceNode contributePropertyPage(PropertyPageManager mng, Object element) { PropertyPageNode node = new PropertyPageNode(this, element); - if (IWorkbenchConstants.WORKBENCH_PROPERTIES_PAGE_INFO.equals(node.getId())) + if (IWorkbenchConstants.WORKBENCH_PROPERTIES_PAGE_INFO.equals(node.getId())) { node.setPriority(-1); + } return node; } @@ -135,14 +136,16 @@ public IPreferencePage createPage(Object element) throws CoreException { } if (supportsMultiSelect) { - if ((ppage instanceof IWorkbenchPropertyPageMulti)) + if ((ppage instanceof IWorkbenchPropertyPageMulti)) { ((IWorkbenchPropertyPageMulti) ppage).setElements(adapt); - else + } else { throw new CoreException(new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, "Property page must implement IWorkbenchPropertyPageMulti: " + getPageName(), //$NON-NLS-1$ null)); - } else + } + } else { ((IWorkbenchPropertyPage) ppage).setElement(adapt[0]); + } return ppage; } @@ -154,8 +157,9 @@ public IPreferencePage createPage(Object element) throws CoreException { */ private Object getAdaptedElement(Object element) { Object adapted = LegacyResourceSupport.getAdapter(element, getObjectClass()); - if (adapted != null) + if (adapted != null) { return adapted; + } return null; } @@ -220,11 +224,13 @@ public boolean isApplicableTo(Object object) { Object[] objs = getObjects(object); // If not a multi-select page not applicable to multiple selection - if (objs.length > 1 && !supportsMultiSelect) + if (objs.length > 1 && !supportsMultiSelect) { return false; + } - if (failsEnablement(objs)) + if (failsEnablement(objs)) { return false; + } // Test name filter String nameFilter = pageElement.getAttribute(PropertyPagesRegistryReader.ATT_NAME_FILTER); @@ -241,13 +247,15 @@ public boolean isApplicableTo(Object object) { objectName = elementName; } } - if (!SelectionEnabler.verifyNameMatch(objectName, nameFilter)) + if (!SelectionEnabler.verifyNameMatch(objectName, nameFilter)) { return false; + } } // Test custom filter - if (getFilterProperties() == null) + if (getFilterProperties() == null) { return true; + } IActionFilter filter = null; // Do the free IResource adapting @@ -258,8 +266,9 @@ public boolean isApplicableTo(Object object) { filter = Adapters.adapt(object, IActionFilter.class); - if (filter != null && !testCustom(object, filter)) + if (filter != null && !testCustom(object, filter)) { return false; + } } return true; @@ -273,8 +282,9 @@ public boolean isApplicableTo(Object object) { * @return boolean true if it fails the enablement test */ private boolean failsEnablement(Object[] objs) { - if (enablementExpression == null) + if (enablementExpression == null) { return false; + } try { // If multi-select property page, always pass a collection for iteration Object object = (supportsMultiSelect) ? Arrays.asList(objs) : objs[0]; @@ -295,8 +305,9 @@ private boolean failsEnablement(Object[] objs) { * @return an object array representing the passed in object */ private Object[] getObjects(Object obj) { - if (obj instanceof IStructuredSelection) + if (obj instanceof IStructuredSelection) { return ((IStructuredSelection) obj).toArray(); + } return new Object[] { obj }; } @@ -306,13 +317,15 @@ private Object[] getObjects(Object obj) { protected void initializeEnablement(IConfigurationElement definingElement) { IConfigurationElement[] elements = definingElement.getChildren(CHILD_ENABLED_WHEN); - if (elements.length == 0) + if (elements.length == 0) { return; + } try { IConfigurationElement[] enablement = elements[0].getChildren(); - if (enablement.length == 0) + if (enablement.length == 0) { return; + } enablementExpression = ExpressionConverter.getDefault().perform(enablement[0]); } catch (CoreException e) { WorkbenchPlugin.log(e); @@ -327,13 +340,15 @@ protected void initializeEnablement(IConfigurationElement definingElement) { private boolean testCustom(Object object, IActionFilter filter) { Map filterProperties = getFilterProperties(); - if (filterProperties == null) + if (filterProperties == null) { return false; + } for (Entry entry : filterProperties.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); - if (!filter.testAttribute(object, key, value)) + if (!filter.testAttribute(object, key, value)) { return false; + } } return true; } @@ -403,8 +418,9 @@ private void processChildElement(Map map, IConfigurationElement if (tag.equals(PropertyPagesRegistryReader.TAG_FILTER)) { String key = element.getAttribute(PropertyPagesRegistryReader.ATT_FILTER_NAME); String value = element.getAttribute(PropertyPagesRegistryReader.ATT_FILTER_VALUE); - if (key == null || value == null) + if (key == null || value == null) { return; + } map.put(key, value); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SavePerspectiveDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SavePerspectiveDialog.java index 8ff7dd417dc..f8a2ae22a08 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SavePerspectiveDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SavePerspectiveDialog.java @@ -55,7 +55,7 @@ public class SavePerspectiveDialog extends org.eclipse.jface.dialogs.Dialog private Button okButton; - private PerspectiveRegistry perspReg; + private final PerspectiveRegistry perspReg; private String perspName; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SelectPerspectiveDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SelectPerspectiveDialog.java index 0ed70431141..783e14b49af 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SelectPerspectiveDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SelectPerspectiveDialog.java @@ -68,9 +68,9 @@ public class SelectPerspectiveDialog extends Dialog implements ISelectionChanged private IPerspectiveDescriptor perspDesc; - private IPerspectiveRegistry perspReg; + private final IPerspectiveRegistry perspReg; - private ActivityViewerFilter activityViewerFilter = new ActivityViewerFilter(); + private final ActivityViewerFilter activityViewerFilter = new ActivityViewerFilter(); private Label descriptionHint; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ShowViewDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ShowViewDialog.java index f59b3daf2e0..9cd9825adc6 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ShowViewDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ShowViewDialog.java @@ -82,19 +82,19 @@ public class ShowViewDialog extends Dialog implements ISelectionChangedListener, private Button okButton; - private MApplication application; + private final MApplication application; private MPartDescriptor[] viewDescs = new MPartDescriptor[0]; private Label descriptionHint; - private IEclipseContext context; + private final IEclipseContext context; - private EModelService modelService; + private final EModelService modelService; - private MWindow window; + private final MWindow window; - private EPartService partService; + private final EPartService partService; /** * Constructs a new ShowViewDialog. @@ -307,11 +307,13 @@ protected void restoreWidgetValues() { IDialogSettings settings = getDialogSettings(); String[] expandedCategoryIds = settings.getArray(STORE_EXPANDED_CATEGORIES_ID); - if (expandedCategoryIds == null) + if (expandedCategoryIds == null) { return; + } - if (expandedCategoryIds.length > 0) + if (expandedCategoryIds.length > 0) { filteredTree.getViewer().setExpandedElements((Object[]) expandedCategoryIds); + } String selectedPartId = settings.get(STORE_SELECTED_VIEW_ID); if (selectedPartId != null) { @@ -336,10 +338,11 @@ protected void saveWidgetValues() { Object[] expandedElements = filteredTree.getViewer().getExpandedElements(); String[] expandedCategoryIds = new String[expandedElements.length]; for (int i = 0; i < expandedElements.length; ++i) { - if (expandedElements[i] instanceof MPartDescriptor) + if (expandedElements[i] instanceof MPartDescriptor) { expandedCategoryIds[i] = ((MPartDescriptor) expandedElements[i]).getElementId(); - else + } else { expandedCategoryIds[i] = expandedElements[i].toString(); + } } // Save them for next time. @@ -412,8 +415,9 @@ void handleTreeViewerKeyPressed(KeyEvent event) { if (o instanceof MPartDescriptor) { String description = ((MPartDescriptor) o).getTooltip(); description = LocalizationHelper.getLocalized(description, (MPartDescriptor) o, context); - if (description != null && description.isEmpty()) + if (description != null && description.isEmpty()) { description = WorkbenchMessages.ShowView_noDesc; + } popUp(description); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SimpleWorkingSetSelectionDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SimpleWorkingSetSelectionDialog.java index 7c91b7d4fbb..0b0c7d793b8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SimpleWorkingSetSelectionDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/SimpleWorkingSetSelectionDialog.java @@ -50,8 +50,9 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { } private boolean isCompatible(IWorkingSet set) { - if (set.isAggregateWorkingSet()) + if (set.isAggregateWorkingSet()) { return false; + } // original JDT code had the catch for self-updating sets that no // one can explain. There doesn't seem to @@ -61,15 +62,18 @@ private boolean isCompatible(IWorkingSet set) { // if (set.isAggregateWorkingSet() || !set.isSelfUpdating()) // return false; - if (!set.isVisible()) + if (!set.isVisible()) { return false; + } - if (!set.isEditable()) + if (!set.isEditable()) { return false; + } Set workingSetTypeIds = getSupportedWorkingSetIds(); - if (workingSetTypeIds == null) + if (workingSetTypeIds == null) { return true; + } for (String workingSetTypeId : workingSetTypeIds) { if (workingSetTypeId.equals(set.getId())) { return true; @@ -82,7 +86,7 @@ private boolean isCompatible(IWorkingSet set) { private CheckboxTableViewer viewer; - private IWorkingSet[] initialSelection; + private final IWorkingSet[] initialSelection; /** * Create a new instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewContentProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewContentProvider.java index b6642be0b85..836ac0765f3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewContentProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewContentProvider.java @@ -39,10 +39,10 @@ public class ViewContentProvider implements ITreeContentProvider { * Child cache. Map from Object->Object[]. Our hasChildren() method is expensive * so it's better to cache the results of getChildren(). */ - private Map childMap = new HashMap<>(); + private final Map childMap = new HashMap<>(); private MApplication application; - private IViewRegistry viewRegistry; + private final IViewRegistry viewRegistry; public ViewContentProvider(MApplication application) { this.application = application; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewLabelProvider.java index 81e928250ac..cb60a9e3b72 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewLabelProvider.java @@ -46,15 +46,15 @@ public class ViewLabelProvider extends ColumnLabelProvider { */ private static final String FOLDER_ICON = "org.eclipse.e4.descriptor.folder"; //$NON-NLS-1$ - private Map imageMap = new HashMap<>(); - private IEclipseContext context; + private final Map imageMap = new HashMap<>(); + private final IEclipseContext context; private final Color dimmedForeground; - private EModelService modelService; + private final EModelService modelService; - private MWindow window; + private final MWindow window; - private EPartService partService; + private final EPartService partService; /** * @param window the workbench window diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java index 774a0810664..af350f44b9b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java @@ -499,8 +499,9 @@ public String getText(Object element) { colorFontsDecorator.setImage(decorationImage); colorFontsDecorator.setDescriptionText(WorkbenchMessages.ThemeChangeWarningText); colorFontsDecorator.show(); - } else + } else { colorFontsDecorator.hide(); + } setColorsAndFontsTheme(colorsAndFontsTheme); }); } @@ -592,8 +593,8 @@ private ColorsAndFontsTheme getCurrentColorsAndFontsTheme() { } private static class ColorsAndFontsTheme { - private String label; - private String id; + private final String label; + private final String id; public ColorsAndFontsTheme(String id, String label) { this.id = id; @@ -615,12 +616,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } ColorsAndFontsTheme other = (ColorsAndFontsTheme) obj; return Objects.equals(id, other.id); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java index 68b4c454533..615fcf2287c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java @@ -42,13 +42,13 @@ * Instances also store a list of wizards. */ public class WizardCollectionElement extends AdaptableList implements IPluginContribution, IWizardCategory { - private String id; + private final String id; private String pluginId; private String name; - private WizardCollectionElement parent; + private final WizardCollectionElement parent; private AdaptableList wizards = new AdaptableList(); @@ -249,8 +249,9 @@ private IWizardDescriptor[] getWizardsExpression(IWizardDescriptor[] wizardDescr int size = wizardDescriptors.length; List result = new ArrayList<>(size); for (int i = 0; i < size; i++) { - if (!WorkbenchActivityHelper.restrictUseOf(wizardDescriptors[i])) + if (!WorkbenchActivityHelper.restrictUseOf(wizardDescriptors[i])) { result.add(wizardDescriptors[i]); + } } return result.toArray(new IWizardDescriptor[result.size()]); } @@ -279,8 +280,9 @@ private WorkbenchWizardElement[] getWorkbenchWizardElementsExpression( List result = new ArrayList<>(size); for (int i = 0; i < size; i++) { WorkbenchWizardElement element = workbenchWizardElements[i]; - if (!WorkbenchActivityHelper.restrictUseOf(element)) + if (!WorkbenchActivityHelper.restrictUseOf(element)) { result.add(element); + } } return result.toArray(new WorkbenchWizardElement[result.size()]); } @@ -303,10 +305,9 @@ public boolean equals(Object obj) { if (obj == this) { return true; } - if (!(obj instanceof WizardCollectionElement)) { + if (!(obj instanceof WizardCollectionElement other)) { return false; } - WizardCollectionElement other = (WizardCollectionElement) obj; return Objects.equals(this.getId(), other.getId()) && Objects.equals(this.name, other.name) && Objects.equals(this.getPluginId(), other.getPluginId()); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardContentProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardContentProvider.java index 47b1330b21e..dff1b36a78a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardContentProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardContentProvider.java @@ -34,10 +34,8 @@ public void dispose() { @Override public Object[] getChildren(Object parentElement) { - if (parentElement instanceof WizardCollectionElement) { + if (parentElement instanceof WizardCollectionElement element) { ArrayList list = new ArrayList(); - WizardCollectionElement element = (WizardCollectionElement) parentElement; - for (Object childCollection : element.getChildren()) { handleChild(childCollection, list); } @@ -47,8 +45,7 @@ public Object[] getChildren(Object parentElement) { } return list.toArray(); - } else if (parentElement instanceof AdaptableList) { - AdaptableList aList = (AdaptableList) parentElement; + } else if (parentElement instanceof AdaptableList aList) { Object[] children = aList.getChildren(); ArrayList list = new ArrayList(children.length); for (Object element : children) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardTagFilter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardTagFilter.java index ed7cb7c3ce0..8525645807e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardTagFilter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WizardTagFilter.java @@ -27,7 +27,7 @@ */ public class WizardTagFilter extends ViewerFilter { - private String[] myTags; + private final String[] myTags; /** * Create a new instance of this filter @@ -40,8 +40,7 @@ public WizardTagFilter(String[] tags) { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { - if (element instanceof IWizardDescriptor) { - IWizardDescriptor desc = (IWizardDescriptor) element; + if (element instanceof IWizardDescriptor desc) { for (String tag : desc.getTags()) { for (String myTag : myTags) { if (tag.equals(myTag)) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchEditorsDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchEditorsDialog.java index 4084dc88066..323e0b6ee22 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchEditorsDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchEditorsDialog.java @@ -75,7 +75,7 @@ */ public class WorkbenchEditorsDialog extends SelectionDialog { - private IWorkbenchWindow window; + private final IWorkbenchWindow window; private Table editorsTable; @@ -95,11 +95,11 @@ public class WorkbenchEditorsDialog extends SelectionDialog { private List elements = new ArrayList<>(); - private HashMap disabledImageCache = new HashMap<>(11); + private final HashMap disabledImageCache = new HashMap<>(11); private boolean reverse = false; - private Collator collator = Collator.getInstance(); + private final Collator collator = Collator.getInstance(); private Rectangle bounds; @@ -113,7 +113,7 @@ public class WorkbenchEditorsDialog extends SelectionDialog { private static final String COLUMNS = "columns"; //$NON-NLS-1$ - private SelectionListener headerListener = widgetSelectedAdapter(e -> { + private final SelectionListener headerListener = widgetSelectedAdapter(e -> { TableColumn column = (TableColumn) e.widget; int index = editorsTable.indexOf(column); if (index == sortColumn) { @@ -493,8 +493,9 @@ private void updateItem(TableItem item, Adapter editor) { item.setData(editor); item.setText(editor.getText()); Image image = editor.getImage(); - if (image != null) + if (image != null) { item.setImage(0, image); + } } /** diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchPreferenceManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchPreferenceManager.java index 3df78003187..fd17f8cd69b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchPreferenceManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchPreferenceManager.java @@ -67,8 +67,7 @@ public void addPages(Collection pageContributions) { Iterator iterator = pageContributions.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); - if (next instanceof WorkbenchPreferenceNode) { - WorkbenchPreferenceNode wNode = (WorkbenchPreferenceNode) next; + if (next instanceof WorkbenchPreferenceNode wNode) { addToRoot(wNode); registerNode(wNode); } @@ -131,8 +130,7 @@ private IExtensionPoint getExtensionPointFilter() { @Override public void removeExtension(IExtension extension, Object[] objects) { for (Object object : objects) { - if (object instanceof IPreferenceNode) { - IPreferenceNode wNode = (IPreferenceNode) object; + if (object instanceof IPreferenceNode wNode) { wNode.disposeResources(); deepRemove(getRoot(), wNode); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchWizardElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchWizardElement.java index 37c553a7615..3403d83b881 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchWizardElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchWizardElement.java @@ -45,13 +45,13 @@ */ public class WorkbenchWizardElement extends WorkbenchAdapter implements IAdaptable, IPluginContribution, IWizardDescriptor { - private String id; + private final String id; private ImageDescriptor imageDescriptor; private SelectionEnabler selectionEnabler; - private IConfigurationElement configurationElement; + private final IConfigurationElement configurationElement; private ImageDescriptor descriptionImage; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchWizardListSelectionPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchWizardListSelectionPage.java index b3df5f1e648..60aa79e3505 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchWizardListSelectionPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkbenchWizardListSelectionPage.java @@ -54,7 +54,7 @@ public abstract class WorkbenchWizardListSelectionPage extends WorkbenchWizardSe private TableViewer viewer; - private String message; + private final String message; /** * Creates a WorkbenchWizardListSelectionPage. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetEditWizard.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetEditWizard.java index 2e68940505f..4db2697fd72 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetEditWizard.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetEditWizard.java @@ -27,7 +27,7 @@ * @see org.eclipse.ui.dialogs.IWorkingSetPage */ public class WorkingSetEditWizard extends Wizard implements IWorkingSetEditWizard { - private IWorkingSetPage workingSetEditPage; + private final IWorkingSetPage workingSetEditPage; private IWorkingSet workingSet; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetFilter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetFilter.java index 8a66da35676..9a569d89a8d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetFilter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetFilter.java @@ -29,8 +29,7 @@ public WorkingSetFilter(Set workingSetIds) { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { - if (element instanceof IWorkingSet) { - IWorkingSet workingSet = (IWorkingSet) element; + if (element instanceof IWorkingSet workingSet) { String id = workingSet.getId(); // if (!workingSet.isVisible()) // return false; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetNewWizard.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetNewWizard.java index d634a4f13d2..3b39341705e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetNewWizard.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetNewWizard.java @@ -40,7 +40,7 @@ public class WorkingSetNewWizard extends Wizard implements IWorkingSetNewWizard private IWorkingSet workingSet; - private WorkingSetDescriptor[] descriptors; + private final WorkingSetDescriptor[] descriptors; /** * Creates a new instance of the receiver. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetSelectionDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetSelectionDialog.java index 143c8e43c5b..034f0558510 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetSelectionDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetSelectionDialog.java @@ -59,13 +59,13 @@ public class WorkingSetSelectionDialog extends AbstractWorkingSetDialog { private static final int SIZING_SELECTION_WIDGET_WIDTH = 50; - private ILabelProvider labelProvider; + private final ILabelProvider labelProvider; - private IStructuredContentProvider contentProvider; + private final IStructuredContentProvider contentProvider; private CheckboxTableViewer listViewer; - private boolean multiSelect; + private final boolean multiSelect; private IWorkbenchWindow workbenchWindow; @@ -229,8 +229,7 @@ protected Control createDialogArea(Composite parent) { listViewer.setCheckedElements(initialElementSelections.toArray()); } else if (!initialElementSelections.isEmpty()) { IWorkingSet set = (IWorkingSet) initialElementSelections.get(0); - if (set instanceof AggregateWorkingSet) { - AggregateWorkingSet aggregate = (AggregateWorkingSet) set; + if (set instanceof AggregateWorkingSet aggregate) { listViewer.setCheckedElements(aggregate.getComponents()); } else { listViewer.setCheckedElements(initialElementSelections.toArray()); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetTypePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetTypePage.java index 176bd690518..9fe027662b0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetTypePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/WorkingSetTypePage.java @@ -52,7 +52,7 @@ public class WorkingSetTypePage extends WizardPage { private TableViewer typesListViewer; - private WorkingSetDescriptor[] descriptors; + private final WorkingSetDescriptor[] descriptors; /** * Creates a new instance of the receiver @@ -111,7 +111,7 @@ public void createControl(Composite parent) { typesListViewer.addDoubleClickListener(event -> handleDoubleClick()); typesListViewer.setContentProvider(ArrayContentProvider.getInstance()); typesListViewer.setLabelProvider(new LabelProvider() { - private ResourceManager images = new LocalResourceManager(JFaceResources.getResources()); + private final ResourceManager images = new LocalResourceManager(JFaceResources.getResources()); @Override public String getText(Object element) { @@ -151,8 +151,9 @@ public void dispose() { */ public String getSelection() { WorkingSetDescriptor descriptor = getSelectedWorkingSet(); - if (descriptor != null) + if (descriptor != null) { return descriptor.getId(); + } return null; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/CustomizePerspectiveDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/CustomizePerspectiveDialog.java index 4f2a463f2c5..59508ce8c28 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/CustomizePerspectiveDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/CustomizePerspectiveDialog.java @@ -174,9 +174,9 @@ public class CustomizePerspectiveDialog extends TrayDialog { WorkbenchWindow window; - private WorkbenchPage windowPage; + private final WorkbenchPage windowPage; - private Perspective perspective; + private final Perspective perspective; private TabFolder tabFolder; @@ -187,7 +187,7 @@ public class CustomizePerspectiveDialog extends TrayDialog { private final String shortcutMenuColumnHeaders[] = { WorkbenchMessages.ActionSetSelection_menuColumnHeader, WorkbenchMessages.ActionSetSelection_descriptionColumnHeader }; - private int[] shortcutMenuColumnWidths = { 125, 300 }; + private final int[] shortcutMenuColumnWidths = { 125, 300 }; ImageDescriptor menuImageDescriptor; @@ -197,7 +197,7 @@ public class CustomizePerspectiveDialog extends TrayDialog { ImageDescriptor warningImageDescriptor; - private TreeManager treeManager; + private final TreeManager treeManager; private DisplayItem menuItems; @@ -215,7 +215,7 @@ public class CustomizePerspectiveDialog extends TrayDialog { private final List actionSets = new ArrayList<>(); - private IWorkbenchWindowConfigurer configurer; + private final IWorkbenchWindowConfigurer configurer; private TabItem actionSetTab; @@ -235,11 +235,11 @@ public class CustomizePerspectiveDialog extends TrayDialog { private CustomizeActionBars customizeActionBars; - private MenuManagerRenderer menuMngrRenderer; - private ToolBarManagerRenderer toolbarMngrRenderer; + private final MenuManagerRenderer menuMngrRenderer; + private final ToolBarManagerRenderer toolbarMngrRenderer; - private ISWTResourceUtilities resUtils; - private IEclipseContext context; + private final ISWTResourceUtilities resUtils; + private final IEclipseContext context; /** * Represents a menu item or a toolbar item. @@ -248,7 +248,7 @@ public class CustomizePerspectiveDialog extends TrayDialog { */ class DisplayItem extends TreeItem { /** The logic item represented */ - private IContributionItem item; + private final IContributionItem item; /** The action set this item belongs to (optional) */ ActionSet actionSet; @@ -286,7 +286,7 @@ public String toString() { * @since 3.5 */ class DynamicContributionItem extends DisplayItem { - private List preview; + private final List preview; public DynamicContributionItem(String label, IContributionItem item) { super(WorkbenchMessages.HideItems_dynamicItemName + " - " + label, item); //$NON-NLS-1$ @@ -344,7 +344,7 @@ class ShortcutItem extends DisplayItem { /** The category this shortcut is in (should be set) */ private Category category; - private Object descriptor; + private final Object descriptor; public ShortcutItem(String label, IWizardDescriptor descriptor) { super(label, CustomizePerspectiveDialog.getIContributionItem(descriptor, window)); @@ -393,7 +393,7 @@ public Category getCategory() { class Category extends TreeItem { /** ShortcutItems which are contributed in this Category */ - private List contributionItems; + private final List contributionItems; public Category(String label) { treeManager.super(label == null ? null : LegacyActionTools.removeMnemonics(removeShortcut(label))); @@ -463,7 +463,7 @@ class ActionSet { ActionSetDescriptor descriptor; /** ContributionItems contributed by this action set */ - private List contributionItems; + private final List contributionItems; private boolean active; @@ -651,8 +651,7 @@ private Composite createShortCutsPage(Composite parent) { treeManager.addListener(changedItem -> { if (changedItem instanceof Category) { menuCategoriesViewer.update(changedItem, null); - } else if (changedItem instanceof ShortcutItem) { - ShortcutItem item = (ShortcutItem) changedItem; + } else if (changedItem instanceof ShortcutItem item) { if (item.getCategory() != null) { item.getCategory().update(); updateCategoryAndParents(menuCategoriesViewer, item.getCategory()); @@ -720,7 +719,7 @@ public Object[] getChildren(Object parentElement) { tc.setText(shortcutMenuColumnHeaders[i]); tc.setWidth(columnWidths[i]); } - sashComposite.setWeights(new int[] { 30, 70 }); + sashComposite.setWeights(30, 70); menusViewer.setInput(shortcuts); @@ -877,7 +876,7 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { actionSetToolbarViewer.setInput(toolBarItems); }); - sashComposite.setWeights(new int[] { 30, 70 }); + sashComposite.setWeights(30, 70); return actionSetsComposite; } @@ -1008,7 +1007,7 @@ public void widgetSelected(SelectionEvent e) { }); book.showPage(simpleComposite); - advancedComposite.setWeights(new int[] { 30, 70 }); + advancedComposite.setWeights(30, 70); return hideMenuItemsComposite; } @@ -1143,7 +1142,7 @@ public void widgetSelected(SelectionEvent e) { }); book.showPage(simpleComposite); - advancedComposite.setWeights(new int[] { 30, 70 }); + advancedComposite.setWeights(30, 70); return hideToolbarItemsComposite; } @@ -1555,8 +1554,7 @@ private void loadMenuAndToolbarStructure() { MenuManager menuManager = customizeActionBars.menuManager; IContributionItem[] items = menuManager.getItems(); for (IContributionItem item : items) { - if (item instanceof ActionSetContributionItem) { - ActionSetContributionItem asci = (ActionSetContributionItem) item; + if (item instanceof ActionSetContributionItem asci) { menuManager.add(asci.getInnerItem()); } } @@ -1614,8 +1612,7 @@ static String getCommandID(DisplayItem item) { * @throws IllegalArgumentException if object is not one of the listed types */ public static String getIDFromIContributionItem(Object object) { - if (object instanceof ActionContributionItem) { - ActionContributionItem item = (ActionContributionItem) object; + if (object instanceof ActionContributionItem item) { IAction action = item.getAction(); if (action == null) { return null; @@ -1632,13 +1629,11 @@ public static String getIDFromIContributionItem(Object object) { } return action.getId(); } - if (object instanceof ActionSetContributionItem) { - ActionSetContributionItem item = (ActionSetContributionItem) object; + if (object instanceof ActionSetContributionItem item) { IContributionItem subitem = item.getInnerItem(); return getIDFromIContributionItem(subitem); } - if (object instanceof CommandContributionItem) { - CommandContributionItem item = (CommandContributionItem) object; + if (object instanceof CommandContributionItem item) { ParameterizedCommand command = item.getCommand(); if (command == null) { return null; @@ -1665,9 +1660,7 @@ public static String getIDFromIContributionItem(Object object) { } static String getParamID(DisplayItem object) { - if (object instanceof ShortcutItem) { - ShortcutItem shortcutItem = (ShortcutItem) object; - + if (object instanceof ShortcutItem shortcutItem) { if (isNewWizard(shortcutItem)) { ActionContributionItem item = (ActionContributionItem) object.getIContributionItem(); NewWizardShortcutAction nwsa = (NewWizardShortcutAction) item.getAction(); @@ -1891,8 +1884,7 @@ private DynamicContributionItem createMenuEntry(DisplayItem parent, DynamicContr } return dynamicEntry; - } else if (contributionItem instanceof CommandContributionItem) { - CommandContributionItem cci = (CommandContributionItem) contributionItem; + } else if (contributionItem instanceof CommandContributionItem cci) { CommandContributionItemParameter data = cci.getData(); DisplayItem menuEntry = new DisplayItem(data.label, contributionItem); menuEntry.setImageDescriptor(data.icon); @@ -1908,8 +1900,7 @@ private DynamicContributionItem createMenuEntry(DisplayItem parent, DynamicContr menuEntry.setCheckState(getMenuItemIsVisible(menuEntry)); parent.addChild(menuEntry); processedOpaqueItems.put(contributionItem, menuEntry); - } else if (contributionItem instanceof MenuManager) { - MenuManager manager = (MenuManager) contributionItem; + } else if (contributionItem instanceof MenuManager manager) { DisplayItem menuEntry = new DisplayItem(manager.getMenuText(), contributionItem); menuEntry.setImageDescriptor(manager.getImageDescriptor()); menuEntry.setActionSet(idToActionSet.get(getActionSetID(contributionItem))); @@ -1937,10 +1928,9 @@ private DynamicContributionItem createMenuEntry(DisplayItem parent, DynamicContr menuEntry.setActionSet(idToActionSet.get(getActionSetID(menuItem))); menuEntry.setCheckState(getMenuItemIsVisible(menuEntry)); parent.addChild(menuEntry); - } else if (menuItem instanceof MHandledMenuItem) { + } else if (menuItem instanceof MHandledMenuItem hmi) { IContributionItem contributionItem = menuMngrRenderer.getContribution(menuItem); - MHandledMenuItem hmi = (MHandledMenuItem) menuItem; String text = hmi.getLocalizedLabel(); if (text == null && hmi.getWbCommand() != null) { try { @@ -2010,10 +2000,9 @@ private DisplayItem createTrimBarEntries(MTrimBar trimBar) { return root; } for (MTrimElement trimElement : trimBar.getChildren()) { - if (!(trimElement instanceof MToolBar)) { + if (!(trimElement instanceof MToolBar toolBar)) { continue; } - MToolBar toolBar = (MToolBar) trimElement; ToolBarManager manager = toolbarMngrRenderer.getManager(toolBar); if (manager != null) { IContributionItem contributionItem = (IContributionItem) toolBar.getTransientData() @@ -2068,7 +2057,7 @@ private void createToolbarEntry(DisplayItem parent, MToolBarElement element) { if (element instanceof MItem) { text = getToolTipText((MItem) element); } - ImageDescriptor iconDescriptor = element instanceof MItem ? getIconDescriptor((MItem) element) : null; + ImageDescriptor iconDescriptor = element instanceof MItem m ? getIconDescriptor(m) : null; if (element.getWidget() instanceof ToolItem) { ToolItem item = (ToolItem) element.getWidget(); if (text == null) { @@ -2122,8 +2111,7 @@ private static ParameterizedCommand generateParameterizedCommand(final MHandledI private String getToolTipText(MItem item) { String text = item.getLocalizedTooltip(); - if (item instanceof MHandledItem) { - MHandledItem handledItem = (MHandledItem) item; + if (item instanceof MHandledItem handledItem) { EBindingService bs = context.get(EBindingService.class); ParameterizedCommand cmd = handledItem.getWbCommand(); if (cmd == null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/FilteredTreeCheckProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/FilteredTreeCheckProvider.java index 064ee6403b0..d201cf3f032 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/FilteredTreeCheckProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/FilteredTreeCheckProvider.java @@ -25,8 +25,8 @@ * @since 3.5 */ class FilteredTreeCheckProvider implements ICheckStateProvider { - private ITreeContentProvider contentProvider; - private ViewerFilter filter; + private final ITreeContentProvider contentProvider; + private final ViewerFilter filter; public FilteredTreeCheckProvider(ITreeContentProvider contentProvider, ViewerFilter filter) { this.contentProvider = contentProvider; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/FilteredViewerCheckListener.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/FilteredViewerCheckListener.java index 21cd6d90638..46e2d36b7a5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/FilteredViewerCheckListener.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/FilteredViewerCheckListener.java @@ -29,8 +29,8 @@ * @since 3.5 */ class FilteredViewerCheckListener implements ICheckStateListener { - private ITreeContentProvider contentProvider; - private ViewerFilter filter; + private final ITreeContentProvider contentProvider; + private final ViewerFilter filter; public FilteredViewerCheckListener(ITreeContentProvider contentProvider, ViewerFilter filter) { this.contentProvider = contentProvider; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/GrayOutUnavailableLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/GrayOutUnavailableLabelProvider.java index c553242fe0e..0e1739ab362 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/GrayOutUnavailableLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/GrayOutUnavailableLabelProvider.java @@ -36,9 +36,9 @@ * @since 3.5 */ class GrayOutUnavailableLabelProvider extends TreeManager.TreeItemLabelProvider implements IColorProvider { - private Display display; - private ViewerFilter filter; - private Set toDispose; + private final Display display; + private final ViewerFilter filter; + private final Set toDispose; public GrayOutUnavailableLabelProvider(ViewerFilter filter) { this.display = PlatformUI.getWorkbench().getDisplay(); @@ -70,8 +70,7 @@ public Color getForeground(Object element) { public Image getImage(Object element) { Image actual = super.getImage(element); - if (element instanceof DisplayItem && actual != null) { - DisplayItem item = (DisplayItem) element; + if (element instanceof DisplayItem item && actual != null) { if (!CustomizePerspectiveDialog.isEffectivelyAvailable(item, filter)) { ImageDescriptor original = ImageDescriptor.createFromImage(actual); ImageDescriptor disable = ImageDescriptor.createWithFlags(original, SWT.IMAGE_DISABLE); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/ItemDetailToolTip.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/ItemDetailToolTip.java index e8fef54727e..f494dc8fdfc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/ItemDetailToolTip.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/ItemDetailToolTip.java @@ -65,12 +65,12 @@ * @since 3.5 */ class ItemDetailToolTip extends NameAndDescriptionToolTip { - private Tree tree; - private boolean showActionSet; - private boolean showKeyBindings; - private ViewerFilter filter; - private TreeViewer v; - private CustomizePerspectiveDialog dialog; + private final Tree tree; + private final boolean showActionSet; + private final boolean showKeyBindings; + private final ViewerFilter filter; + private final TreeViewer v; + private final CustomizePerspectiveDialog dialog; /** * @param tree The tree for the tooltip to hover over @@ -275,8 +275,7 @@ public void widgetSelected(SelectionEvent e) { } // Show dynamic menu item info - if (item instanceof DynamicContributionItem) { - DynamicContributionItem dynamic = ((DynamicContributionItem) item); + if (item instanceof DynamicContributionItem dynamic) { StringBuilder text = new StringBuilder(); final List currentItems = dynamic.getCurrentItems(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/NameAndDescriptionToolTip.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/NameAndDescriptionToolTip.java index f4b53b74608..9994fd8530e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/NameAndDescriptionToolTip.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/NameAndDescriptionToolTip.java @@ -178,16 +178,14 @@ protected Link createEntryWithLink(Composite parent, Image icon, String text) { abstract protected void addContent(Composite destination, Object modelElement); static String getDescription(IContributionItem item) { - if (item instanceof ActionContributionItem) { - ActionContributionItem aci = (ActionContributionItem) item; + if (item instanceof ActionContributionItem aci) { IAction action = aci.getAction(); if (action == null) { return null; } return action.getDescription(); } - if (item instanceof ActionSetContributionItem) { - ActionSetContributionItem asci = (ActionSetContributionItem) item; + if (item instanceof ActionSetContributionItem asci) { IContributionItem subitem = asci.getInnerItem(); return getDescription(subitem); } @@ -195,9 +193,7 @@ static String getDescription(IContributionItem item) { } static String getDescription(Object object) { - if (object instanceof DisplayItem) { - DisplayItem item = (DisplayItem) object; - + if (object instanceof DisplayItem item) { if (CustomizePerspectiveDialog.isNewWizard(item)) { ShortcutItem shortcut = (ShortcutItem) item; IWizardDescriptor descriptor = (IWizardDescriptor) shortcut.getDescriptor(); @@ -224,8 +220,7 @@ static String getDescription(Object object) { return NameAndDescriptionToolTip.getDescription(contrib); } - if (object instanceof ActionSet) { - ActionSet actionSet = (ActionSet) object; + if (object instanceof ActionSet actionSet) { return actionSet.descriptor.getDescription(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/ShowUsedActionSetsFilter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/ShowUsedActionSetsFilter.java index ca58725c46a..aa76b5d26df 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/ShowUsedActionSetsFilter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/ShowUsedActionSetsFilter.java @@ -25,7 +25,7 @@ * @since 3.5 */ final class ShowUsedActionSetsFilter extends ViewerFilter { - private DisplayItem rootItem; + private final DisplayItem rootItem; public ShowUsedActionSetsFilter(DisplayItem rootItem) { this.rootItem = rootItem; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/TableToolTip.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/TableToolTip.java index e4698849f01..966fd2394b5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/TableToolTip.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/TableToolTip.java @@ -26,7 +26,7 @@ * @since 3.5 */ class TableToolTip extends NameAndDescriptionToolTip { - private Table table; + private final Table table; public TableToolTip(Table table) { super(table, RECREATE); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/TreeManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/TreeManager.java index f61793be529..2ed36978687 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/TreeManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/TreeManager.java @@ -81,7 +81,7 @@ public interface CheckListener { * {@link CheckboxTreeViewer}. */ public static class ModelListenerForCheckboxTree implements CheckListener { - private CheckboxTreeViewer treeViewer; + private final CheckboxTreeViewer treeViewer; public ModelListenerForCheckboxTree(TreeManager manager, CheckboxTreeViewer treeViewer) { this.treeViewer = treeViewer; @@ -99,7 +99,7 @@ public void checkChanged(TreeItem changedItem) { * {@link CheckboxTableViewer}. */ public static class ModelListenerForCheckboxTable implements CheckListener { - private CheckboxTableViewer tableViewer; + private final CheckboxTableViewer tableViewer; public ModelListenerForCheckboxTable(TreeManager manager, CheckboxTableViewer tableViewer) { this.tableViewer = tableViewer; @@ -222,8 +222,9 @@ public static IBaseLabelProvider getLabelProvider() { * content in tree format. */ public static ITreeContentProvider getTreeContentProvider() { - if (treeContentProvider == null) + if (treeContentProvider == null) { treeContentProvider = new TreeItemContentProvider(); + } return treeContentProvider; } @@ -232,8 +233,9 @@ public static ITreeContentProvider getTreeContentProvider() { * {@link CheckStateChangedEvent}s by updating the model to reflect them */ public ICheckStateListener getViewerCheckStateListener() { - if (viewerCheckListener == null) + if (viewerCheckListener == null) { viewerCheckListener = new ViewerCheckStateListener(); + } return viewerCheckListener; } @@ -245,7 +247,7 @@ public class TreeItem { private ImageDescriptor imageDescriptor; private Image image; private TreeItem parent; - private List children; + private final List children; private int checkState; private boolean changedByUser; @@ -299,8 +301,9 @@ public TreeItem getParent() { * any iterative synchronization to take place. */ private void internalSetCheckState(int newState) { - if (newState == checkState) + if (newState == checkState) { return; + } checkState = newState; fireListeners(this); @@ -313,8 +316,9 @@ private void internalSetCheckState(int newState) { */ public void setCheckState(boolean checked) { int newState = checked ? CHECKSTATE_CHECKED : CHECKSTATE_UNCHECKED; - if (checkState == newState) + if (checkState == newState) { return; + } // Actually set the state and fire the CheckChangeEvent internalSetCheckState(newState); @@ -365,8 +369,9 @@ private void synchChildren(TreeItem changedItem) { * */ private void synchParents(TreeItem changedItem) { - if (changedItem.parent == null) + if (changedItem.parent == null) { return; + } int newState = changedItem.checkState; @@ -468,10 +473,12 @@ public void addListener(CheckListener listener) { * @return The created {@link CheckListener}. */ public CheckListener getCheckListener(ICheckable viewer) { - if (viewer instanceof CheckboxTreeViewer) + if (viewer instanceof CheckboxTreeViewer) { return new ModelListenerForCheckboxTree(this, (CheckboxTreeViewer) viewer); - if (viewer instanceof CheckboxTableViewer) + } + if (viewer instanceof CheckboxTableViewer) { return new ModelListenerForCheckboxTable(this, (CheckboxTableViewer) viewer); + } return null; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/UnavailableContributionItemCheckListener.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/UnavailableContributionItemCheckListener.java index 1aaf3a677ce..9e6cb7ebe8f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/UnavailableContributionItemCheckListener.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/cpd/UnavailableContributionItemCheckListener.java @@ -38,8 +38,8 @@ class UnavailableContributionItemCheckListener implements ICheckStateListener { private final CustomizePerspectiveDialog dialog; - private CheckboxTreeViewer viewer; - private ICheckStateListener originalListener; + private final CheckboxTreeViewer viewer; + private final ICheckStateListener originalListener; /** * @param viewer the viewer being listened to @@ -101,8 +101,7 @@ public void checkStateChanged(CheckStateChangedEvent event) { WorkbenchMessages.HideItemsCannotMakeVisible_unavailableCommandGroupText, item.getLabel(), item.getActionSet()); final String message = NLS.bind("{0}{1}{1}{2}", //$NON-NLS-1$ - new Object[] { errorExplanation, CustomizePerspectiveDialog.NEW_LINE, - WorkbenchMessages.HideItemsCannotMakeVisible_switchToCommandGroupTab }); + errorExplanation, CustomizePerspectiveDialog.NEW_LINE, WorkbenchMessages.HideItemsCannotMakeVisible_switchToCommandGroupTab); mb.setMessage(message); } if (mb.open() == SWT.YES) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ActionBars.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ActionBars.java index 8ecee77f177..71c0c29ddc2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ActionBars.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ActionBars.java @@ -37,7 +37,7 @@ public class ActionBars extends SubActionBars { private IMenuManager menuManager; - private MPart part; + private final MPart part; public ActionBars(final IActionBars parent, final IServiceLocator serviceLocator, MPart part) { super(parent, serviceLocator); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityEditor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityEditor.java index bc22035b669..ad1c546fd30 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityEditor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityEditor.java @@ -45,7 +45,7 @@ public class CompatibilityEditor extends CompatibilityPart { public static final String MODEL_ELEMENT_ID = "org.eclipse.e4.ui.compatibility.editor"; //$NON-NLS-1$ - private EditorReference reference; + private final EditorReference reference; @Inject private EModelService modelService; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java index 1f11899bf7c..705ecb41c8c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java @@ -96,7 +96,7 @@ public abstract class CompatibilityPart implements ISelectionChangedListener { /** * This handler will be notified when the part's widget has been un/set. */ - private EventHandler widgetSetHandler = event -> { + private final EventHandler widgetSetHandler = event -> { // check that we're looking at our own part and that the widget is // being unset if (event.getProperty(UIEvents.EventTags.ELEMENT) == part @@ -118,7 +118,7 @@ public abstract class CompatibilityPart implements ISelectionChangedListener { /** * This handler will be notified when the part's client object has been un/set. */ - private EventHandler objectSetHandler = event -> { + private final EventHandler objectSetHandler = event -> { // check that we're looking at our own part and that the object is // being set if (event.getProperty(UIEvents.EventTags.ELEMENT) == part @@ -129,7 +129,7 @@ public abstract class CompatibilityPart implements ISelectionChangedListener { } }; - private ISelectionChangedListener postListener = e -> { + private final ISelectionChangedListener postListener = e -> { ESelectionService selectionService = part.getContext().get(ESelectionService.class); selectionService.setPostSelection(e.getSelection()); }; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java index 5156b3da489..9874e793469 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java @@ -61,7 +61,7 @@ public class CompatibilityView extends CompatibilityPart { - private ViewReference reference; + private final ViewReference reference; @Inject EModelService modelService; @@ -123,8 +123,7 @@ protected boolean createPartControl(IWorkbenchPart legacyPart, Composite parent) } AbstractPartRenderer apr = rendererFactory.getRenderer(menu, parent); - if (apr instanceof MenuManagerRenderer) { - MenuManagerRenderer renderer = (MenuManagerRenderer) apr; + if (apr instanceof MenuManagerRenderer renderer) { renderer.linkModelToManager(menu, mm); } @@ -164,8 +163,7 @@ protected boolean createPartControl(IWorkbenchPart legacyPart, Composite parent) toolBarParent.dispose(); apr = rendererFactory.getRenderer(menu, parent); - if (apr instanceof MenuManagerRenderer) { - MenuManagerRenderer renderer = (MenuManagerRenderer) apr; + if (apr instanceof MenuManagerRenderer renderer) { // create opaque items for any contribution items that were added // directly to the manager renderer.reconcileManagerToModel(mm, menu); @@ -241,8 +239,7 @@ public static void clearOpaqueMenuItems(MenuManagerRenderer renderer, MMenu menu } else if (OpaqueElementUtil.isOpaqueMenuItem(child)) { OpaqueElementUtil.clearOpaqueItem(child); it.remove(); - } else if (child instanceof MMenu) { - MMenu submenu = (MMenu) child; + } else if (child instanceof MMenu submenu) { MenuManager manager = renderer.getManager(submenu); if (manager != null) { renderer.clearModelToManager(submenu, manager); @@ -265,8 +262,7 @@ void disposeSite(PartSite site) { for (MMenu menu : part.getMenus()) { if (menu.getTags().contains(StackRenderer.TAG_VIEW_MENU)) { AbstractPartRenderer apr = rendererFactory.getRenderer(menu, null); - if (apr instanceof MenuManagerRenderer) { - MenuManagerRenderer renderer = (MenuManagerRenderer) apr; + if (apr instanceof MenuManagerRenderer renderer) { MenuManager mm = (MenuManager) actionBars.getMenuManager(); renderer.clearModelToManager(menu, mm); clearOpaqueMenuItems(renderer, menu); @@ -278,9 +274,8 @@ void disposeSite(PartSite site) { MToolBar toolbar = part.getToolbar(); if (toolbar != null) { AbstractPartRenderer apr = rendererFactory.getRenderer(toolbar, null); - if (apr instanceof ToolBarManagerRenderer) { + if (apr instanceof ToolBarManagerRenderer tbmr) { ToolBarManager tbm = (ToolBarManager) actionBars.getToolBarManager(); - ToolBarManagerRenderer tbmr = (ToolBarManagerRenderer) apr; tbmr.clearModelToManager(toolbar, tbm); clearOpaqueToolBarItems(tbmr, toolbar); } @@ -293,10 +288,9 @@ void disposeSite(PartSite site) { private static void clearMenuServiceContributions(PartSite site, MPart part) { IMenuService menuService = site.getService(IMenuService.class); - if (!(menuService instanceof IMenuServiceWorkaround)) { + if (!(menuService instanceof IMenuServiceWorkaround service)) { return; } - IMenuServiceWorkaround service = (IMenuServiceWorkaround) menuService; service.clearContributions(site, part); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/E4Util.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/E4Util.java index 4c36c31ce7b..c505dc56b1c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/E4Util.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/E4Util.java @@ -26,24 +26,27 @@ public class E4Util { static { WorkbenchPlugin activator = WorkbenchPlugin.getDefault(); - if (activator == null) + if (activator == null) { DEBUG_E4 = false; - else { + } else { DebugOptions debugOptions = activator.getDebugOptions(); - if (debugOptions == null) + if (debugOptions == null) { DEBUG_E4 = false; - else + } else { DEBUG_E4 = debugOptions.getBooleanOption(OPTION_DEBUG_E4, false); + } } } public static void unsupported(String msg) throws UnsupportedOperationException { - if (DEBUG_E4) + if (DEBUG_E4) { WorkbenchPlugin.log("unsupported: " + msg); //$NON-NLS-1$ + } } public static void message(String msg) throws UnsupportedOperationException { - if (DEBUG_E4) + if (DEBUG_E4) { WorkbenchPlugin.log(msg); + } } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledFolderLayout.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledFolderLayout.java index 37035bbf8f4..60cdc1e1e24 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledFolderLayout.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledFolderLayout.java @@ -40,8 +40,9 @@ public void addView(String viewId) { } folderModel.setToBeRendered(true); boolean isFiltered = layout.isViewFiltered(viewId); - if (isFiltered) + if (isFiltered) { layout.addViewActivator(viewModel); + } viewModel.setToBeRendered(!isFiltered); folderModel.getChildren().add(viewModel); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java index 63791bf196d..9d717260f8d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java @@ -98,27 +98,27 @@ public static List getIds(MPerspective model, String tagPrefix) { return result; } - private MApplication application; + private final MApplication application; // private MWindow window; - private EModelService modelService; + private final EModelService modelService; EPartService partService; WorkbenchPage page; MPerspective perspModel; - private IPerspectiveDescriptor descriptor; + private final IPerspectiveDescriptor descriptor; - private MPlaceholder eaRef; + private final MPlaceholder eaRef; private MPartStack editorStack; boolean createReferences; - private IViewRegistry viewRegistry; + private final IViewRegistry viewRegistry; - private ModeledPageLayoutUtils layoutUtils; + private final ModeledPageLayoutUtils layoutUtils; private static class ViewActivator implements IIdentifierListener { - private MUIElement element; + private final MUIElement element; public ViewActivator(MUIElement element) { this.element = element; @@ -129,8 +129,9 @@ public void identifierChanged(IdentifierEvent identifierEvent) { IIdentifier identifier = identifierEvent.getIdentifier(); // Not activated, do nothing - if (!identifier.isEnabled()) + if (!identifier.isEnabled()) { return; + } // stop listening for activations identifier.removeIdentifierListener(this); @@ -249,8 +250,7 @@ public void addShowViewShortcut(String id) { @Override public void addStandaloneView(String viewId, boolean showTitle, int relationship, float ratio, String refId) { MUIElement newElement = insertView(viewId, relationship, ratio, refId, true, showTitle); - if (newElement instanceof MPartStack) { - MPartStack stack = (MPartStack) newElement; + if (newElement instanceof MPartStack stack) { stack.getTags().add(IPresentationEngine.STANDALONE); stack.getChildren().get(0).getTags().add(IPresentationEngine.NO_MOVE); } else { @@ -262,8 +262,7 @@ public void addStandaloneView(String viewId, boolean showTitle, int relationship public void addStandaloneViewPlaceholder(String viewId, int relationship, float ratio, String refId, boolean showTitle) { MUIElement newElement = insertView(viewId, relationship, ratio, refId, false, showTitle); - if (newElement instanceof MPartStack) { - MPartStack stack = (MPartStack) newElement; + if (newElement instanceof MPartStack stack) { stack.getTags().add(IPresentationEngine.STANDALONE); stack.getChildren().get(0).getTags().add(IPresentationEngine.NO_MOVE); } else { @@ -285,10 +284,12 @@ public void addView(String viewId, int relationship, float ratio, String refId, protected boolean isViewFiltered(String viewID) { IViewDescriptor viewDescriptor = viewRegistry.find(viewID); - if (viewDescriptor == null) + if (viewDescriptor == null) { return false; - if (WorkbenchActivityHelper.restrictUseOf(viewDescriptor)) + } + if (WorkbenchActivityHelper.restrictUseOf(viewDescriptor)) { return true; + } return WorkbenchActivityHelper.filterItem(viewDescriptor); } @@ -335,12 +336,14 @@ public int getEditorReuseThreshold() { @Override public IPlaceholderFolderLayout getFolderForView(String id) { MPart view = findPart(perspModel, id); - if (view == null) + if (view == null) { return null; + } MUIElement stack = view.getParent(); - if (stack == null || !(stack instanceof MPartStack)) + if (stack == null || !(stack instanceof MPartStack)) { return null; + } return new ModeledPlaceholderFolderLayout(this, application, (MPartStack) stack); } @@ -348,12 +351,14 @@ public IPlaceholderFolderLayout getFolderForView(String id) { @Override public IViewLayout getViewLayout(String id) { MPart view = findPart(perspModel, id); - if (view != null) + if (view != null) { return new ModeledViewLayout(view); + } MPlaceholder placeholder = findPlaceholder(perspModel, id); - if (placeholder != null) + if (placeholder != null) { return new ModeledViewLayout(placeholder); + } return null; } @@ -454,8 +459,7 @@ private MUIElement findRefModel(String refId) { } private MUIElement getLastElement(MUIElement element) { - if (element instanceof MElementContainer) { - MElementContainer container = (MElementContainer) element; + if (element instanceof MElementContainer container) { List children = container.getChildren(); return children.isEmpty() ? container : getLastElement((MUIElement) children.get(children.size() - 1)); } @@ -516,24 +520,28 @@ private MPartStack insertStack(String stackId, int relationship, float ratio, St } public static void replace(MUIElement relTo, MElementContainer newParent) { - if (relTo == null || newParent == null) + if (relTo == null || newParent == null) { return; + } MElementContainer parent = relTo.getParent(); - if (parent == null) + if (parent == null) { return; + } List kids = parent.getChildren(); - if (kids == null) + if (kids == null) { return; + } kids.add(kids.indexOf(relTo), newParent); kids.remove(relTo); } public static void insertParent(MElementContainer newParent, MUIElement relTo) { - if (newParent == null || relTo == null) + if (newParent == null || relTo == null) { return; + } MPart curParent = (MPart) relTo.getParent(); if (curParent != null) { @@ -546,20 +554,21 @@ public static void insertParent(MElementContainer newParent, MUIElem MUIElement findElement(MUIElement toSearch, String id) { List found = modelService.findElements(toSearch, id, null, null, EModelService.IN_ANY_PERSPECTIVE); - if (found.size() > 0) + if (found.size() > 0) { return (MUIElement) found.get(0); + } return modelService.find(id, toSearch); } private MPart findPart(MUIElement toSearch, String id) { MUIElement element = modelService.find(id, toSearch); - return element instanceof MPart ? (MPart) element : null; + return element instanceof MPart m ? m : null; } private MPlaceholder findPlaceholder(MUIElement toSearch, String id) { MUIElement element = modelService.find(id, toSearch); - return element instanceof MPlaceholder ? (MPlaceholder) element : null; + return element instanceof MPlaceholder m ? m : null; } public void addHiddenMenuItemId(String id) { @@ -642,12 +651,14 @@ public void setEditorOnboardingImageUri(String iconUri) { public void addEditorOnboardingCommandId(String commandId) { long numberOfOnboardingCommands = perspModel.getTags().stream() .filter(t -> t.startsWith(EDITOR_ONBOARDING_COMMAND)).count(); - if (numberOfOnboardingCommands >= 5) + if (numberOfOnboardingCommands >= 5) { return; + } IContributionFactory contributionFactory = application.getContext().get(IContributionFactory.class); - if (!contributionFactory.isEnabled(commandId)) + if (!contributionFactory.isEnabled(commandId)) { return; + } Predicate commandWithEqualId = b -> Optional.of(b).map(MKeyBinding::getCommand) .map(MCommand::getElementId).filter(elementId -> elementId.equals(commandId)).isPresent(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayoutUtils.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayoutUtils.java index 429325f78df..43f5761b000 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayoutUtils.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayoutUtils.java @@ -26,7 +26,7 @@ public class ModeledPageLayoutUtils { - private EModelService modelService; + private final EModelService modelService; public ModeledPageLayoutUtils(EModelService modelService) { this.modelService = modelService; @@ -53,8 +53,9 @@ public void insert(MUIElement toInsert, MUIElement relTo, int swtSide, float rat } public void insert(MUIElement toInsert, MUIElement relTo, int swtSide, int ratio) { - if (toInsert == null || relTo == null) + if (toInsert == null || relTo == null) { return; + } MElementContainer relParent = relTo.getParent(); if (relParent != null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledViewLayout.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledViewLayout.java index 36de99fe7a4..c678b15e91d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledViewLayout.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/ModeledViewLayout.java @@ -22,7 +22,7 @@ import org.eclipse.ui.IViewLayout; public class ModeledViewLayout implements IViewLayout { - private MUIElement viewME; + private final MUIElement viewME; public ModeledViewLayout(MPart view) { viewME = view; @@ -55,18 +55,20 @@ public boolean isStandalone() { @Override public void setCloseable(boolean closeable) { - if (closeable) + if (closeable) { viewME.getTags().remove(IPresentationEngine.NO_CLOSE); - else + } else { viewME.getTags().add(IPresentationEngine.NO_CLOSE); + } } @Override public void setMoveable(boolean moveable) { - if (moveable) + if (moveable) { viewME.getTags().remove(IPresentationEngine.NO_MOVE); - else + } else { viewME.getTags().add(IPresentationEngine.NO_MOVE); + } } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/SelectionService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/SelectionService.java index 3f61f67ea33..4a4c9199d36 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/SelectionService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/SelectionService.java @@ -63,21 +63,21 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe private IWorkbenchPart activePart; - private ListenerList listeners = new ListenerList<>(); - private ListenerList postSelectionListeners = new ListenerList<>(); - private Map> targetedListeners = new HashMap<>(); - private Map> targetedPostSelectionListeners = new HashMap<>(); + private final ListenerList listeners = new ListenerList<>(); + private final ListenerList postSelectionListeners = new ListenerList<>(); + private final Map> targetedListeners = new HashMap<>(); + private final Map> targetedPostSelectionListeners = new HashMap<>(); - private org.eclipse.e4.ui.workbench.modeling.ISelectionListener listener = (part, + private final org.eclipse.e4.ui.workbench.modeling.ISelectionListener listener = (part, selection) -> handleSelectionChanged(part, selection, false); - private org.eclipse.e4.ui.workbench.modeling.ISelectionListener targetedListener = (part, + private final org.eclipse.e4.ui.workbench.modeling.ISelectionListener targetedListener = (part, selection) -> handleSelectionChanged(part, selection, true); - private org.eclipse.e4.ui.workbench.modeling.ISelectionListener postListener = (part, + private final org.eclipse.e4.ui.workbench.modeling.ISelectionListener postListener = (part, selection) -> handlePostSelectionChanged(part, selection, false); - private org.eclipse.e4.ui.workbench.modeling.ISelectionListener targetedPostListener = (part, + private final org.eclipse.e4.ui.workbench.modeling.ISelectionListener targetedPostListener = (part, selection) -> handlePostSelectionChanged(part, selection, true); private void handleSelectionChanged(MPart part, Object selection, boolean targeted) { @@ -205,13 +205,11 @@ void subscribeTopicDirtyChanged(@UIEventTopic(UIEvents.Dirtyable.TOPIC_DIRTY) Ev Object objElement = event.getProperty(UIEvents.EventTags.ELEMENT); // Ensure that this event is for a MMenuItem - if (!(objElement instanceof MPart)) { + if (!(objElement instanceof MPart part)) { return; } - MPart part = (MPart) objElement; Object wrapperPart = part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY); - if (wrapperPart instanceof E4PartWrapper) { - E4PartWrapper wrapper = (E4PartWrapper) wrapperPart; + if (wrapperPart instanceof E4PartWrapper wrapper) { try { wrapper.addPropertyListener(AbstractSaveHandler.getDirtyStateTracker()); } catch (IllegalArgumentException e) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/migration/PerspectiveBuilder.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/migration/PerspectiveBuilder.java index c035d2e775c..48d9c8dd362 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/migration/PerspectiveBuilder.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/migration/PerspectiveBuilder.java @@ -78,7 +78,7 @@ public class PerspectiveBuilder { private List defaultFastViews; - private Map viewPlaceholders = new HashMap<>(); + private final Map viewPlaceholders = new HashMap<>(); private Map viewLayouts; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/ActivePartExpression.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/ActivePartExpression.java index 3d604c46952..9cac357cc34 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/ActivePartExpression.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/ActivePartExpression.java @@ -70,8 +70,7 @@ protected int computeHashCode() { @Override public boolean equals(final Object object) { - if (object instanceof ActivePartExpression) { - final ActivePartExpression that = (ActivePartExpression) object; + if (object instanceof final ActivePartExpression that) { return equals(this.activePart, that.activePart); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyActionSetExpression.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyActionSetExpression.java index b3c2bf8bb60..d272a779be1 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyActionSetExpression.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyActionSetExpression.java @@ -67,8 +67,7 @@ public void collectExpressionInfo(final ExpressionInfo info) { @Override public boolean equals(final Object object) { - if (object instanceof LegacyActionSetExpression) { - final LegacyActionSetExpression that = (LegacyActionSetExpression) object; + if (object instanceof final LegacyActionSetExpression that) { return equals(this.actionSetId, that.actionSetId) && equals(this.getWindow(), that.getWindow()); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyEditorActionBarExpression.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyEditorActionBarExpression.java index 1098368fbd2..e705f890e7c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyEditorActionBarExpression.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyEditorActionBarExpression.java @@ -72,8 +72,7 @@ protected final int computeHashCode() { @Override public final boolean equals(final Object object) { - if (object instanceof LegacyEditorActionBarExpression) { - final LegacyEditorActionBarExpression that = (LegacyEditorActionBarExpression) object; + if (object instanceof final LegacyEditorActionBarExpression that) { return activeEditorId.equals(that.activeEditorId); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyEditorContributionExpression.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyEditorContributionExpression.java index 30ca472cfa3..b8ebcadf65d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyEditorContributionExpression.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyEditorContributionExpression.java @@ -77,8 +77,7 @@ protected int computeHashCode() { @Override public boolean equals(final Object object) { - if (object instanceof LegacyEditorContributionExpression) { - final LegacyEditorContributionExpression that = (LegacyEditorContributionExpression) object; + if (object instanceof final LegacyEditorContributionExpression that) { return equals(this.activeEditorId, that.activeEditorId) && equals(this.getWindow(), that.getWindow()); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacySelectionEnablerWrapper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacySelectionEnablerWrapper.java index 0132ab4d51a..9500210c2e9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacySelectionEnablerWrapper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacySelectionEnablerWrapper.java @@ -79,8 +79,7 @@ protected int computeHashCode() { @Override public boolean equals(final Object object) { - if (object instanceof LegacySelectionEnablerWrapper) { - final LegacySelectionEnablerWrapper that = (LegacySelectionEnablerWrapper) object; + if (object instanceof final LegacySelectionEnablerWrapper that) { return equals(this.enabler, that.enabler) && equals(this.getWindow(), that.getWindow()); } @@ -95,8 +94,7 @@ public EvaluationResult evaluate(final IEvaluationContext context) throws CoreEx } final Object defaultVariable = context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); - if (defaultVariable instanceof ISelection) { - final ISelection selection = (ISelection) defaultVariable; + if (defaultVariable instanceof final ISelection selection) { if (enabler.isEnabledForSelection(selection)) { return EvaluationResult.TRUE; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyViewContributionExpression.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyViewContributionExpression.java index ac680afb80c..c2c03384ad2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyViewContributionExpression.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/LegacyViewContributionExpression.java @@ -77,8 +77,7 @@ protected int computeHashCode() { @Override public boolean equals(final Object object) { - if (object instanceof LegacyViewContributionExpression) { - final LegacyViewContributionExpression that = (LegacyViewContributionExpression) object; + if (object instanceof final LegacyViewContributionExpression that) { return equals(this.activePartId, that.activePartId) && equals(this.getWindow(), that.getWindow()); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/WorkbenchWindowExpression.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/WorkbenchWindowExpression.java index 8a3a106ce50..3e88b621311 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/WorkbenchWindowExpression.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/expressions/WorkbenchWindowExpression.java @@ -69,8 +69,7 @@ protected int computeHashCode() { @Override public boolean equals(final Object object) { - if (object instanceof WorkbenchWindowExpression) { - final WorkbenchWindowExpression that = (WorkbenchWindowExpression) object; + if (object instanceof final WorkbenchWindowExpression that) { return equals(this.window, that.window); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ActionDelegateHandlerProxy.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ActionDelegateHandlerProxy.java index 8cf0f5aaa74..77cd16c24aa 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ActionDelegateHandlerProxy.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ActionDelegateHandlerProxy.java @@ -84,13 +84,13 @@ public final class ActionDelegateHandlerProxy implements ISelectionListener, ISe * The identifier of the actions to create as a wrapper to the command * architecture. This value may be null. */ - private String actionId; + private final String actionId; /** * The command that will back the dummy actions exposed to this delegate. This * value is never null. */ - private ParameterizedCommand command; + private final ParameterizedCommand command; /** * This is the current selection, as seen by this proxy. @@ -117,14 +117,14 @@ public final class ActionDelegateHandlerProxy implements ISelectionListener, ISe * The name of the configuration element attribute which contains the * information necessary to instantiate the real handler. */ - private String delegateAttributeName; + private final String delegateAttributeName; /** * The configuration element from which the handler can be created. This value * will exist until the element is converted into a real class -- at which point * this value will be set to null. */ - private IConfigurationElement element; + private final IConfigurationElement element; /** * The enabledWhen expression for the handler. Only if this @@ -238,11 +238,9 @@ public void dispose() { private void disposeDelegate() { final IActionDelegate actDel = getDelegate(); - if (actDel instanceof IWorkbenchWindowActionDelegate) { - final IWorkbenchWindowActionDelegate workbenchWindowDelegate = (IWorkbenchWindowActionDelegate) actDel; + if (actDel instanceof final IWorkbenchWindowActionDelegate workbenchWindowDelegate) { workbenchWindowDelegate.dispose(); - } else if (actDel instanceof IActionDelegate2) { - final IActionDelegate2 delegate2 = (IActionDelegate2) actDel; + } else if (actDel instanceof final IActionDelegate2 delegate2) { delegate2.dispose(); } delegate = null; @@ -261,8 +259,7 @@ public Object execute(final ExecutionEvent event) { // Attempt to update the selection. final Object applicationContext = event.getApplicationContext(); - if (applicationContext instanceof IEvaluationContext) { - final IEvaluationContext context = (IEvaluationContext) applicationContext; + if (applicationContext instanceof final IEvaluationContext context) { updateDelegate(action, context); } @@ -271,15 +268,11 @@ public Object execute(final ExecutionEvent event) { } // Decide what type of delegate we have. - if ((delegate instanceof IActionDelegate2) && (trigger instanceof Event)) { + if ((delegate instanceof final IActionDelegate2 delegate2) && (trigger instanceof final Event triggeringEvent)) { // This supports Eclipse 2.1 to Eclipse 3.1. - final IActionDelegate2 delegate2 = (IActionDelegate2) delegate; - final Event triggeringEvent = (Event) trigger; delegate2.runWithEvent(action, triggeringEvent); - } else if ((delegate instanceof IActionDelegateWithEvent) && (trigger instanceof Event)) { + } else if ((delegate instanceof final IActionDelegateWithEvent delegateWithEvent) && (trigger instanceof final Event triggeringEvent)) { // This supports Eclipse 2.0 - final IActionDelegateWithEvent delegateWithEvent = (IActionDelegateWithEvent) delegate; - final Event triggeringEvent = (Event) trigger; delegateWithEvent.runWithEvent(action, triggeringEvent); } else { delegate.run(action); @@ -434,8 +427,7 @@ public void handleException(final Throwable exception) { @Override public void run() { // Handle IActionDelegate2 - if (delegate instanceof IActionDelegate2) { - final IActionDelegate2 delegate2 = (IActionDelegate2) delegate; + if (delegate instanceof final IActionDelegate2 delegate2) { delegate2.init(action); } @@ -460,11 +452,10 @@ public void run() { @Override public void setEnabled(Object evaluationContext) { - if (!(evaluationContext instanceof IEvaluationContext)) { + if (!(evaluationContext instanceof IEvaluationContext context)) { return; } - IEvaluationContext context = (IEvaluationContext) evaluationContext; final CommandLegacyActionWrapper action = getAction(); if (enabledWhenExpression != null) { try { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/CommandLegacyActionWrapper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/CommandLegacyActionWrapper.java index 3310d8473a5..89bec73b7e1 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/CommandLegacyActionWrapper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/CommandLegacyActionWrapper.java @@ -185,8 +185,7 @@ public int getAccelerator() { final String commandId = getActionDefinitionId(); final IBindingService bindingService = serviceLocator.getService(IBindingService.class); final TriggerSequence triggerSequence = bindingService.getBestActiveBindingFor(commandId); - if (triggerSequence instanceof KeySequence) { - final KeySequence keySequence = (KeySequence) triggerSequence; + if (triggerSequence instanceof final KeySequence keySequence) { final KeyStroke[] keyStrokes = keySequence.getKeyStrokes(); if (keyStrokes.length == 1) { final KeyStroke keyStroke = keyStrokes[0]; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ContextMenuHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ContextMenuHandler.java index e4a0c1745c4..ebe5083b3ad 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ContextMenuHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ContextMenuHandler.java @@ -38,10 +38,12 @@ public Object execute(ExecutionEvent exEvent) { event.y = pt.y; event.detail = SWT.MENU_KEYBOARD; focusControl.notifyListeners(SWT.MenuDetect, event); - if (focusControl.isDisposed()) + if (focusControl.isDisposed()) { return null; - if (!event.doit) + } + if (!event.doit) { return null; + } Menu menu = focusControl.getMenu(); if (menu != null && !menu.isDisposed()) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/CyclePageHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/CyclePageHandler.java index 14cb5075c6f..9a0cc29d554 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/CyclePageHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/CyclePageHandler.java @@ -131,8 +131,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException { @Override protected void setDialogLocation(final Shell dialog, IWorkbenchPart activePart) { - if (dialog == null) + if (dialog == null) { return; + } // Default to center on the display Point dlgAnchor = Geometry.centerPoint(dialog.getDisplay().getBounds()); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/FullScreenHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/FullScreenHandler.java index 5c4b2f0f9d5..2cf074fa47b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/FullScreenHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/FullScreenHandler.java @@ -117,8 +117,8 @@ boolean checkDuplicatedEvent(ExecutionEvent event) { private static class FullScreenInfoPopup extends PopupDialog { - private String message; - private String messageDoNotShowAgain; + private final String message; + private final String messageDoNotShowAgain; public FullScreenInfoPopup(Shell parent, int shellStyle, boolean takeFocusOnOpen, boolean persistSize, boolean persistLocation, boolean showDialogMenu, boolean showPersistActions, String titleText, diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerActivation.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerActivation.java index e1f4f9987e3..3201304ca91 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerActivation.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerActivation.java @@ -48,12 +48,12 @@ */ final class HandlerActivation implements IHandlerActivation { IEclipseContext context; - private String commandId; - private IHandler handler; + private final String commandId; + private final IHandler handler; E4HandlerProxy proxy; - private Expression activeWhen; + private final Expression activeWhen; private boolean active; - private int sourcePriority; + private final int sourcePriority; boolean participating = true; public HandlerActivation(IEclipseContext context, String cmdId, IHandler handler, E4HandlerProxy handlerProxy, diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerPersistence.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerPersistence.java index d761601513e..b59b9761191 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerPersistence.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerPersistence.java @@ -77,7 +77,7 @@ public final class HandlerPersistence extends RegistryPersistence { */ private final IHandlerService handlerService; - private IEvaluationService evaluationService; + private final IEvaluationService evaluationService; /** * Constructs a new instance of HandlerPersistence. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerProxy.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerProxy.java index 6daf6211f82..22b023a4811 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerProxy.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/HandlerProxy.java @@ -100,7 +100,7 @@ public final class HandlerProxy extends AbstractHandlerWithState implements IEle * enabledWhenExpression. This value may be null only * if the enabledWhenExpression is null. */ - private IEvaluationService evaluationService; + private final IEvaluationService evaluationService; private IPropertyChangeListener enablementListener; @@ -108,7 +108,7 @@ public final class HandlerProxy extends AbstractHandlerWithState implements IEle private boolean proxyEnabled; - private String commandId; + private final String commandId; // // state to support checked or radio commands. @@ -194,8 +194,9 @@ public HandlerProxy(final String commandId, final IConfigurationElement configur public static void updateStaleCEs(IConfigurationElement[] replacements) { for (IConfigurationElement replacement : replacements) { HandlerProxy proxy = CEToProxyMap.get(replacement); - if (proxy != null) + if (proxy != null) { proxy.configurationElement = replacement; + } } } @@ -206,10 +207,9 @@ private void registerEnablement() { @Override public void setEnabled(Object evaluationContext) { - if (!(evaluationContext instanceof IEvaluationContext)) { + if (!(evaluationContext instanceof IEvaluationContext context)) { return; } - IEvaluationContext context = (IEvaluationContext) evaluationContext; if (enabledWhenExpression != null) { try { setProxyEnabled(enabledWhenExpression.evaluate(context) == EvaluationResult.TRUE); @@ -277,8 +277,9 @@ public Object execute(final ExecutionEvent event) throws ExecutionException { return handler.execute(event); } - if (loadException != null) + if (loadException != null) { throw new ExecutionException("Exception occurred when loading the handler", loadException); //$NON-NLS-1$ + } return null; } @@ -409,8 +410,9 @@ private String getConfigurationElementAttribute() { } private boolean isOkToLoad() { - if (PlatformUI.getWorkbench().isClosing()) + if (PlatformUI.getWorkbench().isClosing()) { return handler != null; + } if (configurationElement != null && handler == null) { final String bundleId = configurationElement.getContributor().getName(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/IntroHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/IntroHandler.java index 3ea5f4f2a51..2187364627f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/IntroHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/IntroHandler.java @@ -31,8 +31,8 @@ */ public class IntroHandler extends AbstractHandler { - private Workbench workbench; - private IntroDescriptor introDescriptor; + private final Workbench workbench; + private final IntroDescriptor introDescriptor; public IntroHandler() { workbench = (Workbench) PlatformUI.getWorkbench(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/LegacyHandlerService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/LegacyHandlerService.java index bb31f88fa14..a89744fbaa9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/LegacyHandlerService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/LegacyHandlerService.java @@ -115,8 +115,9 @@ public Object compute(IEclipseContext context, String contextKey) { HandlerActivation conflictBest = null; HandlerActivation conflictOther = null; for (HandlerActivation handlerActivation : activationSet) { - if (!handlerActivation.participating) + if (!handlerActivation.participating) { continue; + } if (handlerActivation.evaluate(legacyEvalContext)) { if (bestActivation == null) { bestActivation = handlerActivation; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/PinEditorHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/PinEditorHandler.java index b8f46c9da6d..502c19214ad 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/PinEditorHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/PinEditorHandler.java @@ -44,9 +44,7 @@ public Object execute(ExecutionEvent event) { return null; } IWorkbenchPartReference ref = window.getActivePage().getReference(editor); - if (ref instanceof WorkbenchPartReference) { - WorkbenchPartReference concreteRef = (WorkbenchPartReference) ref; - + if (ref instanceof WorkbenchPartReference concreteRef) { concreteRef.setPinned(!concreteRef.isPinned()); ICommandService commandService = window.getService(ICommandService.class); commandService.refreshElements(event.getCommand().getId(), null); @@ -69,8 +67,7 @@ public void updateElement(UIElement element, Map parameters) { return; } IWorkbenchPartReference ref = page.getReference(editor); - if (ref instanceof WorkbenchPartReference) { - WorkbenchPartReference concreteRef = (WorkbenchPartReference) ref; + if (ref instanceof WorkbenchPartReference concreteRef) { element.setChecked(concreteRef.isPinned()); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/PropertyDialogHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/PropertyDialogHandler.java index 235d83c1cc6..f11e5843630 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/PropertyDialogHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/PropertyDialogHandler.java @@ -25,7 +25,7 @@ public class PropertyDialogHandler extends AbstractHandler { - private String initialPageId = null; + private final String initialPageId = null; @Override public Object execute(ExecutionEvent event) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ResetPerspectiveHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ResetPerspectiveHandler.java index 1def2e1f010..2f7e977c40d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ResetPerspectiveHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ResetPerspectiveHandler.java @@ -48,8 +48,7 @@ public Object execute(ExecutionEvent event) { IPerspectiveDescriptor descriptor = page.getPerspective(); if (descriptor != null) { boolean offerRevertToBase = false; - if (descriptor instanceof PerspectiveDescriptor) { - PerspectiveDescriptor desc = (PerspectiveDescriptor) descriptor; + if (descriptor instanceof PerspectiveDescriptor desc) { offerRevertToBase = desc.isPredefined() && desc.hasCustomDefinition(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveAllHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveAllHandler.java index f46fcfa3f67..f2ff1c796da 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveAllHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveAllHandler.java @@ -62,17 +62,20 @@ protected EvaluationResult evaluate(IEvaluationContext context) { IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context); // no window? not active - if (window == null) + if (window == null) { return EvaluationResult.FALSE; + } WorkbenchPage page = (WorkbenchPage) window.getActivePage(); // no page? not active - if (page == null) + if (page == null) { return EvaluationResult.FALSE; + } // if at least one dirty part, then we are active - if (page.getDirtyParts().length > 0) + if (page.getDirtyParts().length > 0) { return EvaluationResult.TRUE; + } EPartService partService = getPartService(window); if (partService != null && (partService.getDirtyParts().size() > 0)) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveAsHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveAsHandler.java index 1d27a92b270..7b605ec06bc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveAsHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveAsHandler.java @@ -43,8 +43,9 @@ public Object execute(ExecutionEvent event) { ISaveablePart saveablePart = getSaveablePart(event); - if (saveablePart != null) + if (saveablePart != null) { saveablePart.doSaveAs(); + } return null; } @@ -54,13 +55,15 @@ protected EvaluationResult evaluate(IEvaluationContext context) { IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context); // no window? not active - if (window == null) + if (window == null) { return EvaluationResult.FALSE; + } WorkbenchPage page = (WorkbenchPage) window.getActivePage(); // no page? not active - if (page == null) + if (page == null) { return EvaluationResult.FALSE; + } MPart activeMPart = getActivePart(window); @@ -72,8 +75,9 @@ protected EvaluationResult evaluate(IEvaluationContext context) { // get saveable part ISaveablePart saveablePart = getSaveablePart(context); - if (saveablePart == null) + if (saveablePart == null) { return EvaluationResult.FALSE; + } // if its available, return whatever it says return saveablePart.isSaveAsAllowed() ? EvaluationResult.TRUE : EvaluationResult.FALSE; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveHandler.java index cb7f93b152a..d3795d87810 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SaveHandler.java @@ -75,8 +75,7 @@ public Object execute(ExecutionEvent event) { } // if editor - if (saveablePart instanceof IEditorPart) { - IEditorPart editorPart = (IEditorPart) saveablePart; + if (saveablePart instanceof IEditorPart editorPart) { IWorkbenchPage page = editorPart.getSite().getPage(); page.saveEditor(editorPart, false); return null; @@ -95,8 +94,9 @@ protected EvaluationResult evaluate(IEvaluationContext context) { IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context); // no window? not active - if (window == null) + if (window == null) { return EvaluationResult.FALSE; + } boolean enabled = evaluateEnabled(context, window); if (window != null) { @@ -114,8 +114,9 @@ private boolean evaluateEnabled(IEvaluationContext context, IWorkbenchWindow win WorkbenchPage page = (WorkbenchPage) window.getActivePage(); // no page? not active - if (page == null) + if (page == null) { return false; + } MPart activeMPart = getActivePart(window); @@ -127,19 +128,22 @@ private boolean evaluateEnabled(IEvaluationContext context, IWorkbenchWindow win // get saveable part ISaveablePart saveablePart = getSaveablePart(context); - if (saveablePart == null && activeMPart == null) + if (saveablePart == null && activeMPart == null) { return false; + } - if (saveablePart instanceof ISaveablesSource) { - ISaveablesSource modelSource = (ISaveablesSource) saveablePart; - if (SaveableHelper.needsSave(modelSource)) + if (saveablePart instanceof ISaveablesSource modelSource) { + if (SaveableHelper.needsSave(modelSource)) { return true; - if (activeMPart == null) + } + if (activeMPart == null) { return false; + } } - if (saveablePart != null && saveablePart.isDirty()) + if (saveablePart != null && saveablePart.isDirty()) { return true; + } if (activeMPart != null && activeMPart.isDirty()) { return true; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SpyHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SpyHandler.java index 741b72da10f..860c4e248ac 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SpyHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/SpyHandler.java @@ -59,8 +59,7 @@ protected void showTooltip(Control control) { ContributionInfo contributionInfo = null; Point offset = new Point(0, 0); while (control != null) { - if (control instanceof Table) { - Table table = (Table) control; + if (control instanceof Table table) { if (table.getSelectionCount() == 1) { TableItem tableItem = table.getSelection()[0]; contributionInfo = getContributionInfo(tableItem.getData(), @@ -71,8 +70,7 @@ protected void showTooltip(Control control) { break; } } - } else if (control instanceof Tree) { - Tree tree = (Tree) control; + } else if (control instanceof Tree tree) { if (tree.getSelectionCount() == 1) { TreeItem treeItem = tree.getSelection()[0]; contributionInfo = getContributionInfo(treeItem.getData(), @@ -87,10 +85,11 @@ protected void showTooltip(Control control) { String optionalElementType; // "force" a contribution info if we are at a shell - if (control instanceof Shell) + if (control instanceof Shell) { optionalElementType = ContributionInfoMessages.ContributionInfo_Window; - else + } else { optionalElementType = null; + } contributionInfo = getContributionInfo(control.getData(), optionalElementType); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ToggleCoolbarHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ToggleCoolbarHandler.java index 43992764767..9e70ab46274 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ToggleCoolbarHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ToggleCoolbarHandler.java @@ -38,8 +38,7 @@ public class ToggleCoolbarHandler extends AbstractHandler implements IElementUpd @Override public Object execute(ExecutionEvent event) throws ExecutionException { final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindowChecked(event); - if (activeWorkbenchWindow instanceof WorkbenchWindow) { - WorkbenchWindow window = (WorkbenchWindow) activeWorkbenchWindow; + if (activeWorkbenchWindow instanceof WorkbenchWindow window) { window.toggleToolbarVisibility(); } @@ -50,8 +49,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException { public void updateElement(UIElement element, Map parameters) { IWorkbenchLocationService wls = element.getServiceLocator().getService(IWorkbenchLocationService.class); IWorkbenchWindow window = wls.getWorkbenchWindow(); - if (window == null || !(window instanceof WorkbenchWindow)) + if (window == null || !(window instanceof WorkbenchWindow)) { return; + } element.setText( isCoolbarVisible((WorkbenchWindow) window) ? WorkbenchMessages.ToggleCoolbarVisibilityAction_hide_text : WorkbenchMessages.ToggleCoolbarVisibilityAction_show_text); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ToggleStatusBarHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ToggleStatusBarHandler.java index 9e23ba6fedd..5bbf96f43c1 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ToggleStatusBarHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/ToggleStatusBarHandler.java @@ -46,14 +46,15 @@ public class ToggleStatusBarHandler extends AbstractHandler implements IElementU private static final String BOTTOM_TRIM_ID = "org.eclipse.ui.trim.status"; //$NON-NLS-1$ // keep references of event handlers and brokers per each window - private HashMap eventHandlers = new HashMap<>(); - private HashMap eventBrokers = new HashMap<>(); + private final HashMap eventHandlers = new HashMap<>(); + private final HashMap eventBrokers = new HashMap<>(); @Override public Object execute(ExecutionEvent event) { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); - if (!(window instanceof WorkbenchWindow)) + if (!(window instanceof WorkbenchWindow)) { return null; + } // initialize event handler if (!eventHandlers.containsKey(window)) { initializeEventHandler(window); @@ -104,8 +105,9 @@ public void dispose() { public void updateElement(UIElement element, Map parameters) { IWorkbenchLocationService wls = element.getServiceLocator().getService(IWorkbenchLocationService.class); IWorkbenchWindow window = wls.getWorkbenchWindow(); - if (!(window instanceof WorkbenchWindow)) + if (!(window instanceof WorkbenchWindow)) { return; + } MUIElement trimStatus = getTrimStatus((WorkbenchWindow) window); if (trimStatus != null) { element.setText(trimStatus.isVisible() ? WorkbenchMessages.ToggleStatusBarVisibilityAction_hide_text diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java index c2c1a5c9975..3697e69de4a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java @@ -47,10 +47,12 @@ public final Object execute(final ExecutionEvent event) { traversalDirection = translateToTraversalDirection(!forward); // we are in the second-to-last item in the given // direction. Now, use the Traverse-event to move back by one } - if (control.traverse(traversalDirection)) + if (control.traverse(traversalDirection)) { return null; - if (control instanceof Shell) + } + if (control instanceof Shell) { return null; + } control = control.getParent(); } while (control != null); } @@ -64,7 +66,7 @@ private boolean hasHiddenItem(CTabFolder folder) { private int translateToTraversalDirection(boolean forward) { return forward ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS; } - + /** * Sets the current selection to the first or last item the given direction. * diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/WidgetMethodHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/WidgetMethodHandler.java index 601043ce538..aa6d39dc215 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/WidgetMethodHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/WidgetMethodHandler.java @@ -195,8 +195,9 @@ public final boolean isHandled() { */ protected Method getMethodToExecute() { Display display = Display.getCurrent(); - if (display == null) + if (display == null) { return null; + } final Control focusControl = display.getFocusControl(); Method method = null; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/WizardHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/WizardHandler.java index 7c70e2e7f4e..3e0d352fc97 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/WizardHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/WizardHandler.java @@ -328,8 +328,9 @@ protected IStructuredSelection getSelectionToUse(ExecutionEvent event) { public void updateElement(UIElement element, Map parameters) { String wizardId = (String) parameters.get(getWizardIdParameterId()); - if (wizardId == null) + if (wizardId == null) { return; + } IWizardDescriptor wizard = getWizardRegistry().findWizard(wizardId); if (wizard != null) { element.setText(NLS.bind(WorkbenchMessages.WizardHandler_menuLabel, wizard.getLabel())); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/help/CommandHelpServiceImpl.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/help/CommandHelpServiceImpl.java index 5f96abe6268..07c49931be2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/help/CommandHelpServiceImpl.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/help/CommandHelpServiceImpl.java @@ -41,7 +41,7 @@ public class CommandHelpServiceImpl implements ICommandHelpService { @Optional private Logger logger; - private Map helpContextIdsByHandler = new WeakHashMap<>(); + private final Map helpContextIdsByHandler = new WeakHashMap<>(); @Override public String getHelpContextId(String commandId, IEclipseContext context) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/help/WorkbenchHelpSystem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/help/WorkbenchHelpSystem.java index d129e21bca1..753c8c252e4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/help/WorkbenchHelpSystem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/help/WorkbenchHelpSystem.java @@ -102,10 +102,9 @@ public void helpRequested(HelpEvent event) { } else if (object instanceof IContext) { // already resolved context (pre 2.0) context = (IContext) object; - } else if (object instanceof Object[]) { + } else if (object instanceof Object[] helpContexts) { // mixed array of String or IContext (pre 2.0) - extract the // first entry - Object[] helpContexts = (Object[]) object; // extract the first entry if (helpContexts.length > 0) { Object primaryEntry = helpContexts[0]; @@ -161,7 +160,7 @@ public void helpRequested(HelpEvent event) { * * @since 3.1 */ - private IExtensionChangeHandler handler = new IExtensionChangeHandler() { + private final IExtensionChangeHandler handler = new IExtensionChangeHandler() { @Override public void addExtension(IExtensionTracker tracker, IExtension extension) { @@ -305,8 +304,8 @@ public boolean isContextHelpDisplayed() { * @since 3.1 */ private static class ContextWithTitle implements IContext2 { - private IContext context; - private String title; + private final IContext context; + private final String title; ContextWithTitle(IContext context, String title) { this.context = context; @@ -765,8 +764,9 @@ public boolean isContextHelpDisplayed() { @Override public void setHelp(final IAction action, final String contextId) { - if (WorkbenchPlugin.DEBUG) + if (WorkbenchPlugin.DEBUG) { setHelpTrace(contextId); + } action.setHelpListener(event -> { if (getHelpUI() != null) { IContext context = HelpSystem.getContext(contextId); @@ -781,8 +781,9 @@ public void setHelp(final IAction action, final String contextId) { @Override public void setHelp(Control control, String contextId) { - if (WorkbenchPlugin.DEBUG) + if (WorkbenchPlugin.DEBUG) { setHelpTrace(contextId); + } control.setData(HELP_KEY, contextId); // ensure that the listener is only registered once control.removeHelpListener(getHelpListener()); @@ -791,8 +792,9 @@ public void setHelp(Control control, String contextId) { @Override public void setHelp(Menu menu, String contextId) { - if (WorkbenchPlugin.DEBUG) + if (WorkbenchPlugin.DEBUG) { setHelpTrace(contextId); + } menu.setData(HELP_KEY, contextId); // ensure that the listener is only registered once menu.removeHelpListener(getHelpListener()); @@ -802,8 +804,9 @@ public void setHelp(Menu menu, String contextId) { @Override public void setHelp(MenuItem item, String contextId) { - if (WorkbenchPlugin.DEBUG) + if (WorkbenchPlugin.DEBUG) { setHelpTrace(contextId); + } item.setData(HELP_KEY, contextId); // ensure that the listener is only registered once @@ -828,12 +831,13 @@ private void setHelpTrace(String contextId) { } } - if (registeredIDTable == null) + if (registeredIDTable == null) { registeredIDTable = new Hashtable<>(); + } - if (!registeredIDTable.containsKey(contextId)) + if (!registeredIDTable.containsKey(contextId)) { registeredIDTable.put(contextId, currentElement); - else if (!registeredIDTable.get(contextId).equals(currentElement)) { + } else if (!registeredIDTable.get(contextId).equals(currentElement)) { StackTraceElement initialElement = registeredIDTable.get(contextId); String error = "UI Duplicate Context ID found: '" + contextId + "'\n" + //$NON-NLS-1$ //$NON-NLS-2$ " 1 at " + initialElement + '\n' + //$NON-NLS-1$ diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/intro/IntroDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/intro/IntroDescriptor.java index 989edd4c8a2..472015d3bfb 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/intro/IntroDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/intro/IntroDescriptor.java @@ -32,7 +32,7 @@ */ public class IntroDescriptor implements IIntroDescriptor, IPluginContribution { - private IConfigurationElement element; + private final IConfigurationElement element; private ImageDescriptor imageDescriptor; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/BindingPersistence.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/BindingPersistence.java index f7afca45bcb..b27b01f7524 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/BindingPersistence.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/BindingPersistence.java @@ -532,16 +532,18 @@ private static final void readBindingsFromRegistry(final IConfigurationElement[] // the local cache for the sequence modifiers IConfigurationElement[] sequenceModifiers = new IConfigurationElement[0]; - if (configurationElementCount > 0) + if (configurationElementCount > 0) { sequenceModifiers = getSequenceModifierElements(configurationElements[0]); + } for (int i = 0; i < configurationElementCount; i++) { final IConfigurationElement configurationElement = configurationElements[i]; // different extension. update the cache ... if (i > 0 && !configurationElement.getDeclaringExtension() - .equals(configurationElements[i - 1].getDeclaringExtension())) + .equals(configurationElements[i - 1].getDeclaringExtension())) { sequenceModifiers = getSequenceModifierElements(configurationElement); + } /* * Read out the command id. Doing this before determining if the key binding is @@ -568,8 +570,9 @@ private static final void readBindingsFromRegistry(final IConfigurationElement[] // Read out the scheme id. String schemeId = readSchemeId(configurationElement, warningsToLog, commandId); - if (isEmpty(schemeId)) + if (isEmpty(schemeId)) { continue; + } // Read out the context id. String contextId = readContextId(configurationElement); @@ -584,8 +587,9 @@ private static final void readBindingsFromRegistry(final IConfigurationElement[] // Read out the key sequence. KeySequence keySequence = readKeySequence(configurationElement, warningsToLog, commandId, keySequenceText); - if (keySequence == null) + if (keySequence == null) { continue; + } // Read out the locale and platform. @@ -731,8 +735,9 @@ private static IConfigurationElement[] getSequenceModifierElements(IConfiguratio IExtension extension = configurationElement.getDeclaringExtension(); List modifierElements = new ArrayList<>(); for (final IConfigurationElement configElement : extension.getConfigurationElements()) { - if (TAG_SEQUENCE_MODIFIER.equals(configElement.getName())) + if (TAG_SEQUENCE_MODIFIER.equals(configElement.getName())) { modifierElements.add(configElement); + } } return modifierElements.toArray(new IConfigurationElement[modifierElements.size()]); } @@ -753,8 +758,9 @@ private static String readKeySequenceText(IConfigurationElement configurationEle if (isEmpty(keySequenceText)) { keySequenceText = configurationElement.getAttribute(ATT_KEY_SEQUENCE); } - if (isEmpty(keySequenceText)) + if (isEmpty(keySequenceText)) { keySequenceText = configurationElement.getAttribute(ATT_STRING); + } return keySequenceText; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/BindingService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/BindingService.java index ba11f4d4848..442eb2e71a7 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/BindingService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/BindingService.java @@ -92,7 +92,7 @@ public final class BindingService implements IBindingService { private BindingPersistence bp; - private Map bindingContexts = new HashMap<>(); + private final Map bindingContexts = new HashMap<>(); private String[] activeSchemeIds; @@ -530,15 +530,18 @@ private MBindingTable getMTable(String contextId) { static private boolean isSameBinding(MKeyBinding existingBinding, MCommand cmd, Binding binding) { // see org.eclipse.jface.bindings.Binding#equals(final Object object) - if (!cmd.equals(existingBinding.getCommand())) + if (!cmd.equals(existingBinding.getCommand())) { return false; + } String existingKeySequence = existingBinding.getKeySequence(); - if (existingKeySequence == null) + if (existingKeySequence == null) { return false; + } try { final KeySequence existingSequence = KeySequence.getInstance(existingKeySequence); - if (!existingSequence.equals(binding.getTriggerSequence())) + if (!existingSequence.equals(binding.getTriggerSequence())) { return false; + } } catch (ParseException e) { return false; } @@ -548,22 +551,26 @@ static private boolean isSameBinding(MKeyBinding existingBinding, MCommand cmd, String schemeId = binding.getSchemeId(); if (schemeId != null && !schemeId.equals(BindingPersistence.getDefaultSchemeId())) { - if (!modelTags.contains(EBindingService.SCHEME_ID_ATTR_TAG + ":" + schemeId)) //$NON-NLS-1$ + if (!modelTags.contains(EBindingService.SCHEME_ID_ATTR_TAG + ":" + schemeId)) { //$NON-NLS-1$ return false; + } } String locale = binding.getLocale(); if (locale != null) { - if (!modelTags.contains(EBindingService.LOCALE_ATTR_TAG + ":" + locale)) //$NON-NLS-1$ + if (!modelTags.contains(EBindingService.LOCALE_ATTR_TAG + ":" + locale)) { //$NON-NLS-1$ return false; + } } String platform = binding.getPlatform(); if (platform != null) { - if (!modelTags.contains(EBindingService.PLATFORM_ATTR_TAG + ":" + platform)) //$NON-NLS-1$ + if (!modelTags.contains(EBindingService.PLATFORM_ATTR_TAG + ":" + platform)) { //$NON-NLS-1$ return false; + } } if (binding.getType() == Binding.USER) { - if (!modelTags.contains(EBindingService.TYPE_ATTR_TAG + ":user")) //$NON-NLS-1$ + if (!modelTags.contains(EBindingService.TYPE_ATTR_TAG + ":user")) { //$NON-NLS-1$ return false; + } } return true; } @@ -607,8 +614,9 @@ static public MKeyBinding createOrUpdateMKeyBinding(MApplication application, MB Map.Entry entry = (Map.Entry) obj; String paramID = entry.getKey(); - if (paramID == null) + if (paramID == null) { continue; + } List bindingParams = keyBinding.getParameters(); MParameter p = null; for (MParameter param : bindingParams) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/CategoryPatternFilter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/CategoryPatternFilter.java index a292deb14fb..0f150ea629f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/CategoryPatternFilter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/CategoryPatternFilter.java @@ -28,7 +28,7 @@ class CategoryPatternFilter extends PatternFilter { private boolean filterCategories; final Category uncategorized; - private IActivityManager activityManager; + private final IActivityManager activityManager; public CategoryPatternFilter(boolean filterCategories, Category c, IActivityManager activityManager) { uncategorized = c; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/GlobalKeyAssistDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/GlobalKeyAssistDialog.java index 3e953a7e707..9c99885c04a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/GlobalKeyAssistDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/GlobalKeyAssistDialog.java @@ -37,7 +37,7 @@ public class GlobalKeyAssistDialog extends KeyAssistDialog { /** * Context for this dialog, used to open services */ - private IEclipseContext context; + private final IEclipseContext context; /** * ID of the key binding preference page diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/KeysPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/KeysPreferencePage.java index 7b34808a232..b4e2e557aa0 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/KeysPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/KeysPreferencePage.java @@ -1581,7 +1581,7 @@ public void setVisible(final boolean visible) { while (iterator2.hasNext()) { Category category = iterator2.next(); String uniqueName = MessageFormat.format(Util.translateString(RESOURCE_BUNDLE, "uniqueName"), //$NON-NLS-1$ - new Object[] { name, category.getId() }); + name, category.getId()); categoryIdsByUniqueName.put(uniqueName, category.getId()); categoryUniqueNamesById.put(category.getId(), uniqueName); } @@ -1604,7 +1604,7 @@ public void setVisible(final boolean visible) { while (iterator2.hasNext()) { Scheme scheme = iterator2.next(); String uniqueName = MessageFormat.format(Util.translateString(RESOURCE_BUNDLE, "uniqueName"), //$NON-NLS-1$ - new Object[] { name, scheme.getId() }); + name, scheme.getId()); schemeIdsByUniqueName.put(uniqueName, scheme.getId()); schemeUniqueNamesById.put(scheme.getId(), uniqueName); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java index e99ed1542fc..6673dfb8a61 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java @@ -216,7 +216,7 @@ public class NewKeysPreferencePage extends PreferencePage implements IWorkbenchP */ protected static class CategoryFilterTree extends FilteredTree { - private CategoryPatternFilter filter; + private final CategoryPatternFilter filter; /** * Constructor for PatternFilteredTree. @@ -238,7 +238,7 @@ public boolean isFilteringCategories() { } private final class BindingModelComparator extends ViewerComparator { - private LinkedList sortColumns = new LinkedList<>(); + private final LinkedList sortColumns = new LinkedList<>(); private boolean ascending = true; public BindingModelComparator() { @@ -290,8 +290,7 @@ private int compareColumn(final Viewer viewer, final Object a, final Object b, f return sortUser(a, b); } IBaseLabelProvider baseLabel = ((TreeViewer) viewer).getLabelProvider(); - if (baseLabel instanceof ITableLabelProvider) { - ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel; + if (baseLabel instanceof ITableLabelProvider tableProvider) { String e1p = tableProvider.getColumnText(a, columnNumber); String e2p = tableProvider.getColumnText(b, columnNumber); if (e1p != null && e2p != null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/WorkbenchKeyboard.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/WorkbenchKeyboard.java index accb6e3d688..2232c06f110 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/WorkbenchKeyboard.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/WorkbenchKeyboard.java @@ -25,10 +25,10 @@ * @since 3.5 */ public class WorkbenchKeyboard { - private KeyBindingDispatcher delegate; + private final KeyBindingDispatcher delegate; static class KeyDownFilter implements Listener { - private KeyBindingDispatcher.KeyDownFilter delegate; + private final KeyBindingDispatcher.KeyDownFilter delegate; @Override public void handleEvent(Event event) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/model/BindingModel.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/model/BindingModel.java index 94fd52225a8..8699bea0c1d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/model/BindingModel.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/model/BindingModel.java @@ -214,8 +214,7 @@ public void refresh(ContextModel contextModel) { while (i.hasNext()) { BindingElement be = (BindingElement) i.next(); Object obj = be.getModelObject(); - if (obj instanceof Binding) { - Binding b = (Binding) obj; + if (obj instanceof Binding b) { if (!activeManagerBindings.contains(b)) { ParameterizedCommand cmd = b.getParameterizedCommand(); if (cmd != null) { @@ -283,8 +282,7 @@ public void remove(BindingElement bindingElement) { continue; } Object modelObject = be.getModelObject(); - if (modelObject instanceof Binding) { - Binding binding = (Binding) modelObject; + if (modelObject instanceof Binding binding) { if (binding.getType() != Binding.SYSTEM) { continue; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/model/KeyController.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/model/KeyController.java index fb10c25ad8c..add786b0648 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/model/KeyController.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/model/KeyController.java @@ -281,8 +281,7 @@ private void updateBindingContext(ContextElement context) { } String activeSchemeId = fSchemeModel.getSelectedElement().getId(); Object obj = activeBinding.getModelObject(); - if (obj instanceof KeyBinding) { - KeyBinding keyBinding = (KeyBinding) obj; + if (obj instanceof KeyBinding keyBinding) { if (!keyBinding.getContextId().equals(context.getId())) { final KeyBinding binding = new KeyBinding(keyBinding.getKeySequence(), keyBinding.getParameterizedCommand(), activeSchemeId, context.getId(), null, null, null, @@ -307,8 +306,7 @@ private void updateTrigger(BindingElement activeBinding, KeySequence keySequence return; } Object obj = activeBinding.getModelObject(); - if (obj instanceof KeyBinding) { - KeyBinding keyBinding = (KeyBinding) obj; + if (obj instanceof KeyBinding keyBinding) { if (!keyBinding.getKeySequence().equals(keySequence)) { if (keySequence != null && !keySequence.isEmpty()) { String activeSchemeId = fSchemeModel.getSelectedElement().getId(); @@ -344,8 +342,7 @@ private void updateTrigger(BindingElement activeBinding, KeySequence keySequence activeBinding.fill(keyBinding.getParameterizedCommand()); } } - } else if (obj instanceof ParameterizedCommand) { - ParameterizedCommand cmd = (ParameterizedCommand) obj; + } else if (obj instanceof ParameterizedCommand cmd) { if (keySequence != null && !keySequence.isEmpty()) { String activeSchemeId = fSchemeModel.getSelectedElement().getId(); ModelElement selectedElement = contextModel.getSelectedElement(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/show/ShowKeysListener.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/show/ShowKeysListener.java index 1639328a2e9..f89856ba6f7 100755 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/show/ShowKeysListener.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/show/ShowKeysListener.java @@ -31,9 +31,9 @@ */ public class ShowKeysListener implements IExecutionListener, IPropertyChangeListener, IDisposable { - private IPreferenceStore preferenceStore; - private IServiceLocator serviceLocator; - private ShowKeysUI showKeysUI; + private final IPreferenceStore preferenceStore; + private final IServiceLocator serviceLocator; + private final ShowKeysUI showKeysUI; public ShowKeysListener(IServiceLocator serviceLocator, IPreferenceStore preferenceStore) { this.serviceLocator = serviceLocator; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/show/ShowKeysUI.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/show/ShowKeysUI.java index e39d1be9128..1f9df21b76a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/show/ShowKeysUI.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/keys/show/ShowKeysUI.java @@ -56,8 +56,8 @@ */ public class ShowKeysUI implements IDisposable { - private IPreferenceStore preferenceStore; - private IServiceLocator serviceLocator; + private final IPreferenceStore preferenceStore; + private final IServiceLocator serviceLocator; private ShowKeysPopup shortcutPopup; public ShowKeysUI(IServiceLocator serviceLocator, IPreferenceStore preferenceStore) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/CacheWrapper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/CacheWrapper.java index 961e60339c0..3299eb33fc4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/CacheWrapper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/CacheWrapper.java @@ -61,7 +61,7 @@ public class CacheWrapper { private Composite proxy; - private SizeCache cache = new SizeCache(); + private final SizeCache cache = new SizeCache(); private Rectangle lastBounds = new Rectangle(0, 0, 0, 0); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/CellLayout.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/CellLayout.java index 4a4df40e50d..5b600b81edc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/CellLayout.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/CellLayout.java @@ -130,22 +130,22 @@ public class CellLayout extends Layout { * Number of columns in this layout, or 0 indicating that the whole layout * should be on a single row. */ - private int numCols; + private final int numCols; /** * List of IColumnInfo. The nth object is used to compute the width of the nth * column, or null indicating that the default column should be used. */ - private List cols; + private final List cols; /** * List of RowInfo. The nth object is used to compute the height of the nth row, * or null indicating that the default row should be used. */ - private List rows = new ArrayList<>(16); + private final List rows = new ArrayList<>(16); // Cached information - private GridInfo gridInfo = new GridInfo(); + private final GridInfo gridInfo = new GridInfo(); private int[] cachedRowMin = null; @@ -155,7 +155,7 @@ public class CellLayout extends Layout { public static int cacheHits; - private LayoutCache cache = new LayoutCache(); + private final LayoutCache cache = new LayoutCache(); // End of cached control sizes diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/SizeCache.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/SizeCache.java index 48bd53e1e36..5e54e2ab593 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/SizeCache.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/layout/SizeCache.java @@ -321,9 +321,8 @@ static boolean independentLengthAndWidth(Control control) { * one dimension of a control's size given the other known dimension. */ private void computeHintOffset(Control control) { - if (control instanceof Composite) { + if (control instanceof Composite composite) { // For composites, subtract off the trim size - Composite composite = (Composite) control; Rectangle trim = composite.computeTrim(0, 0, 0, 0); widthAdjustment = trim.width; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/ContributionFactoryGenerator.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/ContributionFactoryGenerator.java index 23d161dcd39..28e5ad482e3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/ContributionFactoryGenerator.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/ContributionFactoryGenerator.java @@ -37,7 +37,7 @@ public class ContributionFactoryGenerator extends ContextFunction { private AbstractContributionFactory factoryImpl; private IConfigurationElement configElement; - private int type; + private final int type; public ContributionFactoryGenerator(AbstractContributionFactory factory, int type) { this.factoryImpl = factory; @@ -76,8 +76,7 @@ public Object compute(IEclipseContext context, String contextKey) { final Map itemsToExpression = root.getVisibleWhen(); List menuElements = new ArrayList<>(); for (Object obj : contributionItems) { - if (obj instanceof IContributionItem) { - IContributionItem ici = (IContributionItem) obj; + if (obj instanceof IContributionItem ici) { MUIElement opaqueItem = createUIElement(ici); if (opaqueItem != null) { if (itemsToExpression.containsKey(ici)) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/ContributionRoot.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/ContributionRoot.java index d377c4e7d6c..5a065c4e1cf 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/ContributionRoot.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/ContributionRoot.java @@ -32,9 +32,9 @@ */ final class ContributionRoot implements IContributionRoot { - private List topLevelItems = new ArrayList<>(); - private Map itemsToExpressions = new HashMap<>(); - private AbstractContributionFactory factory; + private final List topLevelItems = new ArrayList<>(); + private final Map itemsToExpressions = new HashMap<>(); + private final AbstractContributionFactory factory; public ContributionRoot(AbstractContributionFactory factory) { this.factory = factory; @@ -42,11 +42,13 @@ public ContributionRoot(AbstractContributionFactory factory) { @Override public void addContributionItem(IContributionItem item, Expression visibleWhen) { - if (item == null) + if (item == null) { throw new IllegalArgumentException(); + } topLevelItems.add(item); - if (visibleWhen == null) + if (visibleWhen == null) { visibleWhen = AlwaysEnabledExpression.INSTANCE; + } // menuService.registerVisibleWhen(item, visibleWhen, restriction, // createIdentifierId(item)); @@ -91,10 +93,12 @@ public void release() { @Override public void registerVisibilityForChild(IContributionItem item, Expression visibleWhen) { - if (item == null) + if (item == null) { throw new IllegalArgumentException(); - if (visibleWhen == null) + } + if (visibleWhen == null) { visibleWhen = AlwaysEnabledExpression.INSTANCE; + } // menuService.registerVisibleWhen(item, visibleWhen, restriction, // createIdentifierId(item)); itemsToExpressions.put(item, visibleWhen); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/DynamicMenuContributionItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/DynamicMenuContributionItem.java index 2fa7da043e8..8e69abac880 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/DynamicMenuContributionItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/DynamicMenuContributionItem.java @@ -46,7 +46,7 @@ public class DynamicMenuContributionItem extends ContributionItem { private final IServiceLocator locator; private boolean alreadyFailed; private ContributionItem loadedDynamicContribution; - private IContributionFactory factory; + private final IContributionFactory factory; /** * Creates a DynamicMenuContributionItem @@ -211,8 +211,9 @@ public void fill(ToolBar parent, int index) { } private IContributionItem getContributionItem() { - if (loadedDynamicContribution == null && !alreadyFailed) + if (loadedDynamicContribution == null && !alreadyFailed) { createContributionItem(); + } return loadedDynamicContribution; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/DynamicToolBarContributionItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/DynamicToolBarContributionItem.java index 8e0b2b3da96..a07bc18006d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/DynamicToolBarContributionItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/DynamicToolBarContributionItem.java @@ -125,13 +125,15 @@ public boolean isVisible() { @Override public void fill(CoolBar parent, int index) { IContributionItem contributionItem = getContributionItem(); - if (contributionItem != null) + if (contributionItem != null) { contributionItem.fill(parent, index); + } } private WorkbenchWindowControlContribution getContributionItem() { - if (loadedDynamicContribution == null && !alreadyFailed) + if (loadedDynamicContribution == null && !alreadyFailed) { createContributionItem(); + } return loadedDynamicContribution; } @@ -205,8 +207,9 @@ public void setCurSide(int curSide) { public Control createControl(Composite parent) { WorkbenchWindowControlContribution contributionItem = getContributionItem(); - if (contributionItem != null) + if (contributionItem != null) { return contributionItem.delegateCreateControl(parent); + } return null; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/InternalControlContribution.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/InternalControlContribution.java index 7b9e924a323..d60db690863 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/InternalControlContribution.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/InternalControlContribution.java @@ -67,8 +67,9 @@ public void setCurSide(int curSide) { } public int getOrientation() { - if (getCurSide() == SWT.LEFT || getCurSide() == SWT.RIGHT) + if (getCurSide() == SWT.LEFT || getCurSide() == SWT.RIGHT) { return SWT.VERTICAL; + } return SWT.HORIZONTAL; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java index 01676256e61..4bf3ec6ec3e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java @@ -85,14 +85,14 @@ static boolean isInWorkbenchTrim(MenuLocationURI location) { || TRIM_VERTICAL1.equals(path) || TRIM_VERTICAL2.equals(path) || TRIM_STATUS.equals(path); } - private MApplication application; + private final MApplication application; // private IEclipseContext appContext; - private IConfigurationElement configElement; - private MenuLocationURI location; + private final IConfigurationElement configElement; + private final MenuLocationURI location; - private String namespaceIdentifier; + private final String namespaceIdentifier; - private IActivityManager activityManager; + private final IActivityManager activityManager; public MenuAdditionCacheEntry(MApplication application, IEclipseContext appContext, IConfigurationElement configElement, String attribute, String namespaceIdentifier) { @@ -289,7 +289,7 @@ public void identifierChanged(IdentifierEvent identifierEvent) { } } - private IdListener idUpdater = new IdListener(); + private final IdListener idUpdater = new IdListener(); private void createIdentifierTracker(MApplicationElement item) { if (item.getElementId() != null && item.getElementId().length() > 0) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuFactoryGenerator.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuFactoryGenerator.java index 1641944e7c9..bec3258d722 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuFactoryGenerator.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuFactoryGenerator.java @@ -32,9 +32,9 @@ * @since 3.102.0 */ public class MenuFactoryGenerator { - private MApplication application; - private IConfigurationElement configElement; - private MenuLocationURI location; + private final MApplication application; + private final IConfigurationElement configElement; + private final MenuLocationURI location; public MenuFactoryGenerator(MApplication application, IEclipseContext appContext, IConfigurationElement configElement, String attribute) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuHelper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuHelper.java index 5a3eb443100..21915ad4f79 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuHelper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuHelper.java @@ -316,10 +316,11 @@ public static MHandledToolItem createToolItem(MApplication application, CommandC String disabledIconURI = null; toolItem.setType(ItemType.PUSH); - if (data.style == CommandContributionItem.STYLE_CHECK) + if (data.style == CommandContributionItem.STYLE_CHECK) { toolItem.setType(ItemType.CHECK); - else if (data.style == CommandContributionItem.STYLE_RADIO) + } else if (data.style == CommandContributionItem.STYLE_RADIO) { toolItem.setType(ItemType.RADIO); + } if (data.icon != null) { iconURI = getIconURI(data.icon, application.getContext()); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuLocationURI.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuLocationURI.java index 0437ffa4551..dbf412093c5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuLocationURI.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuLocationURI.java @@ -33,7 +33,7 @@ */ public class MenuLocationURI { - private String rawString; + private final String rawString; public MenuLocationURI(String uriDef) { rawString = uriDef; @@ -62,8 +62,9 @@ public String getScheme() { public String getPath() { // Trim off the scheme String[] vals = Util.split(rawString, ':'); - if (vals.length < 2) + if (vals.length < 2) { return null; + } // Now, trim off any query vals = Util.split(vals[1], '?'); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuPersistence.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuPersistence.java index 9ef1cc1d000..02e6a7384e1 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuPersistence.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/MenuPersistence.java @@ -46,13 +46,13 @@ */ final public class MenuPersistence extends RegistryPersistence { - private MApplication application; - private IEclipseContext appContext; - private ArrayList cacheEntries = new ArrayList<>(); + private final MApplication application; + private final IEclipseContext appContext; + private final ArrayList cacheEntries = new ArrayList<>(); - private ArrayList menuContributions = new ArrayList<>(); - private ArrayList toolBarContributions = new ArrayList<>(); - private ArrayList trimContributions = new ArrayList<>(); + private final ArrayList menuContributions = new ArrayList<>(); + private final ArrayList toolBarContributions = new ArrayList<>(); + private final ArrayList trimContributions = new ArrayList<>(); private final Comparator comparer = (c1, c2) -> c1.getContributor().getName() .compareToIgnoreCase(c2.getContributor().getName()); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/SlaveMenuService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/SlaveMenuService.java index a88868bed04..e1da1f484f5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/SlaveMenuService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/SlaveMenuService.java @@ -28,7 +28,7 @@ * @since 3.105 */ public class SlaveMenuService implements IMenuService, IMenuServiceWorkaround { - private IMenuService parentService; + private final IMenuService parentService; /** * @see org.eclipse.ui.services.IServiceWithSources#addSourceProvider(org.eclipse.ui.ISourceProvider) @@ -101,8 +101,7 @@ public void releaseContributions(ContributionManager mgr) { */ @Override public void clearContributions(PartSite site, MPart part) { - if (parentService instanceof IMenuServiceWorkaround) { - IMenuServiceWorkaround service = (IMenuServiceWorkaround) parentService; + if (parentService instanceof IMenuServiceWorkaround service) { service.clearContributions(site, part); } } @@ -121,7 +120,7 @@ public SlaveMenuService(IMenuService parent, MApplicationElement model) { this.model = model; } - private MApplicationElement model; + private final MApplicationElement model; public MApplicationElement getModel() { return model; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/WorkbenchMenuService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/WorkbenchMenuService.java index 2ef11ab428f..b9cfe948cfc 100755 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/WorkbenchMenuService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/menus/WorkbenchMenuService.java @@ -75,12 +75,12 @@ public class WorkbenchMenuService implements IMenuService, IMenuServiceWorkaroun private static final String POPULATED_TOOL_BARS = "populatedToolBars"; //$NON-NLS-1$ private static final String POPULATED_MENUS = "populatedMenus"; //$NON-NLS-1$ - private IEclipseContext e4Context; - private ServiceLocator serviceLocator; + private final IEclipseContext e4Context; + private final ServiceLocator serviceLocator; private ExpressionContext legacyContext; - private MenuPersistence persistence; - private Map factoriesToContributions = new HashMap<>(); - private EModelService modelService; + private final MenuPersistence persistence; + private final Map factoriesToContributions = new HashMap<>(); + private final EModelService modelService; public WorkbenchMenuService(ServiceLocator serviceLocator, IEclipseContext e4Context) { this.serviceLocator = serviceLocator; @@ -181,8 +181,9 @@ public void removeContributionFactory(AbstractContributionFactory factory) { Object contribution; if ((contribution = factoriesToContributions.remove(factory)) != null) { MApplication app = e4Context.get(MApplication.class); - if (app == null) + if (app == null) { return; + } if (contribution instanceof MMenuContribution) { app.getMenuContributions().remove(contribution); } else if (contribution instanceof MToolBarContribution) { @@ -193,8 +194,9 @@ public void removeContributionFactory(AbstractContributionFactory factory) { } protected IWorkbenchWindow getWindow() { - if (serviceLocator == null) + if (serviceLocator == null) { return null; + } IWorkbenchLocationService wls = serviceLocator.getService(IWorkbenchLocationService.class); @@ -230,8 +232,7 @@ public void populateContributionManager(MApplicationElement model, ContributionM MenuLocationURI uri = new MenuLocationURI(location); // Now handle registering dynamic additions by querying E4 model - if (mgr instanceof MenuManager) { - MenuManager menu = (MenuManager) mgr; + if (mgr instanceof MenuManager menu) { MMenu mMenu = getMenuModel(model, menu, uri); if (mMenu == null) { return; @@ -239,8 +240,7 @@ public void populateContributionManager(MApplicationElement model, ContributionM IRendererFactory factory = e4Context.get(IRendererFactory.class); AbstractPartRenderer obj = factory.getRenderer(mMenu, null); - if (obj instanceof MenuManagerRenderer) { - MenuManagerRenderer renderer = (MenuManagerRenderer) obj; + if (obj instanceof MenuManagerRenderer renderer) { mMenu.setRenderer(renderer); renderer.reconcileManagerToModel(menu, mMenu); renderer.processContributions(mMenu, uri.getPath(), false, "popup".equals(uri.getScheme())); //$NON-NLS-1$ @@ -254,8 +254,7 @@ public void populateContributionManager(MApplicationElement model, ContributionM } MenuManagerRendererFilter.updateElementVisibility(mMenu, renderer, menu, evalContext, 2, true); } - } else if (mgr instanceof ToolBarManager) { - ToolBarManager toolbar = (ToolBarManager) mgr; + } else if (mgr instanceof ToolBarManager toolbar) { MToolBar mToolBar = getToolbarModel(model, toolbar, uri); if (mToolBar == null) { return; @@ -263,8 +262,7 @@ public void populateContributionManager(MApplicationElement model, ContributionM IRendererFactory factory = e4Context.get(IRendererFactory.class); AbstractPartRenderer obj = factory.getRenderer(mToolBar, null); - if (obj instanceof ToolBarManagerRenderer) { - ToolBarManagerRenderer renderer = (ToolBarManagerRenderer) obj; + if (obj instanceof ToolBarManagerRenderer renderer) { mToolBar.setRenderer(renderer); renderer.reconcileManagerToModel(toolbar, mToolBar); renderer.processContribution(mToolBar, uri.getPath()); @@ -280,10 +278,9 @@ protected MToolBar getToolbarModel(MApplicationElement model, ToolBarManager too MenuLocationURI location) { final IRendererFactory factory = e4Context.get(IRendererFactory.class); final AbstractPartRenderer obj = factory.getRenderer(MenuFactoryImpl.eINSTANCE.createToolBar(), null); - if (!(obj instanceof ToolBarManagerRenderer)) { + if (!(obj instanceof ToolBarManagerRenderer renderer)) { return null; } - ToolBarManagerRenderer renderer = (ToolBarManagerRenderer) obj; MToolBar mToolBar = renderer.getToolBarModel(toolbarManager); if (mToolBar != null) { String tag = "toolbar:" + location.getPath(); //$NON-NLS-1$ @@ -340,10 +337,9 @@ protected MMenu getMenuModel(MApplicationElement model, MenuManager menuManager, final IRendererFactory factory = e4Context.get(IRendererFactory.class); final AbstractPartRenderer obj = factory.getRenderer(((WorkbenchWindow) getWindow()).getModel().getMainMenu(), null); - if (!(obj instanceof MenuManagerRenderer)) { + if (!(obj instanceof MenuManagerRenderer renderer)) { return null; } - MenuManagerRenderer renderer = (MenuManagerRenderer) obj; MMenu mMenu = renderer.getMenuModel(menuManager); if (mMenu != null) { final String tag; @@ -388,11 +384,9 @@ private MPart getPartToExtend() { @Override public void releaseContributions(ContributionManager mgr) { - if (mgr instanceof MenuManager) { - MenuManager menu = (MenuManager) mgr; + if (mgr instanceof MenuManager menu) { releaseContributionManager(menu); - } else if (mgr instanceof ToolBarManager) { - ToolBarManager toolbar = (ToolBarManager) mgr; + } else if (mgr instanceof ToolBarManager toolbar) { releaseContributionManager(toolbar); } else { WorkbenchPlugin.log("releaseContributions: Unhandled manager: " + mgr); //$NON-NLS-1$ @@ -402,10 +396,9 @@ public void releaseContributions(ContributionManager mgr) { private void releaseContributionManager(ToolBarManager toolbarManager) { final IRendererFactory factory = e4Context.get(IRendererFactory.class); final AbstractPartRenderer obj = factory.getRenderer(MenuFactoryImpl.eINSTANCE.createToolBar(), null); - if (!(obj instanceof ToolBarManagerRenderer)) { + if (!(obj instanceof ToolBarManagerRenderer renderer)) { return; } - ToolBarManagerRenderer renderer = (ToolBarManagerRenderer) obj; MToolBar mToolBar = renderer.getToolBarModel(toolbarManager); if (mToolBar == null) { return; @@ -431,10 +424,9 @@ private void releaseContributionManager(MenuManager menuManager) { final IRendererFactory factory = e4Context.get(IRendererFactory.class); final AbstractPartRenderer obj = factory.getRenderer(((WorkbenchWindow) getWindow()).getModel().getMainMenu(), null); - if (!(obj instanceof MenuManagerRenderer)) { + if (!(obj instanceof MenuManagerRenderer renderer)) { return; } - MenuManagerRenderer renderer = (MenuManagerRenderer) obj; MMenu mMenu = renderer.getMenuModel(menuManager); if (mMenu == null) { return; @@ -469,9 +461,8 @@ public void clearContributions(PartSite site, MPart part) { for (MToolBar mToolBar : toolbars) { ((Notifier) mToolBar).eAdapters().clear(); AbstractPartRenderer apr = rendererFactory.getRenderer(mToolBar, null); - if (apr instanceof ToolBarManagerRenderer) { + if (apr instanceof ToolBarManagerRenderer tbmr) { ToolBarManager tbm = (ToolBarManager) actionBars.getToolBarManager(); - ToolBarManagerRenderer tbmr = (ToolBarManagerRenderer) apr; tbmr.clearModelToManager(mToolBar, tbm); CompatibilityView.clearOpaqueToolBarItems(tbmr, mToolBar); } @@ -486,9 +477,8 @@ public void clearContributions(PartSite site, MPart part) { for (MMenu mMenu : menus) { ((Notifier) mMenu).eAdapters().clear(); AbstractPartRenderer apr = rendererFactory.getRenderer(mMenu, null); - if (apr instanceof MenuManagerRenderer) { + if (apr instanceof MenuManagerRenderer tbmr) { MenuManager tbm = (MenuManager) actionBars.getMenuManager(); - MenuManagerRenderer tbmr = (MenuManagerRenderer) apr; tbmr.clearModelToManager(mMenu, tbm); CompatibilityView.clearOpaqueMenuItems(tbmr, mMenu); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ExternalEditor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ExternalEditor.java index b587635a276..aee4c258db4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ExternalEditor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ExternalEditor.java @@ -32,9 +32,9 @@ import org.osgi.framework.Bundle; public class ExternalEditor { - private IPath filePath; + private final IPath filePath; - private EditorDescriptor descriptor; + private final EditorDescriptor descriptor; /** * Create an external editor. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ExternalProgramImageDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ExternalProgramImageDescriptor.java index 8b08b5fb297..596e4ba787a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ExternalProgramImageDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ExternalProgramImageDescriptor.java @@ -26,7 +26,7 @@ */ public class ExternalProgramImageDescriptor extends ImageDescriptor implements IAdaptable { - private Program program; + private final Program program; /** * Creates a new ImageDescriptor. The image is loaded from a file with the given diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/Policy.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/Policy.java index ca6e3cb07eb..4d67b61e5e8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/Policy.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/Policy.java @@ -192,8 +192,9 @@ public class Policy { DEBUG_MPE = getDebugOption("/trace/multipageeditor"); //$NON-NLS-1$ DEBUG_WORKING_SETS = getDebugOption("/debug/workingSets"); //$NON-NLS-1$ - if (DEBUG_SWT_DEBUG_GLOBAL) + if (DEBUG_SWT_DEBUG_GLOBAL) { Device.DEBUG = true; + } } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ProgramImageDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ProgramImageDescriptor.java index 2f4f4bdb67f..afdae211056 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ProgramImageDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/ProgramImageDescriptor.java @@ -23,9 +23,9 @@ * An image descriptor that loads its data from a program file. */ public class ProgramImageDescriptor extends ImageDescriptor { - private String filename; + private final String filename; - private int offset; + private final int offset; /** * Creates a new ImageDescriptor. The image is loaded from a file with the given @@ -41,10 +41,9 @@ public ProgramImageDescriptor(String fullPath, int offsetInFile) { */ @Override public boolean equals(Object o) { - if (!(o instanceof ProgramImageDescriptor)) { + if (!(o instanceof ProgramImageDescriptor other)) { return false; } - ProgramImageDescriptor other = (ProgramImageDescriptor) o; return filename.equals(other.filename) && offset == other.offset; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/StatusUtil.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/StatusUtil.java index 3284177102d..de4ca0c0861 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/StatusUtil.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/StatusUtil.java @@ -88,8 +88,7 @@ public static String getLocalizedMessage(Throwable exception) { // Workaround for the fact that CoreException does not implement a // getLocalizedMessage() method. // Remove this branch when and if CoreException implements getLocalizedMessage() - if (exception instanceof CoreException) { - CoreException ce = (CoreException) exception; + if (exception instanceof CoreException ce) { return ce.getStatus().getMessage(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/model/ContributionService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/model/ContributionService.java index 6707f6e8d90..dde38b72517 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/model/ContributionService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/model/ContributionService.java @@ -20,7 +20,7 @@ public class ContributionService implements IContributionService { - private WorkbenchAdvisor advisor; + private final WorkbenchAdvisor advisor; public ContributionService(WorkbenchAdvisor advisor) { this.advisor = advisor; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/operations/AdvancedValidationUserApprover.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/operations/AdvancedValidationUserApprover.java index 57989304ddc..19f154582ba 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/operations/AdvancedValidationUserApprover.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/operations/AdvancedValidationUserApprover.java @@ -66,7 +66,7 @@ public class AdvancedValidationUserApprover implements IOperationApprover, IOper */ public static boolean AUTOMATED_MODE = false; - private IUndoContext context; + private final IUndoContext context; private static final int EXECUTING = 1; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/operations/TimeTriggeredProgressMonitorDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/operations/TimeTriggeredProgressMonitorDialog.java index 4fda177d111..b9a23f3e927 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/operations/TimeTriggeredProgressMonitorDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/operations/TimeTriggeredProgressMonitorDialog.java @@ -34,7 +34,7 @@ public class TimeTriggeredProgressMonitorDialog extends ProgressMonitorDialog { /** * The time considered to be the long operation time. */ - private int longOperationTime; + private final int longOperationTime; /** * The time at which the dialog should be opened. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/part/NullEditorInput.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/part/NullEditorInput.java index 7c525a850f2..f993b20cf55 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/part/NullEditorInput.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/part/NullEditorInput.java @@ -71,8 +71,9 @@ public IPersistableElement getPersistable() { @Override public String getToolTipText() { - if (editorReference != null) + if (editorReference != null) { return editorReference.getTitleToolTip(); + } return ""; //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/part/StatusPart.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/part/StatusPart.java index e517245ed56..b7c577a4598 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/part/StatusPart.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/part/StatusPart.java @@ -45,10 +45,10 @@ public class StatusPart { private static final String LOG_VIEW_ID = "org.eclipse.pde.runtime.LogView"; //$NON-NLS-1$ boolean showingDetails = false; - private Button detailsButton; - private Composite detailsArea; + private final Button detailsButton; + private final Composite detailsArea; private Control details = null; - private IStatus reason; + private final IStatus reason; public StatusPart(final Composite parent, IStatus reason_) { Color bgColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/PreferenceTransferElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/PreferenceTransferElement.java index 45a445450d6..1ad8133873e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/PreferenceTransferElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/PreferenceTransferElement.java @@ -35,11 +35,11 @@ * @since 3.1 */ public class PreferenceTransferElement extends WorkbenchAdapter implements IPluginContribution { - private String id; + private final String id; private ImageDescriptor imageDescriptor; - private IConfigurationElement configurationElement; + private final IConfigurationElement configurationElement; private IPreferenceFilter filter; @@ -136,8 +136,8 @@ public String getPluginId() { static class PreferenceFilter implements IPreferenceFilter { - private String[] scopes; - private Map> mappings; + private final String[] scopes; + private final Map> mappings; public PreferenceFilter(String[] scopes, Map> mappings) { this.scopes = scopes; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/PropertyMapAdapter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/PropertyMapAdapter.java index ed13a31c067..5a19a111885 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/PropertyMapAdapter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/PropertyMapAdapter.java @@ -24,7 +24,7 @@ public abstract class PropertyMapAdapter implements IDynamicPropertyMap { private PropertyListenerList listeners; private int ignoreCount = 0; - private ArrayList queuedEvents = new ArrayList<>(); + private final ArrayList queuedEvents = new ArrayList<>(); @Override public final void addListener(IPropertyMapListener listener) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/ThemeAdapter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/ThemeAdapter.java index 658b046e63f..d6eec74b675 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/ThemeAdapter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/ThemeAdapter.java @@ -26,9 +26,9 @@ */ public class ThemeAdapter extends PropertyMapAdapter { - private ITheme targetTheme; + private final ITheme targetTheme; - private IPropertyChangeListener listener = event -> firePropertyChange(event.getProperty()); + private final IPropertyChangeListener listener = event -> firePropertyChange(event.getProperty()); public ThemeAdapter(ITheme targetTheme) { this.targetTheme = targetTheme; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchPreferenceExpressionNode.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchPreferenceExpressionNode.java index 301e0994cec..2b081b1c7ed 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchPreferenceExpressionNode.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchPreferenceExpressionNode.java @@ -65,8 +65,9 @@ public IPreferenceNode[] getSubNodes() { * Expressions check. */ public static IPreferenceNode getNodeExpression(IPreferenceNode prefNode) { - if (prefNode == null) + if (prefNode == null) { return null; + } if (prefNode instanceof WorkbenchPreferenceExtensionNode) { WorkbenchPreferenceExpressionNode node = (WorkbenchPreferenceExtensionNode) prefNode; if (WorkbenchActivityHelper.restrictUseOf(node)) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchPreferenceExtensionNode.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchPreferenceExtensionNode.java index 6b25c386eb0..a65037543cf 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchPreferenceExtensionNode.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchPreferenceExtensionNode.java @@ -40,7 +40,7 @@ public abstract class WorkbenchPreferenceExtensionNode extends WorkbenchPreferen private Collection keywordReferences; - private IConfigurationElement configurationElement; + private final IConfigurationElement configurationElement; private ImageDescriptor imageDescriptor; @@ -50,7 +50,7 @@ public abstract class WorkbenchPreferenceExtensionNode extends WorkbenchPreferen private int priority; - private String pluginId; + private final String pluginId; /** * Create a new instance of the receiver. @@ -188,8 +188,9 @@ public String getPluginId() { @Override public T getAdapter(Class adapter) { - if (adapter == IConfigurationElement.class) + if (adapter == IConfigurationElement.class) { return adapter.cast(getConfigurationElement()); + } return null; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchSettingsTransfer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchSettingsTransfer.java index 4f029cf8922..3d34a12875f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchSettingsTransfer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkbenchSettingsTransfer.java @@ -50,8 +50,9 @@ protected IPath getNewWorkbenchStateLocation(IPath newWorkspaceRoot) { IPath dataLocation = WorkbenchPlugin.getDefault().getDataLocation(); - if (dataLocation == null) + if (dataLocation == null) { return null; + } int segmentsToRemove = dataLocation.matchingFirstSegments(currentWorkspaceRoot); // Strip it down to the extension diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkingCopyPreferences.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkingCopyPreferences.java index e03c6ff14da..d44d32c3a94 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkingCopyPreferences.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkingCopyPreferences.java @@ -46,7 +46,7 @@ public class WorkingCopyPreferences extends EventManager implements IEclipsePref private final Map temporarySettings; private final IEclipsePreferences original; private boolean removed = false; - private org.eclipse.ui.preferences.WorkingCopyManager manager; + private final org.eclipse.ui.preferences.WorkingCopyManager manager; /** * @param original the underlying preference node diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkingSetSettingsTransfer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkingSetSettingsTransfer.java index c352ef24de5..56a91c0fc65 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkingSetSettingsTransfer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/preferences/WorkingSetSettingsTransfer.java @@ -44,8 +44,9 @@ public String getName() { public IStatus transferSettings(IPath newWorkspaceRoot) { IPath dataLocation = getNewWorkbenchStateLocation(newWorkspaceRoot); - if (dataLocation == null) + if (dataLocation == null) { return noWorkingSettingsStatus(); + } dataLocation = dataLocation.append(WorkingSetManager.WORKING_SET_STATE_FILENAME); @@ -53,11 +54,12 @@ public IStatus transferSettings(IPath newWorkspaceRoot) { try { IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); - if (manager instanceof AbstractWorkingSetManager) + if (manager instanceof AbstractWorkingSetManager) { ((AbstractWorkingSetManager) manager).saveState(stateFile); - else + } else { return new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, WorkbenchMessages.WorkingSets_CannotSave); + } } catch (IOException e) { new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, WorkbenchMessages.ProblemSavingWorkingSetState_message, e); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/BlockedJobsDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/BlockedJobsDialog.java index 811f0c11eea..e0aedefff03 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/BlockedJobsDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/BlockedJobsDialog.java @@ -51,7 +51,7 @@ public class BlockedJobsDialog extends IconAndMessageDialog { */ private Button cancelSelected; - private IProgressMonitor blockingMonitor; + private final IProgressMonitor blockingMonitor; /** * Creates a progress monitor dialog under the given shell. It also sets the @@ -117,8 +117,9 @@ public IStatus runInUIThread(IProgressMonitor monitor) { * @param monitor The monitor that is now cleared. */ public static void clear(IProgressMonitor monitor) { - if (singleton != null) + if (singleton != null) { singleton.close(monitor); + } } /** diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/DetailedProgressViewer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/DetailedProgressViewer.java index c71d74974e6..e5ded48ed3b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/DetailedProgressViewer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/DetailedProgressViewer.java @@ -58,9 +58,9 @@ public class DetailedProgressViewer extends AbstractProgressViewer { Composite control; - private ScrolledComposite scrolled; + private final ScrolledComposite scrolled; - private Composite noEntryArea; + private final Composite noEntryArea; /** * Map to find existing controls for job items. Only elements with a control are @@ -389,8 +389,9 @@ public void remove(JobTreeElement... elements) { if (item == null) { // Is the parent showing? JobTreeElement parent = element.getParent(); - if (parent != null && parent != element) + if (parent != null && parent != element) { remove(parent); + } } items.remove(element); unmapElement(element); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/GroupInfo.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/GroupInfo.java index 7d42132a612..248b9c933d9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/GroupInfo.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/GroupInfo.java @@ -26,8 +26,8 @@ */ class GroupInfo extends JobTreeElement implements IProgressMonitor { - private List infos = new ArrayList<>(); - private Object lock = new Object(); + private final List infos = new ArrayList<>(); + private final Object lock = new Object(); private String taskName = ProgressMessages.SubTaskInfo_UndefinedTaskName; boolean isActive; double total = -1; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/JobInfo.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/JobInfo.java index 1bddd258ca7..d14a3a4103c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/JobInfo.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/JobInfo.java @@ -41,9 +41,9 @@ public class JobInfo extends JobTreeElement { private volatile Optional taskInfo; - private ProgressManager progressManager; + private final ProgressManager progressManager; - private FinishedJobs finishedJobs; + private final FinishedJobs finishedJobs; // Default to no progress private int ticks = -1; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/JobSnapshot.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/JobSnapshot.java index 3a1bb412f2c..4c19efe6b4e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/JobSnapshot.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/JobSnapshot.java @@ -42,7 +42,7 @@ public JobSnapshot(JobTreeElement reference, int index) { this.hashCode = reference.hashCode(); this.displayString = reference.getDisplayString(); - JobInfo jobInfo = (reference instanceof JobInfo) ? (JobInfo) reference : null; + JobInfo jobInfo = (reference instanceof JobInfo j) ? j : null; this.isBlocked = jobInfo == null ? false : jobInfo.isBlocked(); this.isCanceled = jobInfo == null ? false : jobInfo.isCanceled(); @@ -109,8 +109,9 @@ public int compareTo(JobSnapshot other) { return 1; } int n = getName().compareTo(other.getName()); - if (n != 0) + if (n != 0) { return n; + } return getDisplayString().compareTo(other.getDisplayString()); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressAnimationItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressAnimationItem.java index 416b69b2517..c9803dfb245 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressAnimationItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressAnimationItem.java @@ -77,11 +77,11 @@ public class ProgressAnimationItem extends AnimationItem implements FinishedJobs boolean animationRunning; // ProgressBar flags - private int flags; + private final int flags; private AccessibleListener currentAccessibleListener; - private Throttler throttledRefresh = new Throttler(PlatformUI.getWorkbench().getDisplay(), Duration.ofMillis(100), + private final Throttler throttledRefresh = new Throttler(PlatformUI.getWorkbench().getDisplay(), Duration.ofMillis(100), this::refresh); /** @@ -109,8 +109,7 @@ void doAction() { JobTreeElement[] jobTreeElements = FinishedJobs.getInstance().getKeptElements(); // search from end (youngest) for (int i = jobTreeElements.length - 1; i >= 0; i--) { - if (jobTreeElements[i] instanceof JobInfo) { - JobInfo ji = (JobInfo) jobTreeElements[i]; + if (jobTreeElements[i] instanceof JobInfo ji) { Job job = ji.getJob(); if (job != null) { @@ -118,8 +117,9 @@ void doAction() { if (status != null && status.getSeverity() == IStatus.ERROR) { StatusAdapter statusAdapter = StatusAdapterHelper.getInstance().getStatusAdapter(ji); - if (statusAdapter == null) + if (statusAdapter == null) { statusAdapter = new StatusAdapter(status); + } StatusManager.getManager().handle(statusAdapter, StatusManager.SHOW); @@ -146,16 +146,14 @@ void doAction() { private boolean execute(JobInfo ji, Job job) { Object prop = job.getProperty(IProgressConstants.ACTION_PROPERTY); - if (prop instanceof IAction && ((IAction) prop).isEnabled()) { - IAction action = (IAction) prop; + if (prop instanceof IAction action && action.isEnabled()) { action.run(); removeTopElement(ji); return true; } prop = job.getProperty(IProgressConstants2.COMMAND_PROPERTY); - if (prop instanceof ParameterizedCommand) { - ParameterizedCommand command = (ParameterizedCommand) prop; + if (prop instanceof ParameterizedCommand command) { IWorkbenchWindow window = getWindow(); IHandlerService service = window.getService(IHandlerService.class); Exception exception = null; @@ -227,8 +225,7 @@ private void refresh() { JobTreeElement[] jobTreeElements = FinishedJobs.getInstance().getKeptElements(); // search from end (youngest) for (int i = jobTreeElements.length - 1; i >= 0; i--) { - if (jobTreeElements[i] instanceof JobInfo) { - JobInfo ji = (JobInfo) jobTreeElements[i]; + if (jobTreeElements[i] instanceof JobInfo ji) { Job job = ji.getJob(); if (job != null) { IStatus status = job.getResult(); @@ -269,8 +266,9 @@ private void initButton(Image im, final String tt) { toolbar.setVisible(true); toolbar.getParent().requestLayout(); // must layout - if (currentAccessibleListener != null) + if (currentAccessibleListener != null) { toolbar.getAccessible().removeAccessibleListener(currentAccessibleListener); + } currentAccessibleListener = new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { @@ -302,8 +300,9 @@ protected Control createAnimationItem(Composite parent) { boolean isCarbon = Util.isMac(); GridLayout gl = new GridLayout(); - if (isHorizontal()) + if (isHorizontal()) { gl.numColumns = isCarbon ? 3 : 2; + } gl.marginHeight = 0; gl.marginWidth = 0; if (isHorizontal()) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressCanvasViewer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressCanvasViewer.java index a745d6a3a3a..d0244accfcb 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressCanvasViewer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressCanvasViewer.java @@ -44,11 +44,11 @@ public class ProgressCanvasViewer extends AbstractProgressViewer { /** * Font metrics to use for determining pixel sizes. */ - private FontMetrics fontMetrics; + private final FontMetrics fontMetrics; private int numShowItems = 1; - private int maxCharacterWidth; + private final int maxCharacterWidth; private int orientation = SWT.HORIZONTAL; @@ -173,8 +173,9 @@ private void initializeListeners() { gc.drawString(string, xOffset + (i * fontMetrics.getHeight()), 2, true); } } - if (transform != null) + if (transform != null) { transform.dispose(); + } }); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressInfoItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressInfoItem.java index 66394732cbd..bab4d87ce2b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressInfoItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressInfoItem.java @@ -150,7 +150,7 @@ interface IndexListener { private HandlerChangeTracker tracker; - private boolean isThemed; + private final boolean isThemed; static { ImageDescriptor processStopDescriptor = WorkbenchImages.getWorkbenchImageDescriptor("elcl16/progress_stop.svg"); //$NON-NLS-1$ @@ -340,8 +340,9 @@ private Image getInfoImage() { image = getResourceManager().createImageWithDefault(descriptor); } - if (image == null) + if (image == null) { image = jobInfo.getDisplayImage(); + } return image; } @@ -352,8 +353,9 @@ private Image getInfoImage() { * @return {@link ResourceManager} */ private ResourceManager getResourceManager() { - if (resourceManager == null) + if (resourceManager == null) { resourceManager = new LocalResourceManager(JFaceResources.getResources()); + } return resourceManager; } @@ -390,8 +392,9 @@ public String getJobNameAndStatus(JobInfo jobInfo) { } if (jobInfo.isCanceled()) { - if (job.getState() == Job.RUNNING) + if (job.getState() == Job.RUNNING) { return NLS.bind(ProgressMessages.JobInfo_Cancel_Requested, name); + } return NLS.bind(ProgressMessages.JobInfo_Cancelled, name); } @@ -450,8 +453,9 @@ private String getTimeString() { void refresh() { // Don't refresh if not visible - if (isDisposed() || !isShowing) + if (isDisposed() || !isShowing) { return; + } jobImageLabel.setImage(getInfoImage()); int percentDone = getPercentDone(); @@ -539,10 +543,11 @@ else if (isCompleted()) { taskEntries.get(i).dispose(); } - if (infos.length > 1) + if (infos.length > 1) { taskEntries = taskEntries.subList(0, infos.length - 1); - else + } else { taskEntries.clear(); + } } updateToolBarValues(); @@ -594,8 +599,9 @@ private boolean isRunning() { for (JobInfo jobInfo : getJobInfos()) { int state = jobInfo.getJob().getState(); - if (state == Job.WAITING || state == Job.RUNNING) + if (state == Job.WAITING || state == Job.RUNNING) { return true; + } } return false; } @@ -708,8 +714,9 @@ void setLinkText(Job linkJob, String taskString, int index) { link.addListener(SWT.Resize, event -> { Object text = link.getData(TEXT_KEY); - if (text == null) + if (text == null) { return; + } updateText((String) text, link); @@ -746,10 +753,10 @@ void setLinkText(Job linkJob, String taskString, int index) { */ public void executeTrigger() { Object data = link.getData(TRIGGER_KEY); - if (data instanceof IAction) { - IAction action = (IAction) data; - if (action.isEnabled()) + if (data instanceof IAction action) { + if (action.isEnabled()) { action.run(); + } updateTrigger(action, link); } else if (data instanceof ParameterizedCommand) { IWorkbench workbench = PlatformUI.getWorkbench(); @@ -773,8 +780,9 @@ public void executeTrigger() { } Object text = link.getData(TEXT_KEY); - if (text == null) + if (text == null) { return; + } // Refresh the text as enablement might have changed updateText((String) text, link); @@ -932,15 +940,17 @@ private void setDisplayed(boolean displayed) { // See if this element has been turned off boolean refresh = !isShowing && displayed; isShowing = displayed; - if (refresh) + if (refresh) { refresh(); + } } @Override public void dispose() { super.dispose(); - if (resourceManager != null) + if (resourceManager != null) { resourceManager.dispose(); + } } /** @@ -963,8 +973,9 @@ public boolean isTriggerEnabled() { /** Called whenever trigger details change */ private void hookTriggerCommandEnablement() { final Object data = link.getData(TRIGGER_KEY); - if (!(data instanceof ParameterizedCommand) || !PlatformUI.isWorkbenchRunning()) + if (!(data instanceof ParameterizedCommand) || !PlatformUI.isWorkbenchRunning()) { return; + } // Would be nice to have the window's context, but we're too deep IEclipseContext context = PlatformUI.getWorkbench().getService(IEclipseContext.class); @@ -983,7 +994,7 @@ private void hookTriggerCommandEnablement() { * A RAT to update the trigger link on handler changes for the given command */ private class HandlerChangeTracker extends RunAndTrack { - private ParameterizedCommand parmCommand; + private final ParameterizedCommand parmCommand; private boolean stop = false; public HandlerChangeTracker(ParameterizedCommand parmCommand) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManager.java index 542dd60b1fb..e9b35fe2010 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManager.java @@ -106,7 +106,7 @@ public class ProgressManager extends ProgressProvider implements IProgressServic .synchronizedMap(new LinkedHashMap<>()); // list of IJobProgressManagerListener - private ListenerList listeners = new ListenerList<>(); + private final ListenerList listeners = new ListenerList<>(); final IJobChangeListener changeListener; @@ -138,7 +138,7 @@ public class ProgressManager extends ProgressProvider implements IProgressServic final Map runnableMonitors = new HashMap<>(); // A table that maps families to keys in the Jface image table - private Hashtable imageKeyTable = new Hashtable<>(); + private final Hashtable imageKeyTable = new Hashtable<>(); /** * Lock object for synchronizing updates of {@code pendingJobUpdates}, @@ -508,8 +508,9 @@ public void awake(IJobChangeEvent event) { @Override public void sleeping(IJobChangeEvent event) { - if (managedJobs.contains(event.getJob()))// Are we showing this? + if (managedJobs.contains(event.getJob())) { // Are we showing this? sleepJobInfo(progressFor(event.getJob()).getJobInfo()); + } } }; } @@ -528,8 +529,9 @@ protected void sleepJobInfo(JobInfo info) { for (IJobProgressManagerListener listener : listeners) { // Is this one the user never sees? - if (isNeverDisplaying(info.getJob(), listener.showsDebug())) + if (isNeverDisplaying(info.getJob(), listener.showsDebug())) { continue; + } if (listener.showsDebug()) { listener.refreshJobInfo(info); } else { @@ -543,8 +545,9 @@ protected void sleepJobInfo(JobInfo info) { */ private void sleepGroup(GroupInfo group, JobInfo info) { for (IJobProgressManagerListener listener : listeners) { - if (isNeverDisplaying(info.getJob(), listener.showsDebug())) + if (isNeverDisplaying(info.getJob(), listener.showsDebug())) { continue; + } if (listener.showsDebug() || group.isActive()) { listener.refreshGroup(group); @@ -731,8 +734,9 @@ boolean isCurrentDisplaying(Job job, boolean debug) { * @return boolean */ boolean isNeverDisplaying(Job job, boolean debug) { - if (debug) + if (debug) { return false; + } return job.isSystem(); } @@ -887,8 +891,7 @@ public IProgressMonitor createProgressGroup() { @Override public IProgressMonitor createMonitor(Job job, IProgressMonitor group, int ticks) { JobMonitor monitor = progressFor(job); - if (group instanceof GroupInfo) { - GroupInfo groupInfo = (GroupInfo) group; + if (group instanceof GroupInfo groupInfo) { JobInfo jobInfo = monitor.getJobInfo(); jobInfo.setGroupInfo(groupInfo); jobInfo.setTicks(ticks); @@ -1122,8 +1125,9 @@ public void run() { * @return the monitor on the event loop */ private IProgressMonitor getEventLoopMonitor() { - if (PlatformUI.getWorkbench().isStarting()) + if (PlatformUI.getWorkbench().isStarting()) { return new NullProgressMonitor(); + } return new EventLoopProgressMonitor(new NullProgressMonitor()) { @Override diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManagerUtil.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManagerUtil.java index 021efdd3cb7..ebb9796fc8a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManagerUtil.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManagerUtil.java @@ -467,8 +467,9 @@ public static Shell getDefaultParent() { } Shell nonModalShell = getNonModalShell(); - if (nonModalShell != null && nonModalShell.isVisible()) + if (nonModalShell != null && nonModalShell.isVisible()) { return nonModalShell; + } Shell splashShell = WorkbenchPlugin.getSplashShell(PlatformUI.getWorkbench().getDisplay()); if (splashShell != null && splashShell.isVisible()) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressMonitorFocusJobDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressMonitorFocusJobDialog.java index 82eb0f06838..b462bdc2e56 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressMonitorFocusJobDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressMonitorFocusJobDialog.java @@ -269,9 +269,10 @@ protected void createExtendedDialogArea(Composite parent) { @Override public boolean close() { - if (getReturnCode() != CANCEL) + if (getReturnCode() != CANCEL) { WorkbenchPlugin.getDefault().getPreferenceStore().setValue(IPreferenceConstants.RUN_IN_BACKGROUND, showDialog); + } return super.close(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressMonitorJobsDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressMonitorJobsDialog.java index 0effd56f2a9..bb0c936ead8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressMonitorJobsDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressMonitorJobsDialog.java @@ -210,8 +210,9 @@ protected void clearCursors() { @Override protected void updateForSetBlocked(IStatus reason) { - if (alreadyClosed) + if (alreadyClosed) { return; + } super.updateForSetBlocked(reason); enableDetails(true); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressRegion.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressRegion.java index bffdd0db1a2..85433a124e2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressRegion.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressRegion.java @@ -94,9 +94,9 @@ public Control createContents(Composite parent) { @Override public Point computeSize(int wHint, int hHint, boolean changed) { Point size = super.computeSize(wHint, hHint, changed); - if (isHorizontal()) + if (isHorizontal()) { size.y = TrimUtil.TRIM_DEFAULT_HEIGHT; - else { + } else { size.x = TrimUtil.TRIM_DEFAULT_HEIGHT; } return size; @@ -106,8 +106,9 @@ public Point computeSize(int wHint, int hHint, boolean changed) { GridLayout gl = new GridLayout(); gl.marginHeight = 0; gl.marginWidth = 0; - if (isHorizontal()) + if (isHorizontal()) { gl.numColumns = 3; + } region.setLayout(gl); viewer = new ProgressCanvasViewer(region, SWT.NO_FOCUS, 1, 36, isHorizontal() ? SWT.HORIZONTAL : SWT.VERTICAL); @@ -171,8 +172,7 @@ public void mouseDoubleClick(MouseEvent e) { viewer.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { - if (element instanceof JobInfo) { - JobInfo info = (JobInfo) element; + if (element instanceof JobInfo info) { if (info.isBlocked() || info.getJob().getState() == Job.WAITING) { return false; } @@ -215,8 +215,9 @@ public void processDoubleClick() { * @return true if the side is horizontal */ private boolean isHorizontal() { - if (forceHorizontal) + if (forceHorizontal) { return true; + } SideValue loc = getLocation(); return loc == SideValue.TOP || loc == SideValue.BOTTOM; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewUpdater.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewUpdater.java index 10bc22eca25..9afc5353f48 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewUpdater.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewUpdater.java @@ -38,7 +38,7 @@ class ProgressViewUpdater implements IJobProgressManagerListener { * if the collector wants to collect updates for finished jobs * (true) or not. */ - private Map collectors; + private final Map collectors; final UpdatesInfo currentInfo = new UpdatesInfo(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewerContentProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewerContentProvider.java index a76bb8d1102..4244b3bdc32 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewerContentProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewerContentProvider.java @@ -24,7 +24,7 @@ public class ProgressViewerContentProvider extends ProgressContentProvider { /** Viewer to show content. */ protected AbstractProgressViewer progressViewer; - private boolean showFinished; + private final boolean showFinished; /** flag if we need a full refresh */ private boolean refreshNeeded; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewerLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewerLabelProvider.java index 32e27062f1f..0c0d2d3784b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewerLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressViewerLabelProvider.java @@ -20,7 +20,7 @@ * The ProgressViewerLabelProvider is the label provider for progress viewers. */ public class ProgressViewerLabelProvider extends LabelProvider { - private Control control; + private final Control control; @Override public String getText(Object element) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/SubTaskInfo.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/SubTaskInfo.java index b3eee1a203c..d2140db2598 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/SubTaskInfo.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/SubTaskInfo.java @@ -50,10 +50,11 @@ boolean hasChildren() { * Sets the taskName of the receiver. */ void setTaskName(String name) { - if (name == null) + if (name == null) { taskName = ProgressMessages.SubTaskInfo_UndefinedTaskName; - else + } else { this.taskName = name; + } } /** diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/TaskBarProgressManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/TaskBarProgressManager.java index 41160eeed6f..c9054edc6d5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/TaskBarProgressManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/TaskBarProgressManager.java @@ -43,15 +43,15 @@ */ public class TaskBarProgressManager { - private IJobProgressManagerListener listener; + private final IJobProgressManagerListener listener; - private WorkbenchJob animationUpdateJob; + private final WorkbenchJob animationUpdateJob; private boolean isAnimated = false; - private List jobs = Collections.synchronizedList(new ArrayList<>()); + private final List jobs = Collections.synchronizedList(new ArrayList<>()); - private Map jobInfoMap = Collections.synchronizedMap(new HashMap<>()); + private final Map jobInfoMap = Collections.synchronizedMap(new HashMap<>()); private final TaskItem taskItem; @@ -154,8 +154,9 @@ private int getPercentDone(JobTreeElement info) { } private void updateImage(Job job) { - if (taskItem == null || taskItem.isDisposed()) + if (taskItem == null || taskItem.isDisposed()) { return; + } if (job == null) { disposeOverlay(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java index efaadb11d1a..5b4a263a140 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java @@ -62,17 +62,17 @@ public class WorkbenchSiteProgressService implements IWorkbenchSiteProgressServi * requested. * */ - private Map busyJobs = new HashMap<>(); + private final Map busyJobs = new HashMap<>(); - private Object busyLock = new Object(); + private final Object busyLock = new Object(); IPropertyChangeListener[] changeListeners = new IPropertyChangeListener[0]; private int waitCursorJobCount; - private Object waitCursorLock = new Object(); + private final Object waitCursorLock = new Object(); - private SiteUpdateJob updateJob; + private final SiteUpdateJob updateJob; /** * Flag that keeps state from calls to {@link #incrementBusy()} and @@ -229,8 +229,9 @@ private void incrementBusy(Job job, boolean useHalfBusyCursor) { Object halfBusyCursorState; synchronized (busyLock) { halfBusyCursorState = busyJobs.get(job); - if (useHalfBusyCursor || halfBusyCursorState != Boolean.TRUE) + if (useHalfBusyCursor || halfBusyCursorState != Boolean.TRUE) { busyJobs.put(job, Boolean.valueOf(useHalfBusyCursor)); + } } if (useHalfBusyCursor && halfBusyCursorState != Boolean.TRUE) { // want to set busy cursor and it has not been set before diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/PreviousPicksProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/PreviousPicksProvider.java index 5e9ec811310..f5bfc38ff27 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/PreviousPicksProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/PreviousPicksProvider.java @@ -29,7 +29,7 @@ class PreviousPicksProvider extends QuickAccessProvider { LinkedList elements; - private int maxNumberOfElements; + private final int maxNumberOfElements; private Supplier> initializer; private Collection initialProviders; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java index a9fc87fba67..4ee066c959d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java @@ -101,9 +101,9 @@ public abstract class QuickAccessContents { protected Text filterText; - private QuickAccessProvider[] providers; + private final QuickAccessProvider[] providers; private Map providerMap = new HashMap<>(); - private Map elementsToProviders = new HashMap<>(); + private final Map elementsToProviders = new HashMap<>(); protected Table table; protected Label infoLabel; @@ -573,8 +573,9 @@ protected Pattern getCategoryPattern() { StringBuilder sb = new StringBuilder(); sb.append("^(:?"); //$NON-NLS-1$ for (int i = 0; i < providers.length; i++) { - if (i != 0) + if (i != 0) { sb.append("|"); //$NON-NLS-1$ + } sb.append(providers[i].getName()); } sb.append("):\\s?(.*)"); //$NON-NLS-1$ @@ -790,17 +791,20 @@ public void keyReleased(KeyEvent e) { @Override public void mouseUp(MouseEvent e) { - if (table.getSelectionCount() < 1) + if (table.getSelectionCount() < 1) { return; + } - if (e.button != 1) + if (e.button != 1) { return; + } if (table.equals(e.getSource())) { Object o = table.getItem(new Point(e.x, e.y)); TableItem selection = table.getSelection()[0]; - if (selection.equals(o)) + if (selection.equals(o)) { handleSelection(); + } } } }); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessDialog.java index 037abb060bd..dee11c83069 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessDialog.java @@ -198,7 +198,7 @@ protected QuickAccessElement getPerfectMatch(String filter) { @Override protected void handleElementSelected(String text, Object selectedElement) { lastSelectionFilter = text; - if (selectedElement instanceof QuickAccessElement) { + if (selectedElement instanceof final QuickAccessElement element) { addPreviousPick(text, (QuickAccessElement) selectedElement); storeDialog(getDialogSettings()); @@ -206,7 +206,6 @@ protected void handleElementSelected(String text, Object selectedElement) { * Execute after the dialog has been fully closed/disposed and the correct * EclipseContext is in place. */ - final QuickAccessElement element = (QuickAccessElement) selectedElement; window.getShell().getDisplay().asyncExec(element::execute); } } @@ -272,8 +271,9 @@ public void keyPressed(KeyEvent e) { KeySequence keySequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); TriggerSequence[] sequences = getInvokingCommandKeySequences(); - if (sequences == null) + if (sequences == null) { return; + } for (TriggerSequence sequence : sequences) { if (sequence.equals(keySequence)) { e.doit = false; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessEntry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessEntry.java index a4875f9deee..d27ea8eed76 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessEntry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessEntry.java @@ -54,7 +54,7 @@ public class QuickAccessEntry { * the filter string was an exact match to the label or that there is no filter * being applied. */ - private int matchQuality; + private final int matchQuality; /** * Indicates the filter string was a perfect match to the label or there is no @@ -209,8 +209,7 @@ public void paint(Event event, TextLayout textLayout, ResourceManager resourceMa break; case 1: String label = element.getLabel(); - if (element instanceof CommandElement) { - CommandElement commandElement = (CommandElement) element; + if (element instanceof CommandElement commandElement) { String binding = commandElement.getBinding(); if (binding != null) { StyledString styledString = StyledCellLabelProvider.styleDecoratedString(label, @@ -248,8 +247,9 @@ public void paint(Event event, TextLayout textLayout, ResourceManager resourceMa break; } if (lastInCategory) { - if (grayColor != null) + if (grayColor != null) { event.gc.setForeground(grayColor); + } Rectangle bounds = ((TableItem) event.item).getBounds(event.index); event.gc.drawLine(Math.max(0, bounds.x - 1), bounds.y + bounds.height - 1, bounds.x + bounds.width, bounds.y + bounds.height - 1); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/SearchField.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/SearchField.java index 5d8f66de100..6190370d582 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/SearchField.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/SearchField.java @@ -72,7 +72,7 @@ public class SearchField { private ParameterizedCommand quickAccessCommand; private TriggerSequence triggerSequence = null; - private Listener previousFocusListener = e -> { + private final Listener previousFocusListener = e -> { if (e.widget instanceof Control && e.widget != quickAccessButton) { previousFocusControl = (Control) e.widget; } @@ -198,8 +198,9 @@ private void changeShowText(boolean showText, ToolItem quickAccessToolItem) { } else { quickAccessToolItem.setText(""); //$NON-NLS-1$ } - if (quickAccessButton != null) + if (quickAccessButton != null) { quickAccessButton.getParent().requestLayout(); + } } private void updateQuickAccessText() { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ActionElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ActionElement.java index 77191102f6d..f04553a56e5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ActionElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ActionElement.java @@ -26,7 +26,7 @@ */ public class ActionElement extends QuickAccessElement { - private ActionContributionItem item; + private final ActionContributionItem item; /* package */ ActionElement(ActionContributionItem item) { this.item = item; @@ -63,12 +63,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final ActionElement other = (ActionElement) obj; return Objects.equals(item, other.item); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ActionProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ActionProvider.java index 280d2f78ee0..9a66d769141 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ActionProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ActionProvider.java @@ -61,8 +61,9 @@ public QuickAccessElement[] getElements() { collectContributions(menu, result); ActionContributionItem[] actions = result.toArray(new ActionContributionItem[result.size()]); for (ActionContributionItem action : actions) { - if (!action.isVisible()) + if (!action.isVisible()) { continue; + } ActionElement actionElement = new ActionElement(action); idToElement.put(actionElement.getId(), actionElement); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/CommandElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/CommandElement.java index 217c53f6d6a..fbb01400b9a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/CommandElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/CommandElement.java @@ -40,11 +40,11 @@ */ public class CommandElement extends QuickAccessElement { - private ParameterizedCommand command; + private final ParameterizedCommand command; - private String id; + private final String id; - private CommandProvider provider; + private final CommandProvider provider; /* package */ CommandElement(ParameterizedCommand command, String id, CommandProvider commandProvider) { this.provider = commandProvider; @@ -165,12 +165,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final CommandElement other = (CommandElement) obj; return Objects.equals(command, other.command); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/EditorElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/EditorElement.java index 6097d74ef1b..090d012d514 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/EditorElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/EditorElement.java @@ -30,8 +30,8 @@ public class EditorElement extends QuickAccessElement { private static final String DIRTY_MARK = "*"; //$NON-NLS-1$ - private IEditorReference editorReference; - private boolean dirty; + private final IEditorReference editorReference; + private final boolean dirty; /* package */ EditorElement(IEditorReference editorReference) { this.editorReference = editorReference; @@ -80,12 +80,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final EditorElement other = (EditorElement) obj; return Objects.equals(editorReference, other.editorReference); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/HelpSearchElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/HelpSearchElement.java index 23844542717..b0980f58abb 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/HelpSearchElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/HelpSearchElement.java @@ -29,7 +29,7 @@ public class HelpSearchElement extends QuickAccessElement { /** identifier */ private static final String SEARCH_IN_HELP_ID = "search.in.help"; //$NON-NLS-1$ - private String searchText; + private final String searchText; public HelpSearchElement(String filter) { this.searchText = filter; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PerspectiveElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PerspectiveElement.java index 4dda1214669..0a35bd2c48e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PerspectiveElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PerspectiveElement.java @@ -86,12 +86,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final PerspectiveElement other = (PerspectiveElement) obj; return Objects.equals(descriptor, other.descriptor); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PerspectiveProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PerspectiveProvider.java index 68417b52c51..dfb4ad5da2d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PerspectiveProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PerspectiveProvider.java @@ -33,7 +33,7 @@ public class PerspectiveProvider extends QuickAccessProvider { private QuickAccessElement[] cachedElements; - private Map idToElement = new HashMap<>(); + private final Map idToElement = new HashMap<>(); @Override public String getId() { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PreferenceElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PreferenceElement.java index 11405dded6e..e9dcc947fd5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PreferenceElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PreferenceElement.java @@ -29,9 +29,9 @@ */ public class PreferenceElement extends QuickAccessElement { - private IPreferenceNode preferenceNode; + private final IPreferenceNode preferenceNode; - private String prefix; + private final String prefix; private String matchLabelCache; @@ -95,12 +95,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final PreferenceElement other = (PreferenceElement) obj; return Objects.equals(preferenceNode, other.preferenceNode); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PreferenceProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PreferenceProvider.java index 67603cafd9d..977bcb80631 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PreferenceProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PreferenceProvider.java @@ -35,7 +35,7 @@ public class PreferenceProvider extends QuickAccessProvider { private QuickAccessElement[] cachedElements; - private Map idToElement = new HashMap<>(); + private final Map idToElement = new HashMap<>(); @Override public String getId() { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PropertiesElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PropertiesElement.java index 51c02bd4dae..114a0ee4330 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PropertiesElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/PropertiesElement.java @@ -28,8 +28,8 @@ */ public class PropertiesElement extends QuickAccessElement { - private Object selectedElement; - private IPreferenceNode preferenceNode; + private final Object selectedElement; + private final IPreferenceNode preferenceNode; /* package */ PropertiesElement(Object selectedElement, IPreferenceNode preferenceNode) { this.selectedElement = selectedElement; @@ -72,12 +72,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final PropertiesElement other = (PropertiesElement) obj; return Objects.equals(preferenceNode, other.preferenceNode); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ViewElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ViewElement.java index f9692c6dd38..1092190215b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ViewElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ViewElement.java @@ -39,9 +39,9 @@ */ public class ViewElement extends QuickAccessElement { - private MWindow window; - private MPartDescriptor viewDescriptor; - private ImageDescriptor imageDescriptor; + private final MWindow window; + private final MPartDescriptor viewDescriptor; + private final ImageDescriptor imageDescriptor; private String viewLabel; public ViewElement(MWindow window, MPartDescriptor descriptor) { @@ -128,12 +128,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final ViewElement other = (ViewElement) obj; return Objects.equals(viewDescriptor, other.viewDescriptor); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ViewProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ViewProvider.java index bd6fc7ba617..f47c300ca20 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ViewProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ViewProvider.java @@ -46,10 +46,10 @@ public class ViewProvider extends QuickAccessProvider { * bundleclass://org.eclipse.pde.spy.bundle/org.eclipse.pde.spy.bundle.BundleSpyPart */ private static final String BUNDLE_CLASS_SCHEME = "bundleclass://"; //$NON-NLS-1$ - private MApplication application; - private MWindow window; - private Map idToElement = new HashMap<>(); - private IViewRegistry viewRegistry; + private final MApplication application; + private final MWindow window; + private final Map idToElement = new HashMap<>(); + private final IViewRegistry viewRegistry; public ViewProvider(MApplication application, MWindow window) { this.application = application; @@ -86,8 +86,9 @@ public QuickAccessElement[] getElements() { if (uri.equals(CompatibilityPart.COMPATIBILITY_VIEW_URI)) { IViewDescriptor viewDescriptor = viewRegistry.find(element.getId()); // Ignore if restricted - if (viewDescriptor == null) + if (viewDescriptor == null) { continue; + } // Ignore if filtered if (!WorkbenchActivityHelper.filterItem(viewDescriptor)) { idToElement.put(element.getId(), element); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/WizardElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/WizardElement.java index 645c474a002..86cf289ff12 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/WizardElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/WizardElement.java @@ -27,7 +27,7 @@ */ public class WizardElement extends QuickAccessElement { - private IWizardDescriptor wizardDescriptor; + private final IWizardDescriptor wizardDescriptor; /* package */ WizardElement(IWizardDescriptor wizardDescriptor) { this.wizardDescriptor = wizardDescriptor; @@ -64,12 +64,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final WizardElement other = (WizardElement) obj; return Objects.equals(wizardDescriptor, other.wizardDescriptor); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/WizardProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/WizardProvider.java index 7b920bc3ade..715b78ea99b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/WizardProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/WizardProvider.java @@ -37,7 +37,7 @@ public class WizardProvider extends QuickAccessProvider { private QuickAccessElement[] cachedElements; - private Map idToElement = new HashMap<>(); + private final Map idToElement = new HashMap<>(); @Override public QuickAccessElement findElement(String id, String filter) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ActionSetDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ActionSetDescriptor.java index 5265942675e..b302ec08f34 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ActionSetDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ActionSetDescriptor.java @@ -33,17 +33,17 @@ public class ActionSetDescriptor implements IActionSetDescriptor, IAdaptable, IW private static final String INITIALLY_HIDDEN_PREF_ID_PREFIX = "actionSet.initiallyHidden."; //$NON-NLS-1$ - private String id; + private final String id; - private String pluginId; + private final String pluginId; - private String label; + private final String label; private boolean visible; - private String description; + private final String description; - private IConfigurationElement configElement; + private final IConfigurationElement configElement; /** * Create a descriptor from a configuration element. @@ -205,12 +205,10 @@ public String getPluginId() { @Override public boolean equals(Object arg0) { - if (!(arg0 instanceof ActionSetDescriptor)) { + if (!(arg0 instanceof ActionSetDescriptor descr)) { return false; } - ActionSetDescriptor descr = (ActionSetDescriptor) arg0; - return id.equals(descr.id) && descr.pluginId.equals(pluginId); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ActionSetRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ActionSetRegistry.java index 2fb2116450b..d5778fc6775 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ActionSetRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ActionSetRegistry.java @@ -49,13 +49,13 @@ public ActionSetPartAssociation(String partId, String actionSetId) { String actionSetId; } - private ArrayList children = new ArrayList<>(); + private final ArrayList children = new ArrayList<>(); - private Map> mapPartToActionSetIds = new HashMap<>(); + private final Map> mapPartToActionSetIds = new HashMap<>(); - private Map> mapPartToActionSets = new HashMap<>(); + private final Map> mapPartToActionSets = new HashMap<>(); - private IContextService contextService; + private final IContextService contextService; /** * Creates the action set registry. @@ -275,8 +275,7 @@ public void removeExtension(IExtension extension, Object[] objects) { private void removeActionSetPartAssociations(Object[] objects) { for (Object object : objects) { - if (object instanceof ActionSetPartAssociation) { - ActionSetPartAssociation association = (ActionSetPartAssociation) object; + if (object instanceof ActionSetPartAssociation association) { String actionSetId = association.actionSetId; ArrayList actionSets = mapPartToActionSetIds.get(association.partId); if (actionSets == null) { @@ -295,8 +294,7 @@ private void removeActionSetPartAssociations(Object[] objects) { private void removeActionSets(Object[] objects) { for (Object object : objects) { - if (object instanceof IActionSetDescriptor) { - IActionSetDescriptor desc = (IActionSetDescriptor) object; + if (object instanceof IActionSetDescriptor desc) { removeActionSet(desc); // now clean up the part associations diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/Category.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/Category.java index 7ea9043f72d..5037ffcaf81 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/Category.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/Category.java @@ -44,7 +44,7 @@ public class Category implements IWorkbenchAdapter, IPluginContribution, IAdapta */ public static final String MISC_ID = "org.eclipse.ui.internal.otherCategory"; //$NON-NLS-1$ - private String id; + private final String id; private String name; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/EditorRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/EditorRegistry.java index 3676ae37657..022f2652142 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/EditorRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/EditorRegistry.java @@ -126,8 +126,8 @@ public IEditorDescriptor[] getRelatedObjects(String fileName) { } - private Map contentTypeToEditorMappingsFromPlugins = new HashMap<>(); - private Map> contentTypeToEditorMappingsFromUser = new HashMap<>(); + private final Map contentTypeToEditorMappingsFromPlugins = new HashMap<>(); + private final Map> contentTypeToEditorMappingsFromUser = new HashMap<>(); /** * Cached images - these include images from registered editors (via plugins) @@ -162,7 +162,7 @@ public IEditorDescriptor[] getRelatedObjects(String fileName) { * Compares the labels from two IEditorDescriptor objects */ private static final Comparator comparer = new Comparator<>() { - private Collator collator = Collator.getInstance(); + private final Collator collator = Collator.getInstance(); @Override public int compare(IEditorDescriptor arg0, IEditorDescriptor arg1) { @@ -172,7 +172,7 @@ public int compare(IEditorDescriptor arg0, IEditorDescriptor arg1) { } }; - private RelatedRegistry relatedRegistry; + private final RelatedRegistry relatedRegistry; private final IContentTypeManager contentTypeManager; @@ -1239,9 +1239,7 @@ private void removeEditorFromMapping(HashMap map, IEd @Override public void removeExtension(IExtension source, Object[] objects) { for (Object object : objects) { - if (object instanceof IEditorDescriptor) { - IEditorDescriptor desc = (IEditorDescriptor) object; - + if (object instanceof IEditorDescriptor desc) { sortedEditorsFromPlugins.remove(desc); mapIDtoInternalEditor.values().remove(desc); removeEditorFromMapping(typeEditorMappings.defaultMap, desc); @@ -1648,9 +1646,9 @@ public void addUserAssociation(IContentType contentType, IEditorDescriptor selec class MockMapping implements IFileEditorMapping { - private IContentType contentType; - private String extension; - private String filename; + private final IContentType contentType; + private final String extension; + private final String filename; MockMapping(IContentType type, String name, String ext) { this.contentType = type; @@ -1711,11 +1709,10 @@ public boolean equals(Object obj) { return true; } - if (!(obj instanceof MockMapping)) { + if (!(obj instanceof MockMapping mapping)) { return false; } - MockMapping mapping = (MockMapping) obj; return this.filename.equals(mapping.filename) && this.extension.equals(mapping.extension) && Arrays.equals(this.getEditors(), mapping.getEditors()) && Arrays.equals(this.getDeletedEditors(), mapping.getDeletedEditors()); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/FileEditorMapping.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/FileEditorMapping.java index 583e7ef8903..95b3c5271f2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/FileEditorMapping.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/FileEditorMapping.java @@ -110,10 +110,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (!(obj instanceof FileEditorMapping)) { + if (!(obj instanceof FileEditorMapping mapping)) { return false; } - FileEditorMapping mapping = (FileEditorMapping) obj; return Objects.equals(name, mapping.name) && Objects.equals(extension, mapping.extension) && Objects.equals(editors, mapping.editors) && Objects.equals(declaredDefaultEditors, mapping.declaredDefaultEditors) diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ImportExportPespectiveHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ImportExportPespectiveHandler.java index c2dc7fe9cae..8d24fa952ab 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ImportExportPespectiveHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ImportExportPespectiveHandler.java @@ -90,8 +90,8 @@ public class ImportExportPespectiveHandler { private IPreferenceChangeListener preferenceListener; private boolean ignoreEvents; - private List exportedPersps = new ArrayList<>(); - private List importedPersps = new ArrayList<>(); + private final List exportedPersps = new ArrayList<>(); + private final List importedPersps = new ArrayList<>(); private Map minMaxPersistedState; @PostConstruct @@ -139,8 +139,9 @@ private void addShowInTags(MPerspective perspective) { private String getOriginalId(String id) { int index = id.lastIndexOf('.'); - if (index == -1) + if (index == -1) { return id; + } return id.substring(0, index); } @@ -255,8 +256,7 @@ private MPerspective perspFromString(String perspAsString) throws IOException { private void copyPerspsToPreferences() { for (MUIElement snippet : application.getSnippets()) { - if (snippet instanceof MPerspective) { - MPerspective persp = (MPerspective) snippet; + if (snippet instanceof MPerspective persp) { exportedPersps.add(persp); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/KeywordRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/KeywordRegistry.java index 2c70437a60f..1b529671770 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/KeywordRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/KeywordRegistry.java @@ -55,7 +55,7 @@ public static KeywordRegistry getInstance() { /** * Map of id->labels. */ - private Map internalKeywordMap = new HashMap(); + private final Map internalKeywordMap = new HashMap(); /** * Private constructor. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PerspectiveDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PerspectiveDescriptor.java index 7f62bdf97ca..c0b35e41626 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PerspectiveDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PerspectiveDescriptor.java @@ -42,7 +42,7 @@ */ public class PerspectiveDescriptor implements IPerspectiveDescriptor, IPluginContribution { - private String id; + private final String id; private String label; private ImageDescriptor image; private IConfigurationElement configElement; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PerspectiveRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PerspectiveRegistry.java index dc432c2acf3..cf4ee48d141 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PerspectiveRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PerspectiveRegistry.java @@ -75,7 +75,7 @@ public class PerspectiveRegistry implements IPerspectiveRegistry, IExtensionChan @Inject Logger logger; - private Map descriptors = new HashMap<>(); + private final Map descriptors = new HashMap<>(); @PostConstruct void postConstruct(MApplication application) { @@ -87,8 +87,7 @@ void postConstruct(MApplication application) { List snippets = application.getSnippets(); for (MUIElement snippet : snippets) { - if (snippet instanceof MPerspective) { - MPerspective perspective = (MPerspective) snippet; + if (snippet instanceof MPerspective perspective) { String id = perspective.getElementId(); // See if the clone is customizing an a predefined perspective without changing @@ -155,8 +154,9 @@ public IPerspectiveDescriptor clonePerspective(String id, String label, IPerspec @Override public void deletePerspective(IPerspectiveDescriptor toDelete) { PerspectiveDescriptor perspective = (PerspectiveDescriptor) toDelete; - if (perspective.isPredefined()) + if (perspective.isPredefined()) { return; + } descriptors.remove(perspective.getId()); removeSnippet(application, perspective.getId()); @@ -164,8 +164,9 @@ public void deletePerspective(IPerspectiveDescriptor toDelete) { private MUIElement removeSnippet(MSnippetContainer snippetContainer, String id) { MUIElement snippet = modelService.findSnippet(snippetContainer, id); - if (snippet != null) + if (snippet != null) { snippetContainer.getSnippets().remove(snippet); + } return snippet; } @@ -254,8 +255,9 @@ public boolean validateLabel(String label) { @Override public void revertPerspective(IPerspectiveDescriptor perspToRevert) { PerspectiveDescriptor perspective = (PerspectiveDescriptor) perspToRevert; - if (!perspective.isPredefined()) + if (!perspective.isPredefined()) { return; + } perspective.setHasCustomDefinition(false); removeSnippet(application, perspective.getId()); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PreferencePageRegistryReader.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PreferencePageRegistryReader.java index e06b3b567ce..81bb12487b4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PreferencePageRegistryReader.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PreferencePageRegistryReader.java @@ -36,7 +36,7 @@ public class PreferencePageRegistryReader extends CategorizedPageRegistryReader private List nodes; - private IWorkbench workbench; + private final IWorkbench workbench; static class PreferencesCategoryNode extends CategoryNode { @@ -154,8 +154,9 @@ protected boolean readElement(IConfigurationElement element) { WorkbenchPreferenceNode node = createNode(element); if (node != null) { if (workbench instanceof Workbench) { - if (node.getId().equals(((Workbench) workbench).getMainPreferencePageId())) + if (node.getId().equals(((Workbench) workbench).getMainPreferencePageId())) { node.setPriority(-1); + } } nodes.add(node); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PreferenceTransferRegistryReader.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PreferenceTransferRegistryReader.java index 8a1b936b453..dfc90c02571 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PreferenceTransferRegistryReader.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PreferenceTransferRegistryReader.java @@ -36,7 +36,7 @@ public class PreferenceTransferRegistryReader extends RegistryReader { private List preferenceTransfers; - private String pluginPoint; + private final String pluginPoint; /** * Create an instance of this class. @@ -94,8 +94,9 @@ protected boolean readElement(IConfigurationElement element) { if (element.getName().equals(IWorkbenchRegistryConstants.TAG_TRANSFER)) { PreferenceTransferElement transfer = createPreferenceTransferElement(element); - if (transfer != null) + if (transfer != null) { preferenceTransfers.add(transfer); + } return true; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PropertyPagesRegistryReader.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PropertyPagesRegistryReader.java index 61614848b47..3fc57dd9bb9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PropertyPagesRegistryReader.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/PropertyPagesRegistryReader.java @@ -84,9 +84,9 @@ public class PropertyPagesRegistryReader extends CategorizedPageRegistryReader { private static final String CHILD_ENABLED_WHEN = "enabledWhen"; //$NON-NLS-1$ ; - private Collection pages = new ArrayList<>(); + private final Collection pages = new ArrayList<>(); - private PropertyPageContributorManager manager; + private final PropertyPageContributorManager manager; static class PropertyCategoryNode extends CategoryNode { @@ -223,8 +223,9 @@ Object findNode(String id) { Iterator iterator = pages.iterator(); while (iterator.hasNext()) { RegistryPageContributor next = iterator.next(); - if (next.getPageId().equals(id)) + if (next.getPageId().equals(id)) { return next; + } } return null; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/StickyViewDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/StickyViewDescriptor.java index 1fe841e6efc..dc22f4a4dc3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/StickyViewDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/StickyViewDescriptor.java @@ -27,9 +27,9 @@ */ public class StickyViewDescriptor implements IStickyViewDescriptor, IPluginContribution { - private IConfigurationElement configurationElement; + private final IConfigurationElement configurationElement; - private String id; + private final String id; /** * Folder constant for right sticky views. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewCategory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewCategory.java index aaeed2d4749..03ae1b309cb 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewCategory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewCategory.java @@ -25,10 +25,10 @@ public class ViewCategory implements IViewCategory { - private String id; - private String label; - private IPath path; - private List descriptors = new ArrayList<>(); + private final String id; + private final String label; + private final IPath path; + private final List descriptors = new ArrayList<>(); public ViewCategory(String id, String label) { this.id = id; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewDescriptor.java index dfd18a04585..e1f4a3d6aa7 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewDescriptor.java @@ -35,9 +35,9 @@ public class ViewDescriptor implements IViewDescriptor, IPluginContribution { - private MApplication application; - private MPartDescriptor descriptor; - private IConfigurationElement element; + private final MApplication application; + private final MPartDescriptor descriptor; + private final IConfigurationElement element; private String[] categoryPath; private ImageDescriptor imageDescriptor; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewRegistry.java index 17eda7d6cd0..cd955cd7ef8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/ViewRegistry.java @@ -78,13 +78,13 @@ public class ViewRegistry implements IViewRegistry { @Inject Logger logger; - private Map descriptors = new HashMap<>(); + private final Map descriptors = new HashMap<>(); - private List stickyDescriptors = new ArrayList<>(); + private final List stickyDescriptors = new ArrayList<>(); - private HashMap categories = new HashMap<>(); + private final HashMap categories = new HashMap<>(); - private Category miscCategory = new Category(); + private final Category miscCategory = new Category(); @PostConstruct void postConstruct() { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WizardsRegistryReader.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WizardsRegistryReader.java index 4ced47df04e..ed63e55b5e9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WizardsRegistryReader.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WizardsRegistryReader.java @@ -39,7 +39,7 @@ */ public class WizardsRegistryReader extends RegistryReader { - private String pluginPoint; + private final String pluginPoint; private WizardCollectionElement wizardElements = null; @@ -70,7 +70,7 @@ public class WizardsRegistryReader extends RegistryReader { private WorkbenchWizardElement[] primaryWizards = new WorkbenchWizardElement[0]; private static class CategoryNode { - private Category category; + private final Category category; private String path; @@ -96,7 +96,7 @@ Category getCategory() { } private static final Comparator comparer = new Comparator<>() { - private Collator collator = Collator.getInstance(); + private final Collator collator = Collator.getInstance(); @Override public int compare(CategoryNode arg0, CategoryNode arg1) { @@ -108,7 +108,7 @@ public int compare(CategoryNode arg0, CategoryNode arg1) { private boolean readAll = true; - private String plugin; + private final String plugin; /** * Create an instance of this class. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WorkingSetDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WorkingSetDescriptor.java index 14bb6b9ada5..cbf1852767a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WorkingSetDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WorkingSetDescriptor.java @@ -37,17 +37,17 @@ * @since 2.0 */ public class WorkingSetDescriptor implements IPluginContribution { - private String id; + private final String id; - private String name; + private final String name; - private String icon; + private final String icon; - private String pageClassName; + private final String pageClassName; - private String updaterClassName; + private final String updaterClassName; - private IConfigurationElement configElement; + private final IConfigurationElement configElement; private String[] classTypes; @@ -93,10 +93,12 @@ public WorkingSetDescriptor(IConfigurationElement configElement) throws CoreExce List byAdapterList = new ArrayList<>(containsChildren.length); for (IConfigurationElement child : containsChildren) { String className = child.getAttribute(IWorkbenchRegistryConstants.ATT_CLASS); - if (className != null) + if (className != null) { byClassList.add(className); - if ("true".equals(child.getAttribute(IWorkbenchRegistryConstants.ATT_ADAPTABLE))) //$NON-NLS-1$ + } + if ("true".equals(child.getAttribute(IWorkbenchRegistryConstants.ATT_ADAPTABLE))) { //$NON-NLS-1$ byAdapterList.add(className); + } } if (!byClassList.isEmpty()) { classTypes = byClassList.toArray(new String[byClassList.size()]); @@ -221,8 +223,9 @@ public String getUpdaterClassName() { * declared */ public IWorkingSetElementAdapter createWorkingSetElementAdapter() { - if (!WorkbenchPlugin.hasExecutableExtension(configElement, ATT_ELEMENT_ADAPTER_CLASS)) + if (!WorkbenchPlugin.hasExecutableExtension(configElement, ATT_ELEMENT_ADAPTER_CLASS)) { return null; + } IWorkingSetElementAdapter result = null; try { result = (IWorkingSetElementAdapter) WorkbenchPlugin.createExtension(configElement, @@ -302,8 +305,9 @@ public IConfigurationElement getConfigurationElement() { */ public String getDescription() { String description = configElement.getAttribute(IWorkbenchRegistryConstants.ATT_DESCRIPTION); - if (description == null) + if (description == null) { description = ""; //$NON-NLS-1$ + } return description; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WorkingSetRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WorkingSetRegistry.java index 80dcf071a0e..09558f4d9ed 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WorkingSetRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WorkingSetRegistry.java @@ -38,7 +38,7 @@ public class WorkingSetRegistry implements IExtensionChangeHandler { // @issue this is an IDE specific working set page! private static final String DEFAULT_PAGE_ID = "org.eclipse.ui.resourceWorkingSetPage"; //$NON-NLS-1$ - private HashMap workingSetDescriptors = new HashMap<>(); + private final HashMap workingSetDescriptors = new HashMap<>(); public WorkingSetRegistry() { IExtensionTracker tracker = PlatformUI.getWorkbench().getExtensionTracker(); @@ -152,8 +152,9 @@ public List getUpdaterDescriptorsForNamespace(String names } public WorkingSetDescriptor[] getElementAdapterDescriptorsForNamespace(String namespace) { - if (namespace == null) // fix for Bug 84225 + if (namespace == null) { // fix for Bug 84225 return new WorkingSetDescriptor[0]; + } Collection descriptors = workingSetDescriptors.values(); List result = new ArrayList<>(); for (Iterator iter = descriptors.iterator(); iter.hasNext();) { @@ -199,8 +200,7 @@ public void addExtension(IExtensionTracker tracker, IExtension extension) { @Override public void removeExtension(IExtension extension, Object[] objects) { for (Object object : objects) { - if (object instanceof WorkingSetDescriptor) { - WorkingSetDescriptor desc = (WorkingSetDescriptor) object; + if (object instanceof WorkingSetDescriptor desc) { workingSetDescriptors.remove(desc.getId()); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/EvaluationService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/EvaluationService.java index daf31e67ea2..48248f13bcc 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/EvaluationService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/EvaluationService.java @@ -59,13 +59,13 @@ public final class EvaluationService implements IEvaluationService { private IEclipseContext ratContext; private int notifying = 0; - private ListenerList serviceListeners = new ListenerList<>(ListenerList.IDENTITY); + private final ListenerList serviceListeners = new ListenerList<>(ListenerList.IDENTITY); ArrayList sourceProviders = new ArrayList<>(); LinkedList refs = new LinkedList<>(); private ISourceProviderListener contextUpdater; - private HashSet ratVariables = new HashSet<>(); - private RunAndTrack ratUpdater = new RunAndTrack() { + private final HashSet ratVariables = new HashSet<>(); + private final RunAndTrack ratUpdater = new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { context.get(RE_EVAL); @@ -85,7 +85,7 @@ public boolean changed(IEclipseContext context) { } }; - private HashSet variableFilter = new HashSet<>(); + private final HashSet variableFilter = new HashSet<>(); private IEventBroker eventBroker; public EvaluationService(IEclipseContext c) { @@ -100,8 +100,7 @@ public Object compute(IEclipseContext context, String contextKey) { return defaultVariable; } defaultVariable = context.getActive(IServiceConstants.ACTIVE_SELECTION); - if (defaultVariable instanceof IStructuredSelection) { - final IStructuredSelection selection = (IStructuredSelection) defaultVariable; + if (defaultVariable instanceof final IStructuredSelection selection) { return selection.toList(); } else if ((defaultVariable instanceof ISelection) && (!((ISelection) defaultVariable).isEmpty())) { return Collections.singleton(defaultVariable); @@ -125,11 +124,7 @@ public void sourceChanged(int sourcePriority, Map sourceValuesByName) { } } }; - variableFilter.addAll(Arrays.asList(new String[] { ISources.ACTIVE_WORKBENCH_WINDOW_NAME, - ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME, ISources.ACTIVE_EDITOR_ID_NAME, - ISources.ACTIVE_EDITOR_INPUT_NAME, ISources.SHOW_IN_INPUT, ISources.SHOW_IN_SELECTION, - ISources.ACTIVE_PART_NAME, ISources.ACTIVE_PART_ID_NAME, ISources.ACTIVE_SITE_NAME, - ISources.ACTIVE_CONTEXT_NAME, ISources.ACTIVE_CURRENT_SELECTION_NAME })); + variableFilter.addAll(Arrays.asList(ISources.ACTIVE_WORKBENCH_WINDOW_NAME, ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME, ISources.ACTIVE_EDITOR_ID_NAME, ISources.ACTIVE_EDITOR_INPUT_NAME, ISources.SHOW_IN_INPUT, ISources.SHOW_IN_SELECTION, ISources.ACTIVE_PART_NAME, ISources.ACTIVE_PART_ID_NAME, ISources.ACTIVE_SITE_NAME, ISources.ACTIVE_CONTEXT_NAME, ISources.ACTIVE_CURRENT_SELECTION_NAME)); context.runAndTrack(ratUpdater); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/ExpressionAuthority.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/ExpressionAuthority.java index fc751397e46..3e5b3fb16f8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/ExpressionAuthority.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/ExpressionAuthority.java @@ -169,8 +169,7 @@ public final IEvaluationContext getCurrentState() { if (currentState == null) { final Object defaultVariable = context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); final IEvaluationContext contextWithDefaultVariable; - if (defaultVariable instanceof IStructuredSelection) { - final IStructuredSelection selection = (IStructuredSelection) defaultVariable; + if (defaultVariable instanceof final IStructuredSelection selection) { contextWithDefaultVariable = new EvaluationContext(context, selection.toList()); } else if ((defaultVariable instanceof ISelection) && (!((ISelection) defaultVariable).isEmpty())) { contextWithDefaultVariable = new EvaluationContext(context, Collections.singleton(defaultVariable)); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/LogThrottle.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/LogThrottle.java index a74b88cf367..0f665c51950 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/LogThrottle.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/LogThrottle.java @@ -26,9 +26,9 @@ */ public class LogThrottle { - private LinkedBlockingQueue fThrottleQueue; - private HashMap fActiveMessages = new HashMap<>(); - private String fThrottleMessage; + private final LinkedBlockingQueue fThrottleQueue; + private final HashMap fActiveMessages = new HashMap<>(); + private final String fThrottleMessage; private int fThrottleValue; /** diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/MenuSourceProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/MenuSourceProvider.java index d031c99846a..c2e88b9d450 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/MenuSourceProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/MenuSourceProvider.java @@ -49,7 +49,7 @@ public final class MenuSourceProvider extends AbstractSourceProvider { * The menu ids that are currently showing, as known by this source provider. * This value may be null. */ - private Set menuIds = new HashSet(); + private final Set menuIds = new HashSet(); /** * Adds all of the given menu identifiers as being shown. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/ServiceLocator.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/ServiceLocator.java index fa5e04ff28e..9845f0e80ba 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/ServiceLocator.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/ServiceLocator.java @@ -38,8 +38,8 @@ public final class ServiceLocator implements IDisposable, INestable, IServiceLoc boolean activated = false; private static class ParentLocator implements IServiceLocator { - private IServiceLocator locator; - private Class key; + private final IServiceLocator locator; + private final Class key; public ParentLocator(IServiceLocator parent, Class serviceInterface) { locator = parent; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/SlaveEvaluationService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/SlaveEvaluationService.java index d39b285a99e..328eff38c72 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/SlaveEvaluationService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/SlaveEvaluationService.java @@ -28,13 +28,13 @@ */ public class SlaveEvaluationService implements IEvaluationService { - private IEvaluationService parentService; + private final IEvaluationService parentService; - private Collection sourceProviders = new ArrayList(); + private final Collection sourceProviders = new ArrayList(); - private Collection serviceListeners = new ArrayList(); + private final Collection serviceListeners = new ArrayList(); - private Collection evaluationReferences = new ArrayList(); + private final Collection evaluationReferences = new ArrayList(); public SlaveEvaluationService(IEvaluationService parent) { parentService = parent; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/SourceProviderService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/SourceProviderService.java index 76e76a6a352..63686cba726 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/SourceProviderService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/SourceProviderService.java @@ -51,7 +51,7 @@ public final class SourceProviderService implements ISourceProviderService, IDis */ private final Set sourceProviders = new HashSet<>(); - private IServiceLocator locator; + private final IServiceLocator locator; public SourceProviderService(final IServiceLocator locator) { this.locator = locator; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchLocationService.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchLocationService.java index 65dafdb872f..b9273c6a1a5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchLocationService.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchLocationService.java @@ -32,7 +32,7 @@ public class WorkbenchLocationService implements IWorkbenchLocationService, IDis private String serviceScope; private IWorkbench workbench; private IWorkbenchWindow window; - private int level; + private final int level; public WorkbenchLocationService(String serviceScope, IWorkbench workbench, IWorkbenchWindow window, IWorkbenchPartSite partSite, IEditorSite mpepSite, IPageSite pageSite, int level) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchServiceRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchServiceRegistry.java index 83c813443af..85fc76ee12b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchServiceRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchServiceRegistry.java @@ -225,8 +225,7 @@ public void addExtension(IExtensionTracker tracker, IExtension extension) { @Override public void removeExtension(IExtension extension, Object[] objects) { for (Object object : objects) { - if (object instanceof ServiceFactoryHandle) { - ServiceFactoryHandle handle = (ServiceFactoryHandle) object; + if (object instanceof ServiceFactoryHandle handle) { ServiceLocator[] locators = handle.serviceLocators.toArray(ServiceLocator[]::new); Arrays.sort(locators, (loc1, loc2) -> { int l1 = loc1.getService(IWorkbenchLocationService.class).getServiceLevel(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchSourceProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchSourceProvider.java index 46df1fac10d..1fca99c9091 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchSourceProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/services/WorkbenchSourceProvider.java @@ -86,8 +86,9 @@ public void initialize(IServiceLocator locator) { @Override public void dispose() { - if (lastWindow != null) + if (lastWindow != null) { lastWindow.getSelectionService().removeSelectionListener(this); + } workbench.removeWindowListener(windowListener); display.removeFilter(SWT.Activate, listener); hookListener(lastActiveWorkbenchWindow, null); @@ -122,8 +123,7 @@ private int updateSelection(final Map currentState) { int sources = 0; currentState.put(ISources.ACTIVE_CURRENT_SELECTION_NAME, IEvaluationContext.UNDEFINED_VARIABLE); Object object = currentState.get(ISources.ACTIVE_PART_NAME); - if (object instanceof IWorkbenchPart) { - IWorkbenchPart part = (IWorkbenchPart) object; + if (object instanceof IWorkbenchPart part) { if (part.getSite() != null && part.getSite().getSelectionProvider() != null) { sources = ISources.ACTIVE_CURRENT_SELECTION; ISelection currentSelection = part.getSite().getSelectionProvider().getSelection(); @@ -136,8 +136,9 @@ private int updateSelection(final Map currentState) { @Override public final void selectionChanged(final IWorkbenchPart part, final ISelection newSelection) { - if (Objects.equals(selection, newSelection)) + if (Objects.equals(selection, newSelection)) { return; // we have already handled the change + } selection = newSelection; @@ -550,8 +551,9 @@ private void updateActivePart(Map currentState, boolean updateShowInSelection) { private final IPropertyChangeListener propertyListener = event -> { if (WorkbenchWindow.PROP_COOLBAR_VISIBLE.equals(event.getProperty())) { Object newValue1 = event.getNewValue(); - if (newValue1 == null || !(newValue1 instanceof Boolean)) + if (newValue1 == null || !(newValue1 instanceof Boolean)) { return; + } if (!lastCoolbarVisibility.equals(newValue1)) { fireSourceChanged(ISources.ACTIVE_WORKBENCH_WINDOW_SUBORDINATE, ISources.ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME, newValue1); @@ -559,8 +561,9 @@ private void updateActivePart(Map currentState, boolean updateShowInSelection) { } } else if (WorkbenchWindow.PROP_PERSPECTIVEBAR_VISIBLE.equals(event.getProperty())) { Object newValue2 = event.getNewValue(); - if (newValue2 == null || !(newValue2 instanceof Boolean)) + if (newValue2 == null || !(newValue2 instanceof Boolean)) { return; + } if (!lastPerspectiveBarVisibility.equals(newValue2)) { fireSourceChanged(ISources.ACTIVE_WORKBENCH_WINDOW_SUBORDINATE, ISources.ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME, newValue2); @@ -568,8 +571,9 @@ private void updateActivePart(Map currentState, boolean updateShowInSelection) { } } else if (WorkbenchWindow.PROP_STATUS_LINE_VISIBLE.equals(event.getProperty())) { Object newValue3 = event.getNewValue(); - if (newValue3 == null || !(newValue3 instanceof Boolean)) + if (newValue3 == null || !(newValue3 instanceof Boolean)) { return; + } if (!lastStatusLineVisibility.equals(newValue3)) { fireSourceChanged(ISources.ACTIVE_WORKBENCH_WINDOW_SUBORDINATE, ISources.ACTIVE_WORKBENCH_WINDOW_NAME + ".isStatusLineVisible", newValue3); //$NON-NLS-1$ @@ -599,7 +603,7 @@ public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor persp } }; - private IPropertyListener editorListener = (source, propId) -> { + private final IPropertyListener editorListener = (source, propId) -> { if (propId == IEditorPart.PROP_INPUT) { handleInputChanged((IEditorPart) source); } @@ -809,8 +813,9 @@ private void updateActiveShell(Map currentState) { } final int shellType = contextService.getShellType(newActiveShell); - if (shellType == IContextService.TYPE_DIALOG) + if (shellType == IContextService.TYPE_DIALOG) { return; + } final WorkbenchWindow newActiveWorkbenchWindow = (WorkbenchWindow) workbench.getActiveWorkbenchWindow(); final Shell newActiveWorkbenchWindowShell; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/splash/SplashHandlerFactory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/splash/SplashHandlerFactory.java index 39ac7709ad6..70b8023bd7f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/splash/SplashHandlerFactory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/splash/SplashHandlerFactory.java @@ -43,14 +43,16 @@ public final class SplashHandlerFactory { * @return the splash or null */ public static AbstractSplashHandler findSplashHandlerFor(IProduct product) { - if (product == null) + if (product == null) { return null; + } IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_SPLASH_HANDLERS); - if (point == null) + if (point == null) { return null; + } IExtension[] extensions = point.getExtensions(); Map idToSplash = new HashMap(); // String->ConfigurationElement @@ -59,8 +61,9 @@ public static AbstractSplashHandler findSplashHandlerFor(IProduct product) { IConfigurationElement[] children = extension.getConfigurationElements(); for (IConfigurationElement element : children) { AbstractSplashHandler handler = processElement(element, idToSplash, targetId, product); - if (handler != null) + if (handler != null) { return handler; + } } } @@ -82,8 +85,9 @@ private static AbstractSplashHandler processElement(IConfigurationElement config String type = configurationElement.getName(); if (IWorkbenchRegistryConstants.TAG_SPLASH_HANDLER.equals(type)) { String id = configurationElement.getAttribute(IWorkbenchRegistryConstants.ATT_ID); - if (id == null) + if (id == null) { return null; + } // we know the target and this element is it if (targetId[0] != null && id.equals(targetId[0])) { @@ -99,8 +103,9 @@ private static AbstractSplashHandler processElement(IConfigurationElement config targetId[0] = configurationElement.getAttribute(IWorkbenchRegistryConstants.ATT_SPLASH_ID); // check all currently located splashes IConfigurationElement splashElement = (IConfigurationElement) idToSplash.get(targetId[0]); - if (splashElement != null) + if (splashElement != null) { return create(splashElement); + } } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/DefaultDetailsArea.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/DefaultDetailsArea.java index 50fb0d929ca..99440f77492 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/DefaultDetailsArea.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/DefaultDetailsArea.java @@ -66,7 +66,7 @@ public class DefaultDetailsArea extends AbstractStatusAreaProvider { /* * All statuses should be displayed. */ - private int mask; + private final int mask; /* * New child entry in the list will be shifted by a number of pixels @@ -78,9 +78,9 @@ public class DefaultDetailsArea extends AbstractStatusAreaProvider { */ private StyledText text; - private boolean handleOkStatuses; + private final boolean handleOkStatuses; - private Map dialogState; + private final Map dialogState; private MenuItem copyAction; @@ -232,7 +232,7 @@ private void adjustHeight(StyledText text) { */ private void createDNDSource() { DragSource ds = new DragSource(text, DND.DROP_COPY); - ds.setTransfer(new Transfer[] { TextTransfer.getInstance() }); + ds.setTransfer(TextTransfer.getInstance()); ds.addDragListener(new DragSourceListener() { @Override public void dragFinished(DragSourceEvent event) { @@ -278,8 +278,7 @@ private void populateList(StyledText text, IStatus status, int nesting, int[] li // Look for a nested core exception Throwable t = status.getException(); - if (t instanceof CoreException) { - CoreException ce = (CoreException) t; + if (t instanceof CoreException ce) { populateList(text, ce.getStatus(), nesting + 1, lineNumber); } else if (t != null) { // Include low-level exception message diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/DetailsAreaManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/DetailsAreaManager.java index 6a087f4ba40..636b174636f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/DetailsAreaManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/DetailsAreaManager.java @@ -27,7 +27,7 @@ */ public class DetailsAreaManager { - private Map dialogState; + private final Map dialogState; private Control control = null; public DetailsAreaManager(Map dialogState) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/InternalDialog.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/InternalDialog.java index fbd51b76f40..723308eba77 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/InternalDialog.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/InternalDialog.java @@ -140,9 +140,9 @@ public class InternalDialog extends TrayDialog { */ private SupportTray supportTray; - private DetailsAreaManager detailsManager; + private final DetailsAreaManager detailsManager; - private Map dialogState; + private final Map dialogState; public InternalDialog(final Map dialogState, boolean modal) { super(ProgressManagerUtil.getDefaultParent()); @@ -494,8 +494,9 @@ private void silentTrayClose() { /** opens the tray without changing any flag */ private void silentTrayOpen() { - if (getTray() == null) + if (getTray() == null) { super.openTray(supportTray); + } } /** @@ -571,8 +572,9 @@ protected void createButtonsForButtonBar(Composite parent) { } Button button = createButton(parent, GOTO_ACTION_ID, text == null ? "" : text, //$NON-NLS-1$ false); - if (text == null) + if (text == null) { hideButton(button, true); + } createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); @@ -673,8 +675,9 @@ private void updateEnablements() { ((GridData) gotoButton.getLayoutData()).widthHint = gotoButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).x; gotoButton.getParent().layout(); - } else + } else { hideButton(gotoButton, true); + } } // and tray enablement button if (providesSupport() && !getBooleanValue(IStatusDialogConstants.HIDE_SUPPORT_BUTTON)) { @@ -740,8 +743,9 @@ public void openTray(DialogTray tray) throws IllegalStateException, UnsupportedO */ private void refreshSingleStatusArea() { String description = getLabelProviderWrapper().getColumnText(getCurrentStatusAdapter(), 0); - if (description.equals(singleStatusLabel.getText())) + if (description.equals(singleStatusLabel.getText())) { singleStatusLabel.setText(" "); //$NON-NLS-1$ + } singleStatusLabel.setText(description); singleStatusDisplayArea.layout(); getShell().setText(getString(IStatusDialogConstants.TITLE)); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/LabelProviderWrapper.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/LabelProviderWrapper.java index b946353efd6..579e4c77db4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/LabelProviderWrapper.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/LabelProviderWrapper.java @@ -149,7 +149,7 @@ public void removeListener(ILabelProviderListener listener) { */ private ILabelDecorator messageDecorator; - private Map dialogState; + private final Map dialogState; public LabelProviderWrapper(Map dialogState) { this.dialogState = dialogState; @@ -301,8 +301,7 @@ public String getMainMessage(StatusAdapter statusAdapter) { public String getPrimaryMessage(StatusAdapter statusAdapter) { // if there was nonempty title set, display the title Object property = statusAdapter.getProperty(IStatusAdapterConstants.TITLE_PROPERTY); - if (property instanceof String) { - String header = (String) property; + if (property instanceof String header) { if (header.trim().length() > 0) { return decorate(header, statusAdapter); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StackTraceSupportArea.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StackTraceSupportArea.java index cc381f65cfd..29a9c358a4b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StackTraceSupportArea.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StackTraceSupportArea.java @@ -89,7 +89,7 @@ public void widgetSelected(SelectionEvent e) { */ private void createDNDSource() { DragSource ds = new DragSource(list, DND.DROP_COPY); - ds.setTransfer(new Transfer[] { TextTransfer.getInstance() }); + ds.setTransfer(TextTransfer.getInstance()); ds.addDragListener(new DragSourceListener() { @Override public void dragFinished(DragSourceEvent event) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerDescriptor.java index b50510f4151..72bc978a09c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerDescriptor.java @@ -33,11 +33,11 @@ public class StatusHandlerDescriptor implements IPluginContribution { private static final String PREFIX = "prefix"; //$NON-NLS-1$ - private IConfigurationElement configElement; + private final IConfigurationElement configElement; - private String id; + private final String id; - private String pluginId; + private final String pluginId; private String prefix; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerDescriptorsMap.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerDescriptorsMap.java index 9b05fd927e9..44ff6fdef37 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerDescriptorsMap.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerDescriptorsMap.java @@ -28,7 +28,7 @@ class StatusHandlerDescriptorsMap { private static final String ASTERISK = "*"; //$NON-NLS-1$ - private HashMap map; + private final HashMap map; /** * Creates a new instance of the class diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerProductBindingDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerProductBindingDescriptor.java index 3597c4914db..fa82df4821a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerProductBindingDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerProductBindingDescriptor.java @@ -30,13 +30,13 @@ class StatusHandlerProductBindingDescriptor implements IPluginContribution { */ private static String ATT_HANDLER_ID = "handlerId"; //$NON-NLS-1$ - private String id; + private final String id; - private String pluginId; + private final String pluginId; - private String productId; + private final String productId; - private String handlerId; + private final String handlerId; public StatusHandlerProductBindingDescriptor(IConfigurationElement configElement) { super(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerRegistry.java index ce4f7d051ba..3ebf4cae993 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/StatusHandlerRegistry.java @@ -42,11 +42,11 @@ public class StatusHandlerRegistry implements IExtensionChangeHandler { private static final String STATUSHANDLER_ARG = "-statushandler"; //$NON-NLS-1$ - private ArrayList statusHandlerDescriptors = new ArrayList<>(); + private final ArrayList statusHandlerDescriptors = new ArrayList<>(); - private ArrayList productBindingDescriptors = new ArrayList<>(); + private final ArrayList productBindingDescriptors = new ArrayList<>(); - private StatusHandlerDescriptorsMap statusHandlerDescriptorsMap; + private final StatusHandlerDescriptorsMap statusHandlerDescriptorsMap; private StatusHandlerDescriptor defaultHandlerDescriptor; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/SupportTray.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/SupportTray.java index 09813d52643..0130670c54f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/SupportTray.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/SupportTray.java @@ -52,7 +52,7 @@ */ public class SupportTray extends DialogTray implements ISelectionChangedListener { - private Map dialogState; + private final Map dialogState; public SupportTray(Map dialogState, Listener listener) { this.closeListener = listener; @@ -62,8 +62,8 @@ public SupportTray(Map dialogState, Listener listener) { } private IContributionItem closeAction; - private Listener closeListener; - private boolean hideSupportButtons; + private final Listener closeListener; + private final boolean hideSupportButtons; private Image normal; private Image hover; private static final int[] closeButtonPolygon = new int[] { 3, 3, 5, 3, 7, 5, 8, 5, 10, 3, 12, 3, 12, 5, 10, 7, 10, @@ -126,8 +126,9 @@ protected Control createContents(Composite parent) { gd.grabExcessVerticalSpace = true; supportArea.setLayoutData(gd); - if (lastSelectedStatus != null) + if (lastSelectedStatus != null) { createSupportArea(supportArea, lastSelectedStatus); + } Point shellSize = supportArea.getShell().getSize(); Point desiredSize = supportArea.getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); @@ -196,10 +197,12 @@ public void fill(ToolBar parent, int index) { } private void destroyImages() { - if (normal != null) + if (normal != null) { normal.dispose(); - if (hover != null) + } + if (hover != null) { hover.dispose(); + } } /** @@ -214,11 +217,13 @@ private void createSupportArea(Composite parent, StatusAdapter statusAdapter) { ErrorSupportProvider provider = getSupportProvider(); // default support area was disabled - if (provider == null) + if (provider == null) { return; + } - if (supportAreaContent != null) + if (supportAreaContent != null) { supportAreaContent.dispose(); + } supportAreaContent = new Composite(parent, SWT.FILL); @@ -257,8 +262,7 @@ private StatusAdapter getStatusAdapterFromEvent(SelectionChangedEvent event) { ISelection selection = event.getSelection(); - if (selection instanceof StructuredSelection) { - StructuredSelection structuredSelection = (StructuredSelection) selection; + if (selection instanceof StructuredSelection structuredSelection) { Object element = structuredSelection.getFirstElement(); if (element instanceof StatusAdapter) { return (StatusAdapter) element; @@ -276,8 +280,7 @@ private StatusAdapter getStatusAdapterFromEvent(SelectionChangedEvent event) { */ public ErrorSupportProvider providesSupport(StatusAdapter adapter) { ErrorSupportProvider provider = getSupportProvider(); - if (provider instanceof AbstractStatusAreaProvider) { - AbstractStatusAreaProvider areaProvider = (AbstractStatusAreaProvider) provider; + if (provider instanceof AbstractStatusAreaProvider areaProvider) { if (areaProvider.validFor(adapter)) { return areaProvider; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/WorkbenchStatusDialogManagerImpl.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/WorkbenchStatusDialogManagerImpl.java index 00d41e92568..a0109890d6d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/WorkbenchStatusDialogManagerImpl.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/WorkbenchStatusDialogManagerImpl.java @@ -73,7 +73,7 @@ public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) { } } - private DisposeListener disposeListener = new StatusDialogDisposeListener(); + private final DisposeListener disposeListener = new StatusDialogDisposeListener(); /** * This field stores the real dialog that appears to the user. @@ -338,8 +338,7 @@ public void setStatusListLabelProvider(ITableLabelProvider labelProvider) { public boolean shouldBeModal() { Map modals = (Map) dialogState.get(IStatusDialogConstants.STATUS_MODALS); for (Object value : modals.values()) { - if (value instanceof Boolean) { - Boolean b = (Boolean) value; + if (value instanceof Boolean b) { if (b.booleanValue()) { return true; } @@ -370,8 +369,9 @@ public boolean shouldPrompt(final StatusAdapter statusAdapter) { * @return Shell or null */ public Shell getShell() { - if (this.dialog == null) + if (this.dialog == null) { return null; + } return this.dialog.getShell(); } @@ -504,8 +504,7 @@ public void finished(JobTreeElement jte) { @Override public void removed(JobTreeElement jte) { - if (jte instanceof JobInfo) { - JobInfo jobInfo = (JobInfo) jte; + if (jte instanceof JobInfo jobInfo) { StatusAdapter statusAdapter = StatusAdapterHelper.getInstance().getStatusAdapter(jobInfo); if (statusAdapter != null) { getErrors().remove(statusAdapter); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/testing/PluginContributionAdapterFactory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/testing/PluginContributionAdapterFactory.java index abe1c810bf8..1c57a41743b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/testing/PluginContributionAdapterFactory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/testing/PluginContributionAdapterFactory.java @@ -43,9 +43,7 @@ public T getAdapter(Object adaptableObject, Class adapterType) { if (adapterType != ContributionInfo.class) { return null; } - if (adaptableObject instanceof IPluginContribution) { - IPluginContribution contribution = (IPluginContribution) adaptableObject; - + if (adaptableObject instanceof IPluginContribution contribution) { String elementType; if (contribution instanceof EditorDescriptor) { @@ -78,8 +76,7 @@ public T getAdapter(Object adaptableObject, Class adapterType) { return adapterType.cast(new ContributionInfo(contribution.getPluginId(), elementType, null)); } - if (adaptableObject instanceof JobInfo) { - JobInfo jobInfo = (JobInfo) adaptableObject; + if (adaptableObject instanceof JobInfo jobInfo) { Job job = jobInfo.getJob(); if (job != null) { Bundle bundle = FrameworkUtil.getBundle(job.getClass()); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/testing/WorkbenchPartTestable.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/testing/WorkbenchPartTestable.java index a486aa456fe..fe85b842014 100755 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/testing/WorkbenchPartTestable.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/testing/WorkbenchPartTestable.java @@ -25,7 +25,7 @@ */ public class WorkbenchPartTestable implements IWorkbenchPartTestable { - private Composite composite; + private final Composite composite; /** * Create a new instance of this class based on the provided part. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingColorRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingColorRegistry.java index b68554ffa2b..401b29c1764 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingColorRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingColorRegistry.java @@ -27,16 +27,17 @@ */ public class CascadingColorRegistry extends ColorRegistry { - private ColorRegistry parent; + private final ColorRegistry parent; - private IPropertyChangeListener listener = event -> { + private final IPropertyChangeListener listener = event -> { // check to see if we have an override for the given key. If so, // then a change in our parent registry shouldn't cause a change in // us. Without this check we will propagate a new value // (event.getNewValue()) to our listeners despite the fact that this // value is NOT our current value. - if (!hasOverrideFor(event.getProperty())) + if (!hasOverrideFor(event.getProperty())) { fireMappingChanged(event.getProperty(), event.getOldValue(), event.getNewValue()); + } }; /** diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingFontRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingFontRegistry.java index 534f7b4dbae..adc3fb916f8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingFontRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingFontRegistry.java @@ -27,16 +27,17 @@ */ public class CascadingFontRegistry extends FontRegistry { - private FontRegistry parent; + private final FontRegistry parent; - private IPropertyChangeListener listener = event -> { + private final IPropertyChangeListener listener = event -> { // check to see if we have an override for the given key. If so, // then a change in our parent registry shouldn't cause a change in // us. Without this check we will propagate a new value // (event.getNewValue()) to our listeners despite the fact that this // value is NOT our current value. - if (!hasOverrideFor(event.getProperty())) + if (!hasOverrideFor(event.getProperty())) { fireMappingChanged(event.getProperty(), event.getOldValue(), event.getNewValue()); + } }; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingMap.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingMap.java index c5b649d57ef..9232748fc7a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingMap.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingMap.java @@ -23,7 +23,7 @@ */ public class CascadingMap { - private Map base, override; + private final Map base, override; /** * @param base the base (default) map diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingTheme.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingTheme.java index 4eeb85dcb26..551cf74753d 100755 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingTheme.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/CascadingTheme.java @@ -26,13 +26,13 @@ */ public class CascadingTheme extends EventManager implements ITheme { - private CascadingFontRegistry fontRegistry; + private final CascadingFontRegistry fontRegistry; - private CascadingColorRegistry colorRegistry; + private final CascadingColorRegistry colorRegistry; - private ITheme currentTheme; + private final ITheme currentTheme; - private IPropertyChangeListener listener = this::fire; + private final IPropertyChangeListener listener = this::fire; public CascadingTheme(ITheme currentTheme, CascadingColorRegistry colorRegistry, CascadingFontRegistry fontRegistry) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorDefinition.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorDefinition.java index 35e00089bc6..a2219462097 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorDefinition.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorDefinition.java @@ -37,7 +37,7 @@ public class ColorDefinition extends ThemeElementDefinition implements IPluginCo private String defaultsTo; - private String pluginId; + private final String pluginId; private String rawValue; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorsAndFontsPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorsAndFontsPreferencePage.java index a6f6680a8d9..93dd53bf64b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorsAndFontsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorsAndFontsPreferencePage.java @@ -238,15 +238,17 @@ private boolean parentIsInSameCategory(FontDefinition definition) { @Override public Object getParent(Object element) { - if (element instanceof ThemeElementCategory) + if (element instanceof ThemeElementCategory) { return registry; + } if (element instanceof ColorDefinition) { String defaultId = ((IHierarchalThemeElementDefinition) element).getDefaultsTo(); if (defaultId != null) { ColorDefinition defaultElement = registry.findColor(defaultId); - if (parentIsInSameCategory(defaultElement)) + if (parentIsInSameCategory(defaultElement)) { return defaultElement; + } } String categoryId = ((ColorDefinition) element).getCategoryId(); return registry.findCategory(categoryId); @@ -256,8 +258,9 @@ public Object getParent(Object element) { String defaultId = ((FontDefinition) element).getDefaultsTo(); if (defaultId != null) { FontDefinition defaultElement = registry.findFont(defaultId); - if (parentIsInSameCategory(defaultElement)) + if (parentIsInSameCategory(defaultElement)) { return defaultElement; + } } String categoryId = ((FontDefinition) element).getCategoryId(); return registry.findCategory(categoryId); @@ -326,9 +329,9 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { private class PresentationLabelProvider extends LabelProvider implements IFontProvider, IColorProvider { - private HashMap fonts = new HashMap<>(); + private final HashMap fonts = new HashMap<>(); - private HashMap images = new HashMap<>(); + private final HashMap images = new HashMap<>(); private int imageSize = -1; @@ -344,7 +347,7 @@ private class PresentationLabelProvider extends LabelProvider implements IFontPr tree.getViewer().refresh(); }; - private IPropertyChangeListener listener = event -> { + private final IPropertyChangeListener listener = event -> { if (event.getNewValue() != null) { fireLabelProviderChanged(new LabelProviderChangedEvent(PresentationLabelProvider.this)); Display.getDefault().timerExec(REFRESH_INTERVAL_IN_MS, updateControlsAndRefreshTreeRunnable); @@ -476,8 +479,7 @@ private void ensureImageSize() { @Override public String getText(Object element) { - if (element instanceof IHierarchalThemeElementDefinition) { - IHierarchalThemeElementDefinition themeElement = (IHierarchalThemeElementDefinition) element; + if (element instanceof IHierarchalThemeElementDefinition themeElement) { if (themeElement.getDefaultsTo() != null) { String myCategory = ((ICategorizedThemeElementDefinition) themeElement).getCategoryId(); ICategorizedThemeElementDefinition def; @@ -507,17 +509,16 @@ public String getText(Object element) { * @since 3.2 */ private boolean isDefault(IThemeElementDefinition def) { - if (def instanceof FontDefinition) { - FontDefinition fontDef = (FontDefinition) def; + if (def instanceof FontDefinition fontDef) { String defaultFontID = fontDef.getDefaultsTo(); return defaultFontID != null && Arrays.equals(fontRegistry.getFontData(def.getId()), fontRegistry.getFontData(defaultFontID)); } - if (def instanceof ColorDefinition) { - ColorDefinition colorDef = (ColorDefinition) def; + if (def instanceof ColorDefinition colorDef) { String defaultColorID = colorDef.getDefaultsTo(); - if (defaultColorID == null) + if (defaultColorID == null) { return false; + } RGB defaultRGB = colorRegistry.getRGB(defaultColorID); return defaultRGB != null && defaultRGB.equals(colorRegistry.getRGB(colorDef.getId())); } @@ -554,7 +555,7 @@ public Color getBackground(Object element) { /** * Map to precalculate category color lists. */ - private Map categoryMap = new HashMap<>(7); + private final Map categoryMap = new HashMap<>(7); private Font appliedDialogFont; @@ -562,7 +563,7 @@ public Color getBackground(Object element) { * Map of definition ColorDefinition->RGB capturing the explicit changes made by * the user. These changes need to be stored into the preference store. */ - private Map colorPreferencesToSet = new HashMap<>(7); + private final Map colorPreferencesToSet = new HashMap<>(7); private CascadingColorRegistry colorRegistry; @@ -570,7 +571,7 @@ public Color getBackground(Object element) { * Map of definition id->RGB capturing the temporary changes caused by a * 'defaultsTo' color change. */ - private Map colorValuesToSet = new HashMap<>(7); + private final Map colorValuesToSet = new HashMap<>(7); /** * The default color preview composite. @@ -609,7 +610,7 @@ public Color getBackground(Object element) { private String fontSampleText; - private List dialogFontWidgets = new ArrayList<>(); + private final List dialogFontWidgets = new ArrayList<>(); private Button fontChangeButton; @@ -638,7 +639,7 @@ public Color getBackground(Object element) { * Map of definition FontDefinition->FontData[] capturing the changes explicitly * made by the user. These changes need to be stored into the preference store. */ - private Map fontPreferencesToSet = new HashMap<>(7); + private final Map fontPreferencesToSet = new HashMap<>(7); private CascadingFontRegistry fontRegistry; @@ -655,7 +656,7 @@ public Color getBackground(Object element) { * ThemeAPI and listeners */ @Deprecated - private Map fontValuesToSet = new HashMap<>(7); + private final Map fontValuesToSet = new HashMap<>(7); /** * The composite that is parent to all previews. @@ -665,12 +666,12 @@ public Color getBackground(Object element) { /** * A mapping from PresentationCategory->Composite for the created previews. */ - private Map previewMap = new HashMap<>(7); + private final Map previewMap = new HashMap<>(7); /** * Set containing all IPresentationPreviews created. */ - private Set previewSet = new HashSet<>(7); + private final Set previewSet = new HashSet<>(7); /** * The layout for the previewComposite. @@ -695,7 +696,7 @@ public Color getBackground(Object element) { private IEventBroker eventBroker; - private EventHandler themeRegistryRestyledHandler = new EventHandler() { + private final EventHandler themeRegistryRestyledHandler = new EventHandler() { @Override public void handleEvent(Event event) { if (isAnyThemeChanged()) { @@ -744,8 +745,9 @@ public ColorsAndFontsPreferencePage() { */ @Override public void applyData(Object data) { - if (tree == null || !(data instanceof String)) + if (tree == null || !(data instanceof String)) { return; + } ThemeRegistry themeRegistry = (ThemeRegistry) tree.getViewer().getInput(); String command = (String) data; @@ -785,12 +787,15 @@ private void selectAndReveal(Object selection) { } private static boolean equals(String string, String string2) { - if ((string == null && string2 == null)) + if ((string == null && string2 == null)) { return true; - if (string == null || string2 == null) + } + if (string == null || string2 == null) { return false; - if (string.equals(string2)) + } + if (string.equals(string2)) { return true; + } return false; } @@ -836,8 +841,9 @@ protected Control createContents(Composite parent) { PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IWorkbenchHelpContextIds.FONTS_PREFERENCE_PAGE); parent.addDisposeListener(e -> { - if (appliedDialogFont != null) + if (appliedDialogFont != null) { appliedDialogFont.dispose(); + } }); final SashForm advancedComposite = new SashForm(parent, SWT.VERTICAL); @@ -927,7 +933,7 @@ protected Control createContents(Composite parent) { updateTreeSelection(tree.getViewer().getSelection()); - advancedComposite.setWeights(new int[] { 75, 25 }); + advancedComposite.setWeights(75, 25); return advancedComposite; } @@ -946,8 +952,9 @@ private void createTree(Composite parent) { PatternFilter filter = new PatternFilter() { @Override protected boolean isLeafMatch(Viewer viewer, Object element) { - if (super.isLeafMatch(viewer, element)) + if (super.isLeafMatch(viewer, element)) { return true; + } return wordMatches(getText(element)); } @@ -988,16 +995,18 @@ private String getText(Object element) { tree.setLayoutData(data); myApplyDialogFont(tree.getViewer().getControl()); Text filterText = tree.getFilterControl(); - if (filterText != null) + if (filterText != null) { myApplyDialogFont(filterText); + } tree.getViewer().setLabelProvider(labelProvider); tree.getViewer().setContentProvider(new ThemeContentProvider()); tree.getViewer().setComparator(new ViewerComparator() { @Override public int category(Object element) { - if (element instanceof ThemeElementCategory) + if (element instanceof ThemeElementCategory) { return 0; + } return 1; } }); @@ -1005,12 +1014,11 @@ public int category(Object element) { tree.getViewer().addDoubleClickListener(event -> { IStructuredSelection s = (IStructuredSelection) event.getSelection(); Object element = s.getFirstElement(); - if (tree.getViewer().isExpandable(element)) + if (tree.getViewer().isExpandable(element)) { tree.getViewer().setExpandedState(element, !tree.getViewer().getExpandedState(element)); + } - if (element instanceof ThemeElementDefinition) { - ThemeElementDefinition definition = (ThemeElementDefinition) element; - + if (element instanceof ThemeElementDefinition definition) { if (element instanceof FontDefinition) { editFont(tree.getDisplay()); } else if (element instanceof ColorDefinition && isAvailableInCurrentTheme(definition)) { @@ -1038,8 +1046,9 @@ public void dispose() { * Clear all previews. */ private void clearPreviews() { - if (cascadingTheme != null) + if (cascadingTheme != null) { cascadingTheme.dispose(); + } for (IThemePreview preview : previewSet) { try { @@ -1061,8 +1070,9 @@ private void clearPreviews() { */ private ColorDefinition getColorAncestor(ColorDefinition definition) { String defaultsTo = definition.getDefaultsTo(); - if (defaultsTo == null) + if (defaultsTo == null) { return null; + } return themeRegistry.findColor(defaultsTo); } @@ -1074,8 +1084,9 @@ private ColorDefinition getColorAncestor(ColorDefinition definition) { */ private RGB getColorAncestorValue(ColorDefinition definition) { ColorDefinition ancestor = getColorAncestor(definition); - if (ancestor == null) + if (ancestor == null) { return null; + } return getColorValue(ancestor); } @@ -1091,8 +1102,9 @@ private RGB getColorValue(ColorDefinition definition) { RGB updatedRGB = colorPreferencesToSet.get(definition); if (updatedRGB == null) { updatedRGB = colorValuesToSet.get(id); - if (updatedRGB == null) + if (updatedRGB == null) { updatedRGB = currentTheme.getColorRegistry().getRGB(id); + } } return updatedRGB; } @@ -1115,8 +1127,9 @@ private ColorDefinition[] getDescendantColors(ColorDefinition definition) { Arrays.sort(sorted, new IThemeRegistry.HierarchyComparator(colors)); for (ColorDefinition colorDefinition : sorted) { - if (id.equals(colorDefinition.getDefaultsTo())) + if (id.equals(colorDefinition.getDefaultsTo())) { list.add(colorDefinition); + } } return list.toArray(new ColorDefinition[list.size()]); } @@ -1132,16 +1145,18 @@ private FontDefinition[] getDescendantFonts(FontDefinition definition) { Arrays.sort(sorted, new IThemeRegistry.HierarchyComparator(fonts)); for (FontDefinition fontDefinition : sorted) { - if (id.equals(fontDefinition.getDefaultsTo())) + if (id.equals(fontDefinition.getDefaultsTo())) { list.add(fontDefinition); + } } return list.toArray(new FontDefinition[list.size()]); } private FontDefinition getFontAncestor(FontDefinition definition) { String defaultsTo = definition.getDefaultsTo(); - if (defaultsTo == null) + if (defaultsTo == null) { return null; + } return themeRegistry.findFont(defaultsTo); } @@ -1158,8 +1173,9 @@ protected FontData[] getFontValue(FontDefinition definition) { FontData[] updatedFD = fontPreferencesToSet.get(definition); if (updatedFD == null) { updatedFD = fontValuesToSet.get(id); - if (updatedFD == null) + if (updatedFD == null) { updatedFD = currentTheme.getFontRegistry().getFontData(id); + } } return updatedFD; } @@ -1199,25 +1215,28 @@ private void hookListeners() { fontChangeButton.addSelectionListener(widgetSelectedAdapter(event -> { Display display = event.display; - if (isFontSelected()) + if (isFontSelected()) { editFont(display); - else if (isColorSelected()) + } else if (isColorSelected()) { editColor(display); + } updateControls(); })); fontResetButton.addSelectionListener(widgetSelectedAdapter(e -> { - if (isFontSelected()) + if (isFontSelected()) { resetFont(getSelectedFontDefinition(), false); - else if (isColorSelected()) + } else if (isColorSelected()) { resetColor(getSelectedColorDefinition(), false); + } updateControls(); })); fontSystemButton.addSelectionListener(widgetSelectedAdapter(event -> { FontDefinition definition = getSelectedFontDefinition(); - if (definition == null) + if (definition == null) { return; + } FontData[] defaultFontData = JFaceResources.getDefaultFont().getFontData(); setFontPreferenceValue(definition, defaultFontData, false); updateControls(); @@ -1288,13 +1307,16 @@ private void updateThemeInfo(IThemeManager manager) { clearPreviews(); categoryMap.clear(); - if (labelProvider != null) + if (labelProvider != null) { labelProvider.dispose(); // nuke the old cache + } - if (colorRegistry != null) + if (colorRegistry != null) { colorRegistry.dispose(); - if (fontRegistry != null) + } + if (fontRegistry != null) { fontRegistry.dispose(); + } currentTheme = manager.getCurrentTheme(); @@ -1314,8 +1336,9 @@ private void updateThemeInfo(IThemeManager manager) { colorPreferencesToSet.clear(); colorValuesToSet.clear(); - if (labelProvider != null) + if (labelProvider != null) { labelProvider.hookListeners(); // rehook the listeners + } } private RGB getColorTakingPreferenceDefaultValueIntoAccount(ColorDefinition definition) { @@ -1355,17 +1378,21 @@ private boolean isDefault(ColorDefinition definition) { if (colorPreferencesToSet.containsKey(definition)) { if (definition.getValue() != null) { // value-based color if (colorPreferencesToSet.get(definition) - .equals(getColorTakingPreferenceDefaultValueIntoAccount(definition))) + .equals(getColorTakingPreferenceDefaultValueIntoAccount(definition))) { return true; - } else if (colorPreferencesToSet.get(definition).equals(getColorAncestorValue(definition))) + } + } else if (colorPreferencesToSet.get(definition).equals(getColorAncestorValue(definition))) { return true; + } } else if (colorValuesToSet.containsKey(id)) { if (definition.getValue() != null) { // value-based color - if (colorValuesToSet.get(id).equals(getColorTakingPreferenceDefaultValueIntoAccount(definition))) + if (colorValuesToSet.get(id).equals(getColorTakingPreferenceDefaultValueIntoAccount(definition))) { return true; + } } else { - if (colorValuesToSet.get(id).equals(getColorAncestorValue(definition))) + if (colorValuesToSet.get(id).equals(getColorAncestorValue(definition))) { return true; + } } } else if (definition.getValue() != null) { // value-based color IPreferenceStore store = getPreferenceStore(); @@ -1374,13 +1401,15 @@ private boolean isDefault(ColorDefinition definition) { if (defaultString != null && string != null && defaultString.equals(string)) { return true; } - if (store.isDefault(createPreferenceKey(definition))) + if (store.isDefault(createPreferenceKey(definition))) { return true; + } } else { // a descendant is default if it's the same value as its ancestor RGB rgb = getColorValue(definition); - if (rgb != null && rgb.equals(getColorAncestorValue(definition))) + if (rgb != null && rgb.equals(getColorAncestorValue(definition))) { return true; + } } return false; } @@ -1390,33 +1419,40 @@ private boolean isDefault(FontDefinition definition) { if (fontPreferencesToSet.containsKey(definition)) { if (definition.getValue() != null) { // value-based font - if (Arrays.equals(fontPreferencesToSet.get(definition), definition.getValue())) + if (Arrays.equals(fontPreferencesToSet.get(definition), definition.getValue())) { return true; + } } else { FontData[] ancestor = getFontAncestorValue(definition); - if (Arrays.equals(fontPreferencesToSet.get(definition), ancestor)) + if (Arrays.equals(fontPreferencesToSet.get(definition), ancestor)) { return true; + } } } else if (fontValuesToSet.containsKey(id)) { if (definition.getValue() != null) { // value-based font - if (Arrays.equals(fontValuesToSet.get(id), definition.getValue())) + if (Arrays.equals(fontValuesToSet.get(id), definition.getValue())) { return true; + } } else { FontData[] ancestor = getFontAncestorValue(definition); - if (Arrays.equals(fontValuesToSet.get(id), ancestor)) + if (Arrays.equals(fontValuesToSet.get(id), ancestor)) { return true; + } } } else if (definition.getValue() != null) { // value-based font - if (getPreferenceStore().isDefault(createPreferenceKey(definition))) + if (getPreferenceStore().isDefault(createPreferenceKey(definition))) { return true; + } } else { FontData[] ancestor = getFontAncestorValue(definition); - if (ancestor == null) + if (ancestor == null) { return true; + } // a descendant is default if it's the same value as its ancestor - if (Arrays.equals(getFontValue(definition), ancestor)) + if (Arrays.equals(getFontValue(definition), ancestor)) { return true; + } } return false; } @@ -1440,8 +1476,9 @@ protected void performApply() { // Apply the default font to the dialog. Font oldFont = appliedDialogFont; FontDefinition fontDefinition = themeRegistry.findFont(JFaceResources.DIALOG_FONT); - if (fontDefinition == null) + if (fontDefinition == null) { return; + } FontData[] newData = getFontValue(fontDefinition); appliedDialogFont = new Font(getControl().getDisplay(), newData); @@ -1479,8 +1516,9 @@ private boolean performColorOk() { String rgbString = StringConverter.asString(entry.getValue()); String storeString = getPreferenceStore().getString(key); - if (!rgbString.equals(storeString)) + if (!rgbString.equals(storeString)) { getPreferenceStore().setValue(key, rgbString); + } } colorValuesToSet.clear(); @@ -1523,8 +1561,9 @@ private boolean performFontOk() { String fdString = PreferenceConverter.getStoredRepresentation(entry.getValue()); String storeString = getPreferenceStore().getString(key); - if (!fdString.equals(storeString)) + if (!fdString.equals(storeString)) { getPreferenceStore().setValue(key, fdString); + } } fontValuesToSet.clear(); @@ -1562,9 +1601,9 @@ private boolean resetColor(ColorDefinition definition, boolean force) { RGB newRGB; if (definition.getValue() != null) { newRGB = getColorTakingPreferenceDefaultValueIntoAccount(definition); - } - else + } else { newRGB = getColorAncestorValue(definition); + } if (newRGB != null) { setColorPreferenceValue(definition, newRGB, true); @@ -1664,14 +1703,16 @@ protected void setRegistryValue(FontDefinition definition, FontData[] datas) { */ private IThemePreview getThemePreview(ThemeElementCategory category) throws CoreException { IThemePreview preview = category.createPreview(); - if (preview != null) + if (preview != null) { return preview; + } if (category.getParentId() != null) { int idx = Arrays.binarySearch(themeRegistry.getCategories(), category.getParentId(), IThemeRegistry.ID_COMPARATOR); - if (idx >= 0) + if (idx >= 0) { return getThemePreview(themeRegistry.getCategories()[idx]); + } } return null; } @@ -1735,12 +1776,13 @@ private void updateTreeSelection(ISelection selection) { } if (previewControl == null) { // there is no preview for this theme, use default preview - if (element instanceof ColorDefinition) + if (element instanceof ColorDefinition) { previewControl = defaultColorPreview; - else if (element instanceof FontDefinition) + } else if (element instanceof FontDefinition) { previewControl = defaultFontPreview; - else + } else { previewControl = defaultNoPreview; + } } stackLayout.topControl = previewControl; @@ -1755,11 +1797,13 @@ else if (element instanceof FontDefinition) */ private void restoreTreeSelection() { String selectedElementString = getPreferenceStore().getString(SELECTED_ELEMENT_PREF); - if (selectedElementString == null) + if (selectedElementString == null) { return; + } Object element = findElementFromMarker(selectedElementString); - if (element == null) + if (element == null) { return; + } tree.getViewer().setSelection(new StructuredSelection(element), true); } @@ -1773,8 +1817,9 @@ private void saveTreeSelection() { Object element = selection.getFirstElement(); StringBuilder buffer = new StringBuilder(); appendMarkerToBuffer(buffer, element); - if (buffer.length() > 0) + if (buffer.length() > 0) { buffer.append(((IThemeElementDefinition) element).getId()); + } getPreferenceStore().setValue(SELECTED_ELEMENT_PREF, buffer.toString()); } @@ -1785,17 +1830,20 @@ private void saveTreeSelection() { */ private void restoreTreeExpansion() { String expandedElementsString = getPreferenceStore().getString(EXPANDED_ELEMENTS_PREF); - if (expandedElementsString == null) + if (expandedElementsString == null) { return; + } String[] expandedElementIDs = expandedElementsString.split(EXPANDED_ELEMENTS_TOKEN); - if (expandedElementIDs.length == 0) + if (expandedElementIDs.length == 0) { return; + } List elements = new ArrayList<>(expandedElementIDs.length); for (String expandedElementID : expandedElementIDs) { IThemeElementDefinition def = findElementFromMarker(expandedElementID); - if (def != null) + if (def != null) { elements.add(def); + } } tree.getViewer().setExpandedElements(elements.toArray()); } @@ -1810,8 +1858,9 @@ private void restoreTreeExpansion() { * @return the element, or null */ private IThemeElementDefinition findElementFromMarker(String string) { - if (string.length() < 2) + if (string.length() < 2) { return null; + } char marker = string.charAt(0); String id = string.substring(1); @@ -1906,8 +1955,9 @@ private void editColor(Display display) { } private void editColor(ColorDefinition definition, Display display) { - if (definition == null) + if (definition == null) { return; + } RGB currentColor = colorRegistry.getRGB(definition.getId()); ColorDialog colorDialog = new ColorDialog(display.getActiveShell()); @@ -2029,23 +2079,26 @@ private Composite createFontPreviewControl() { fontSampler.setLayoutData(new GridData(GridData.FILL_BOTH)); fontSampler.addPaintListener(e -> { - if (currentFont != null) // do the font preview + if (currentFont != null) { // do the font preview paintFontSample(e.gc); + } }); return fontSampler; } private void paintFontSample(GC gc) { - if (currentFont == null || currentFont.isDisposed()) + if (currentFont == null || currentFont.isDisposed()) { return; + } // draw rectangle all around Rectangle clientArea = colorSampler.getClientArea(); FontMetrics standardFontMetrics = gc.getFontMetrics(); int standardLineHeight = standardFontMetrics.getHeight(); int maxHeight = standardLineHeight * 4; - if (clientArea.height > maxHeight) + if (clientArea.height > maxHeight) { clientArea = new Rectangle(clientArea.x, clientArea.y, clientArea.width, maxHeight); + } gc.setForeground(previewComposite.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); gc.drawRectangle(0, 0, clientArea.width - 1, clientArea.height - 1); @@ -2070,22 +2123,25 @@ private Composite createColorPreviewControl() { colorSampler.setLayoutData(new GridData(GridData.FILL_BOTH)); colorSampler.addPaintListener(e -> { - if (currentColor != null) // do the color preview + if (currentColor != null) { // do the color preview paintColorSample(e.gc); + } }); return colorSampler; } private void paintColorSample(GC gc) { - if (currentColor == null || currentColor.isDisposed()) + if (currentColor == null || currentColor.isDisposed()) { return; + } gc.setFont(previewComposite.getDisplay().getSystemFont()); FontMetrics fontMetrics = gc.getFontMetrics(); int lineHeight = fontMetrics.getHeight(); Rectangle clientArea = colorSampler.getClientArea(); int maxHeight = lineHeight * 4; - if (clientArea.height > maxHeight) + if (clientArea.height > maxHeight) { clientArea = new Rectangle(clientArea.x, clientArea.y, clientArea.width, maxHeight); + } String messageTop = RESOURCE_BUNDLE.getString("fontColorSample"); //$NON-NLS-1$ String fontColorString = RESOURCE_BUNDLE.getString("fontColorString"); //$NON-NLS-1$ @@ -2099,25 +2155,29 @@ private void paintColorSample(GC gc) { // calculate text positions int verticalCenter = clientArea.height / 2; int textTopY = (verticalCenter - lineHeight) / 2; - if (textTopY < 1) + if (textTopY < 1) { textTopY = 1; + } textTopY += clientArea.y; int textBottomY = verticalCenter + textTopY; - if (textBottomY > clientArea.height - 2) + if (textBottomY > clientArea.height - 2) { textBottomY = clientArea.height - 2; + } textBottomY += clientArea.y; int stringWidthTop = gc.stringExtent(messageTop).x; int textTopX = (separator - stringWidthTop - 1) / 2; - if (textTopX < 1) + if (textTopX < 1) { textTopX = 1; + } textTopX += clientArea.x; int stringWidthBottom = gc.stringExtent(messageBottom).x; int textBottomX = (separator - stringWidthBottom - 1) / 2; - if (textBottomX < 1) + if (textBottomX < 1) { textBottomX = 1; + } textBottomX += clientArea.x; // put text on the left - default background @@ -2184,8 +2244,7 @@ private void refreshAllLabels() { } private boolean isAvailableInCurrentTheme(ThemeElementDefinition definition) { - if (definition instanceof ColorDefinition) { - ColorDefinition colorDef = (ColorDefinition) definition; + if (definition instanceof ColorDefinition colorDef) { RGB value = colorDef.getValue(); if ((value == null || value == EMPTY_COLOR_VALUE) && colorDef.getDefaultsTo() == null) { return false; @@ -2216,7 +2275,7 @@ private void refreshElement(ThemeElementDefinition definition) { tree.getViewer().refresh(definition); updateTreeSelection(tree.getViewer().getSelection()); - Object newValue = definition instanceof ColorDefinition ? ((ColorDefinition) definition).getValue() + Object newValue = definition instanceof ColorDefinition c ? c.getValue() : ((FontDefinition) definition).getValue(); getCascadingTheme().fire(new PropertyChangeEvent(this, definition.getId(), null, newValue)); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/IThemeRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/IThemeRegistry.java index fb56ec9c2bc..737a35b4088 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/IThemeRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/IThemeRegistry.java @@ -33,7 +33,7 @@ public interface IThemeRegistry { */ public static class HierarchyComparator implements Comparator { - private IHierarchalThemeElementDefinition[] definitions; + private final IHierarchalThemeElementDefinition[] definitions; /** * Create a new comparator. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/LightColorFactory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/LightColorFactory.java index d4b46d01de7..c739134ac76 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/LightColorFactory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/LightColorFactory.java @@ -63,8 +63,7 @@ public static RGB createHighlightStartColor(RGB tabStartColor) { @Override public void setInitializationData(IConfigurationElement config, String propertyName, Object data) { - if (data instanceof Hashtable) { - Hashtable table = (Hashtable) data; + if (data instanceof Hashtable table) { baseColorName = (String) table.get("base"); //$NON-NLS-1$ definitionId = (String) table.get("definitionId"); //$NON-NLS-1$ } @@ -76,12 +75,15 @@ public void setInitializationData(IConfigurationElement config, String propertyN */ protected int valuesInRange(RGB test, int lower, int upper) { int hits = 0; - if (test.red >= lower && test.red <= upper) + if (test.red >= lower && test.red <= upper) { hits++; - if (test.blue >= lower && test.blue <= upper) + } + if (test.blue >= lower && test.blue <= upper) { hits++; - if (test.green >= lower && test.green <= upper) + } + if (test.green >= lower && test.green <= upper) { hits++; + } return hits; } @@ -92,16 +94,19 @@ protected int valuesInRange(RGB test, int lower, int upper) { */ private RGB getLightenedColor(RGB sample) { // Group 1 - if (valuesInRange(sample, 180, 255) >= 2) + if (valuesInRange(sample, 180, 255) >= 2) { return sample; + } // Group 2 - if (valuesInRange(sample, 100, 179) >= 2) + if (valuesInRange(sample, 100, 179) >= 2) { return ColorUtil.blend(white, sample, 40); + } // Group 3 - if (valuesInRange(sample, 0, 99) >= 2) + if (valuesInRange(sample, 0, 99) >= 2) { return ColorUtil.blend(white, sample, 60); + } // Group 4 return ColorUtil.blend(white, sample, 30); @@ -111,8 +116,9 @@ private RGB getLightenedColor(RGB sample) { * Return the Start (top of tab) color as an RGB */ private RGB getActiveFocusStartColor() { - if (Display.getCurrent().getDepth() < 15) + if (Display.getCurrent().getDepth() < 15) { return getActiveFocusEndColor(); + } return ColorUtil.blend(white, getActiveFocusEndColor(), 75); } @@ -121,8 +127,9 @@ private RGB getActiveFocusStartColor() { * Return the End (top of tab) color as an RGB */ private RGB getActiveFocusEndColor() { - if (Display.getCurrent().getDepth() < 15) + if (Display.getCurrent().getDepth() < 15) { return ColorUtil.getColorValue(baseColorName); + } return getLightenedColor(ColorUtil.getColorValue(baseColorName)); } @@ -131,8 +138,9 @@ private RGB getActiveFocusEndColor() { * Return the active focus tab text color as an RGB */ private RGB getActiveFocusTextColor() { - if (Display.getCurrent().getDepth() < 15) + if (Display.getCurrent().getDepth() < 15) { return ColorUtil.getColorValue(baseColorName); // typically TITLE_FOREGROUND + } return ColorUtil.getColorValue("COLOR_BLACK"); //$NON-NLS-1$ } @@ -142,8 +150,9 @@ private RGB getActiveFocusTextColor() { */ private RGB getActiveNofocusStartColor() { RGB base = ColorUtil.getColorValue(baseColorName); - if (Display.getCurrent().getDepth() < 15) + if (Display.getCurrent().getDepth() < 15) { return base; + } return ColorUtil.blend(white, base, 40); } @@ -151,17 +160,22 @@ private RGB getActiveNofocusStartColor() { @Override public RGB createColor() { // should have base, otherwise error in the xml - if (baseColorName == null || definitionId == null) + if (baseColorName == null || definitionId == null) { return white; + } - if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START")) //$NON-NLS-1$ + if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START")) { //$NON-NLS-1$ return getActiveFocusStartColor(); - if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END")) //$NON-NLS-1$ + } + if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END")) { //$NON-NLS-1$ return getActiveFocusEndColor(); - if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")) //$NON-NLS-1$ + } + if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")) { //$NON-NLS-1$ return getActiveFocusTextColor(); - if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START")) //$NON-NLS-1$ + } + if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START")) { //$NON-NLS-1$ return getActiveNofocusStartColor(); + } // should be one of start or end, otherwise error in the xml return white; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBBrightnessColorFactory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBBrightnessColorFactory.java index 250735d3e19..393e9367f8d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBBrightnessColorFactory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBBrightnessColorFactory.java @@ -34,10 +34,12 @@ public RGB createColor() { float scale = Float.parseFloat(scaleFactor); float[] hsb = rgb.getHSB(); float b = hsb[2] * scale; - if (b < 0) + if (b < 0) { b = 0; - if (b > 1) + } + if (b > 1) { b = 1; + } return new RGB(hsb[0], hsb[1], b); } @@ -55,8 +57,7 @@ public RGB createColor() { */ @Override public void setInitializationData(IConfigurationElement config, String propertyName, Object data) { - if (data instanceof Hashtable) { - Hashtable table = (Hashtable) data; + if (data instanceof Hashtable table) { color = (String) table.get("color"); //$NON-NLS-1$ scaleFactor = (String) table.get("scaleFactor"); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBContrastFactory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBContrastFactory.java index 0a9fa1b167a..cc5d0b9590f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBContrastFactory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBContrastFactory.java @@ -155,8 +155,7 @@ public RGB createColor() { */ @Override public void setInitializationData(IConfigurationElement config, String propertyName, Object data) { - if (data instanceof Hashtable) { - Hashtable table = (Hashtable) data; + if (data instanceof Hashtable table) { fg = (String) table.get("foreground"); //$NON-NLS-1$ bg1 = (String) table.get("background1"); //$NON-NLS-1$ bg2 = (String) table.get("background2"); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBInfoColorFactory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBInfoColorFactory.java index 4a5df9f875e..1eb68dc4d39 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBInfoColorFactory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/RGBInfoColorFactory.java @@ -71,8 +71,7 @@ public RGB createColor() { @Override public void setInitializationData(IConfigurationElement config, String propertyName, Object data) { - if (data instanceof Hashtable) { - Hashtable map = (Hashtable) data; + if (data instanceof Hashtable map) { color = (String) map.get("color"); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/Theme.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/Theme.java index 2440fac0c77..6643bcf1144 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/Theme.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/Theme.java @@ -49,13 +49,13 @@ public class Theme extends EventManager implements ITheme { private CascadingFontRegistry themeFontRegistry; - private IThemeDescriptor descriptor; + private final IThemeDescriptor descriptor; private IPropertyChangeListener themeListener; private CascadingMap dataMap; - private ThemeRegistry themeRegistry; + private final ThemeRegistry themeRegistry; private IPropertyChangeListener propertyListener; @@ -105,16 +105,18 @@ private void registryColorChangeEvent(PropertyChangeEvent event) { if (oldColor == PreferenceConverter.COLOR_DEFAULT_DEFAULT) { // If the preference is set to default, but there is no actual default value, // then the preference state is inconsistent. Do nothing. - } else if (!newColor.equals(oldColor)) + } else if (!newColor.equals(oldColor)) { PreferenceConverter.setValue(store, key, newColor); + } } else { RGB oldColor = PreferenceConverter.getColor(store, key); if (!newColor.equals(oldColor)) { oldColor = PreferenceConverter.getDefaultColor(store, key); - if (oldColor != PreferenceConverter.COLOR_DEFAULT_DEFAULT && newColor.equals(oldColor)) + if (oldColor != PreferenceConverter.COLOR_DEFAULT_DEFAULT && newColor.equals(oldColor)) { store.setToDefault(key); - else + } else { PreferenceConverter.setValue(store, key, newColor); + } } } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeDescriptor.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeDescriptor.java index c6952f42a0c..538d71b0e19 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeDescriptor.java @@ -33,17 +33,17 @@ public class ThemeDescriptor implements IThemeDescriptor { private static final String ATT_NAME = "name";//$NON-NLS-1$ - private Collection colors = new HashSet<>(); + private final Collection colors = new HashSet<>(); private String description; - private Collection fonts = new HashSet<>(); + private final Collection fonts = new HashSet<>(); - private String id; + private final String id; private String name; - private Map dataMap = new HashMap<>(); + private final Map dataMap = new HashMap<>(); /** * Create a new ThemeDescriptor @@ -116,8 +116,9 @@ public String getId() { @Override public String getName() { - if (name == null) + if (name == null) { return getId(); + } return name; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeElementCategory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeElementCategory.java index 03f45d10a84..e0c9cb86694 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeElementCategory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeElementCategory.java @@ -25,17 +25,17 @@ */ public class ThemeElementCategory implements IPluginContribution, IThemeElementDefinition { - private String description; + private final String description; - private IConfigurationElement element; + private final IConfigurationElement element; - private String id; + private final String id; - private String parentId; + private final String parentId; - private String label; + private final String label; - private String pluginId; + private final String pluginId; public ThemeElementCategory(String label, String id, String parentId, String description, String pluginId, IConfigurationElement element) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeElementDefinition.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeElementDefinition.java index 26c14e7f8a1..e1dffb7cac2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeElementDefinition.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeElementDefinition.java @@ -34,7 +34,7 @@ public interface State { int MODIFIED_BY_USER = 4; } - private String id; + private final String id; private String label; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeRegistry.java index 6476fdd23fd..df6027799f9 100755 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeRegistry.java @@ -31,15 +31,15 @@ */ public class ThemeRegistry implements IThemeRegistry { - private List themes; + private final List themes; - private List colors; + private final List colors; - private List fonts; + private final List fonts; - private List categories; + private final List categories; - private Map dataMap; + private final Map dataMap; /** * Create a new ThemeRegistry. @@ -178,12 +178,10 @@ private IThemeElementDefinition[] overlay(IThemeElementDefinition[] defs, ITheme * @return the overlayed element */ private IThemeElementDefinition overlay(IThemeElementDefinition original, IThemeElementDefinition overlay) { - if (original instanceof ColorDefinition) { - ColorDefinition originalColor = (ColorDefinition) original; + if (original instanceof ColorDefinition originalColor) { ColorDefinition overlayColor = (ColorDefinition) overlay; return new ColorDefinition(originalColor, overlayColor.getValue()); - } else if (original instanceof FontDefinition) { - FontDefinition originalFont = (FontDefinition) original; + } else if (original instanceof FontDefinition originalFont) { FontDefinition overlayFont = (FontDefinition) overlay; return new FontDefinition(originalFont, overlayFont.getValue()); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeRegistryReader.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeRegistryReader.java index e537bb52d2f..0faa2e4f883 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeRegistryReader.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemeRegistryReader.java @@ -40,17 +40,17 @@ public class ThemeRegistryReader extends RegistryReader { */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(ThemeRegistryReader.class.getName()); - private Collection categoryDefinitions = new HashSet<>(); + private final Collection categoryDefinitions = new HashSet<>(); - private Collection colorDefinitions = new HashSet<>(); + private final Collection colorDefinitions = new HashSet<>(); - private Collection fontDefinitions = new HashSet<>(); + private final Collection fontDefinitions = new HashSet<>(); private ThemeDescriptor themeDescriptor = null; private ThemeRegistry themeRegistry; - private Map dataMap = new HashMap<>(); + private final Map dataMap = new HashMap<>(); /** * ThemeRegistryReader constructor comment. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemesExtension.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemesExtension.java index 0bf87bbe33e..201f17f836f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemesExtension.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ThemesExtension.java @@ -27,7 +27,7 @@ public class ThemesExtension implements IThemesExtension { public static final String DEFAULT_CATEGORY_ID = "org.eclipse.ui.themes.CssTheme"; //$NON-NLS-1$ - private List> definitions = new ArrayList<>(); + private final List> definitions = new ArrayList<>(); @Override public void addFontDefinition(String symbolicName) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/WorkbenchPreview.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/WorkbenchPreview.java index bea11c8d451..518c5b9c848 100755 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/WorkbenchPreview.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/WorkbenchPreview.java @@ -57,7 +57,7 @@ public class WorkbenchPreview implements IThemePreview { private ViewForm viewForm; - private IPropertyChangeListener fontAndColorListener = event -> { + private final IPropertyChangeListener fontAndColorListener = event -> { if (!disposed) { setColorsAndFonts(); // viewMessage.setSize(viewMessage.computeSize(SWT.DEFAULT, SWT.DEFAULT, true)); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/WorkbenchThemeManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/WorkbenchThemeManager.java index b2e98ea90e4..691725a4665 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/WorkbenchThemeManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/WorkbenchThemeManager.java @@ -95,7 +95,7 @@ public static synchronized void disposeManager() { private ITheme currentTheme; - private IPropertyChangeListener currentThemeListener = event -> { + private final IPropertyChangeListener currentThemeListener = event -> { firePropertyChange(event); if (event.getSource() instanceof FontRegistry) { JFaceResources.getFontRegistry().put(event.getProperty(), (FontData[]) event.getNewValue()); @@ -110,11 +110,11 @@ public static synchronized void disposeManager() { private IThemeRegistry themeRegistry; - private Map themes = new HashMap<>(7); + private final Map themes = new HashMap<>(7); - private EventHandler themeChangedHandler = new WorkbenchThemeChangedHandler(); + private final EventHandler themeChangedHandler = new WorkbenchThemeChangedHandler(); - private EventHandler themeRegistryModifiedHandler = new ThemeRegistryModifiedHandler(); + private final EventHandler themeRegistryModifiedHandler = new ThemeRegistryModifiedHandler(); private boolean initialized = false; @@ -148,8 +148,9 @@ private synchronized void init() { .getDefaultString(IWorkbenchPreferenceConstants.CURRENT_THEME_ID); // If not set, use default - if (themeId.isEmpty()) + if (themeId.isEmpty()) { themeId = IThemeManager.DEFAULT_THEME; + } final boolean highContrast = Display.getCurrent().getHighContrast(); @@ -157,8 +158,9 @@ private synchronized void init() { // If in HC, *always* use the system default. // This ignores any default theme set via plugin_customization.ini - if (highContrast) + if (highContrast) { themeId = SYSTEM_DEFAULT_THEME; + } PrefUtil.getAPIPreferenceStore().setDefault(IWorkbenchPreferenceConstants.CURRENT_THEME_ID, themeId); @@ -257,9 +259,9 @@ public ITheme getCurrentTheme() { if (currentTheme == null) { String themeId = PrefUtil.getAPIPreferenceStore().getString(IWorkbenchPreferenceConstants.CURRENT_THEME_ID); - if (themeId == null) // missing preference + if (themeId == null) { // missing preference setCurrentTheme(IThemeManager.DEFAULT_THEME); - else { + } else { setCurrentTheme(themeId); if (currentTheme == null) { // still null - the preference // didn't resolve to a proper theme diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/tweaklets/Tweaklets.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/tweaklets/Tweaklets.java index 4d1b38ce6f1..5a1c26dc6e8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/tweaklets/Tweaklets.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/tweaklets/Tweaklets.java @@ -44,12 +44,15 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final TweakKey other = (TweakKey) obj; return Objects.equals(tweakClass, other.tweakClass); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/util/BundleUtility.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/util/BundleUtility.java index eeef36ab989..13156fd6e6f 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/util/BundleUtility.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/util/BundleUtility.java @@ -37,8 +37,9 @@ public static boolean isActive(Bundle bundle) { } public static boolean isActivated(Bundle bundle) { - if (bundle != null && (bundle.getState() & Bundle.STARTING) != 0) + if (bundle != null && (bundle.getState() & Bundle.STARTING) != 0) { return WorkbenchPlugin.getDefault().isStarting(bundle); + } return bundle != null && (bundle.getState() & (Bundle.ACTIVE | Bundle.STOPPING)) != 0; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/util/ConfigurationElementMemento.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/util/ConfigurationElementMemento.java index a1d883f7132..72e7df5859c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/util/ConfigurationElementMemento.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/util/ConfigurationElementMemento.java @@ -19,7 +19,7 @@ public final class ConfigurationElementMemento implements IMemento { - private IConfigurationElement configurationElement; + private final IConfigurationElement configurationElement; public ConfigurationElementMemento(IConfigurationElement configurationElement) { if (configurationElement == null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/AbstractExtensionWizardRegistry.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/AbstractExtensionWizardRegistry.java index f6e5728c6e6..a032586132c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/AbstractExtensionWizardRegistry.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/AbstractExtensionWizardRegistry.java @@ -152,12 +152,10 @@ public void removeExtension(IExtension extension, Object[] objects) { return; } for (Object object : objects) { - if (object instanceof WizardCollectionElement) { + if (object instanceof WizardCollectionElement collection) { // TODO: should we move child wizards to the "other" node? - WizardCollectionElement collection = (WizardCollectionElement) object; collection.getParentCollection().remove(collection); - } else if (object instanceof WorkbenchWizardElement) { - WorkbenchWizardElement wizard = (WorkbenchWizardElement) object; + } else if (object instanceof WorkbenchWizardElement wizard) { WizardCollectionElement parent = wizard.getCollectionElement(); if (parent != null) { parent.remove(wizard); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/preferences/PreferencesContentProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/preferences/PreferencesContentProvider.java index ebab43bdf1e..b96098b0e99 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/preferences/PreferencesContentProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/preferences/PreferencesContentProvider.java @@ -42,8 +42,9 @@ public boolean hasChildren(Object element) { @Override public Object[] getElements(Object inputElement) { - if (inputElement instanceof PreferenceTransferElement[]) + if (inputElement instanceof PreferenceTransferElement[]) { return (PreferenceTransferElement[]) inputElement; + } return new PreferenceTransferElement[0]; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/preferences/WizardPreferencesPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/preferences/WizardPreferencesPage.java index 0592e56288f..9dee92a80e6 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/preferences/WizardPreferencesPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/wizards/preferences/WizardPreferencesPage.java @@ -793,10 +793,11 @@ protected void restoreWidgetValues() { if (shouldSaveTransferAll() && settings != null) { boolean transferAll; - if (settings.get(TRANSFER_ALL_PREFERENCES_ID) == null) + if (settings.get(TRANSFER_ALL_PREFERENCES_ID) == null) { transferAll = true; - else + } else { transferAll = settings.getBoolean(TRANSFER_ALL_PREFERENCES_ID); + } transferAllButton.setSelection(transferAll); if (!transferAll) { String[] preferenceIds = settings.getArray(TRANSFER_PREFERENCES_NAMES_ID); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/KeySequence.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/KeySequence.java index 70addd831c9..235e4a73045 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/KeySequence.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/KeySequence.java @@ -210,7 +210,7 @@ public static KeySequence getInstance(String string) throws ParseException { /** * The list of key strokes for this key sequence. */ - private List keyStrokes; + private final List keyStrokes; /** * Constructs an instance of KeySequence given a list of key diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/KeyStroke.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/KeyStroke.java index b8392331d60..199e669491e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/KeyStroke.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/KeyStroke.java @@ -215,7 +215,7 @@ public static KeyStroke getInstance(String string) throws ParseException { /** * The set of modifier keys for this key stroke. */ - private SortedSet modifierKeys; + private final SortedSet modifierKeys; /** * The set of modifier keys for this key stroke in the form of an array. Used @@ -226,7 +226,7 @@ public static KeyStroke getInstance(String string) throws ParseException { /** * The natural key for this key stroke. */ - private NaturalKey naturalKey; + private final NaturalKey naturalKey; /** * Constructs an instance of KeyStroke given a set of modifier keys @@ -261,12 +261,10 @@ public int compareTo(Object object) { @Override public boolean equals(Object object) { - if (!(object instanceof KeyStroke)) { + if (!(object instanceof KeyStroke castedObject)) { return false; } - KeyStroke castedObject = (KeyStroke) object; - if (!modifierKeys.equals(castedObject.modifierKeys)) { return false; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/SWTKeySupport.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/SWTKeySupport.java index 3870ece6b7d..5618c6f3c8c 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/SWTKeySupport.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/keys/SWTKeySupport.java @@ -336,9 +336,7 @@ public static int convertKeyStrokeToAccelerator(final KeyStroke keyStroke) { if (naturalKey instanceof CharacterKey) { accelerator |= ((CharacterKey) naturalKey).getCharacter(); - } else if (naturalKey instanceof SpecialKey) { - final SpecialKey specialKey = (SpecialKey) naturalKey; - + } else if (naturalKey instanceof final SpecialKey specialKey) { if (specialKey == SpecialKey.ARROW_DOWN) { accelerator |= SWT.ARROW_DOWN; } else if (specialKey == SpecialKey.ARROW_LEFT) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/AbstractContributionFactory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/AbstractContributionFactory.java index f0555ec0db1..c777a823d26 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/AbstractContributionFactory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/AbstractContributionFactory.java @@ -61,7 +61,7 @@ */ public abstract class AbstractContributionFactory { private String location = null; - private String namespace; + private final String namespace; /** * The contribution factories must be instantiated with their location, which diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/CommandContributionItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/CommandContributionItem.java index f2e6b39106b..5fdbaa986e8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/CommandContributionItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/CommandContributionItem.java @@ -139,13 +139,13 @@ public class CommandContributionItem extends ContributionItem { private ImageDescriptor hoverIcon; - private String mnemonic; + private final String mnemonic; private IElementReference elementRef; private boolean checkedState; - private int style; + private final int style; private ICommandListener commandListener; @@ -161,14 +161,14 @@ public class CommandContributionItem extends ContributionItem { * This is true when the menu contribution's visibleWhen * checkEnabled attribute is true. */ - private boolean visibleEnabled; + private final boolean visibleEnabled; - private Display display; + private final Display display; // items contributed - private String contributedLabel; + private final String contributedLabel; - private String contributedTooltip; + private final String contributedTooltip; private ImageDescriptor contributedIcon; @@ -279,12 +279,15 @@ private void setImages(IServiceLocator locator, String iconStyle) { disabledIcon = service.getImageDescriptor(command.getId(), ICommandImageService.TYPE_DISABLED, iconStyle); hoverIcon = service.getImageDescriptor(command.getId(), ICommandImageService.TYPE_HOVER, iconStyle); - if (contributedIcon == null) + if (contributedIcon == null) { contributedIcon = icon; - if (contributedDisabledIcon == null) + } + if (contributedDisabledIcon == null) { contributedDisabledIcon = disabledIcon; - if (contributedHoverIcon == null) + } + if (contributedHoverIcon == null) { contributedHoverIcon = hoverIcon; + } } } @@ -336,15 +339,16 @@ private boolean shouldRestoreAppearance(IHandler handler) { // if no handler or handler doesn't implement IElementUpdater, // restore the contributed elements - if (handler == null) + if (handler == null) { return true; + } - if (!(handler instanceof IElementUpdater)) + if (!(handler instanceof IElementUpdater)) { return true; + } // special case, if its HandlerProxy, then check the actual handler - if (handler instanceof HandlerProxy) { - HandlerProxy handlerProxy = (HandlerProxy) handler; + if (handler instanceof HandlerProxy handlerProxy) { IHandler actualHandler = handlerProxy.getHandler(); return shouldRestoreAppearance(actualHandler); } @@ -394,8 +398,9 @@ public void fill(Menu parent, int index) { // Menus don't support the pulldown style int tmpStyle = style; - if (tmpStyle == STYLE_PULLDOWN) + if (tmpStyle == STYLE_PULLDOWN) { tmpStyle = STYLE_PUSH; + } MenuItem item = null; if (index >= 0) { @@ -428,8 +433,9 @@ public void fill(Composite parent) { // Buttons don't support the pulldown style int tmpStyle = style; - if (tmpStyle == STYLE_PULLDOWN) + if (tmpStyle == STYLE_PULLDOWN) { tmpStyle = STYLE_PUSH; + } Button item = new Button(parent, tmpStyle); item.setData(this); @@ -627,11 +633,13 @@ private void updateButton() { private String getToolTipText(String text) { String tooltipText = tooltip; - if (tooltip == null) - if (text != null) + if (tooltip == null) { + if (text != null) { tooltipText = text; - else + } else { tooltipText = ""; //$NON-NLS-1$ + } + } TriggerSequence activeBinding = bindingService.getBestActiveBindingFor(command); if (activeBinding != null && !activeBinding.isEmpty()) { @@ -669,8 +677,9 @@ private void handleWidgetDispose(Event event) { @Override public void setParent(IContributionManager parent) { super.setParent(parent); - if (parent == null) + if (parent == null) { disconnectReferences(); + } } private void establishReferences() { @@ -786,8 +795,9 @@ private Listener getItemListener() { private void handleWidgetSelection(Event event) { // Special check for ToolBar dropdowns... - if (openDropDownMenu(event)) + if (openDropDownMenu(event)) { return; + } if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) { if (event.widget instanceof ToolItem) { @@ -867,8 +877,7 @@ private void setIcon(ImageDescriptor desc) { } private void updateIcons() { - if (widget instanceof MenuItem) { - MenuItem item = (MenuItem) widget; + if (widget instanceof MenuItem item) { LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources()); try { item.setImage(icon == null ? null : m.create(icon)); @@ -881,8 +890,7 @@ private void updateIcons() { } disposeOldImages(); localResourceManager = m; - } else if (widget instanceof ToolItem) { - ToolItem item = (ToolItem) widget; + } else if (widget instanceof ToolItem item) { LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources()); item.setDisabledImage(disabledIcon == null ? null : m.create(disabledIcon)); item.setHotImage(hoverIcon == null ? null : m.create(hoverIcon)); @@ -946,7 +954,7 @@ public boolean isVisible() { return super.isVisible(); } - private IBindingManagerListener bindingManagerListener = event -> { + private final IBindingManagerListener bindingManagerListener = event -> { if (event.isActiveBindingsChanged() && event.isActiveBindingsChangedFor(getCommand())) { update(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/UIElement.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/UIElement.java index 371bafe78e4..886b4bd46b9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/UIElement.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/UIElement.java @@ -32,7 +32,7 @@ */ public abstract class UIElement { - private IServiceLocator serviceLocator; + private final IServiceLocator serviceLocator; /** * Construct a new instance of this class keyed off of the provided service @@ -41,8 +41,9 @@ public abstract class UIElement { * @param serviceLocator the locator. May not be null. */ protected UIElement(IServiceLocator serviceLocator) throws IllegalArgumentException { - if (serviceLocator == null) + if (serviceLocator == null) { throw new IllegalArgumentException(); + } this.serviceLocator = serviceLocator; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/WorkbenchWindowControlContribution.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/WorkbenchWindowControlContribution.java index d9f3513ca72..99b307148a6 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/WorkbenchWindowControlContribution.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/WorkbenchWindowControlContribution.java @@ -81,8 +81,9 @@ public final int getCurSide() { @Override public final int getOrientation() { - if (getCurSide() == SWT.LEFT || getCurSide() == SWT.RIGHT) + if (getCurSide() == SWT.LEFT || getCurSide() == SWT.RIGHT) { return SWT.VERTICAL; + } return SWT.HORIZONTAL; } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/ContributionComparator.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/ContributionComparator.java index 7a293b624fc..38f091fe04d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/ContributionComparator.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/ContributionComparator.java @@ -47,11 +47,13 @@ public class ContributionComparator extends ViewerComparator implements Comparat public int compare(Object o1, Object o2) { IComparableContribution c1 = null, c2 = null; - if (o1 instanceof IComparableContribution) + if (o1 instanceof IComparableContribution) { c1 = (IComparableContribution) o1; + } - if (o2 instanceof IComparableContribution) + if (o2 instanceof IComparableContribution) { c2 = (IComparableContribution) o2; + } // neither are comparable contributions, we need to be consistent if (c1 == null && c2 == null) { @@ -62,10 +64,12 @@ public int compare(Object o1, Object o2) { } // if we're in a mixed scenario the comparable contribution wins. - if (c1 == null) + if (c1 == null) { return 1; - if (c2 == null) + } + if (c2 == null) { return -1; + } return compare(c1, c2); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/PerspectiveLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/PerspectiveLabelProvider.java index 78b2387769e..d73e7dd5a3a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/PerspectiveLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/PerspectiveLabelProvider.java @@ -41,12 +41,12 @@ public final class PerspectiveLabelProvider extends LabelProvider implements ITa /** * List of all Image objects this label provider is responsible for. */ - private HashMap imageCache = new HashMap<>(5); + private final HashMap imageCache = new HashMap<>(5); /** * Indicates whether the default perspective is visually marked. */ - private boolean markDefault; + private final boolean markDefault; /** * Creates a new label provider for perspectives. The default perspective is @@ -70,8 +70,7 @@ public PerspectiveLabelProvider(boolean markDefault) { @Override public Image getImage(Object element) { - if (element instanceof IPerspectiveDescriptor) { - IPerspectiveDescriptor desc = (IPerspectiveDescriptor) element; + if (element instanceof IPerspectiveDescriptor desc) { ImageDescriptor imageDescriptor = desc.getImageDescriptor(); if (imageDescriptor == null) { imageDescriptor = WorkbenchImages.getImageDescriptor(ISharedImages.IMG_ETOOL_DEF_PERSPECTIVE); @@ -96,8 +95,7 @@ public void dispose() { @Override public String getText(Object element) { - if (element instanceof IPerspectiveDescriptor) { - IPerspectiveDescriptor desc = (IPerspectiveDescriptor) element; + if (element instanceof IPerspectiveDescriptor desc) { String label = desc.getLabel(); if (markDefault) { String def = PlatformUI.getWorkbench().getPerspectiveRegistry().getDefaultPerspective(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/WorkbenchLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/WorkbenchLabelProvider.java index 1f2bea462ef..f37396a31c8 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/WorkbenchLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/WorkbenchLabelProvider.java @@ -67,7 +67,7 @@ public static ILabelProvider getDecoratingWorkbenchLabelProvider() { * when it changes, since many workbench adapters derive their icon from the * file associations in the registry. */ - private IPropertyListener editorRegistryListener = (source, propId) -> { + private final IPropertyListener editorRegistryListener = (source, propId) -> { if (propId == IEditorRegistry.PROP_CONTENTS) { fireLabelProviderChanged(new LabelProviderChangedEvent(WorkbenchLabelProvider.this)); } @@ -114,8 +114,9 @@ protected String decorateText(String input, Object element) { @Override public void dispose() { PlatformUI.getWorkbench().getEditorRegistry().removePropertyListener(editorRegistryListener); - if (resourceManager != null) + if (resourceManager != null) { resourceManager.dispose(); + } resourceManager = null; super.dispose(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/WorkbenchPartLabelProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/WorkbenchPartLabelProvider.java index 0d7b5f75b79..329099fd4e3 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/WorkbenchPartLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/model/WorkbenchPartLabelProvider.java @@ -39,8 +39,8 @@ */ public final class WorkbenchPartLabelProvider extends LabelProvider implements ITableLabelProvider { - private ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources()); - private HashMap images = new HashMap(); + private final ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources()); + private final HashMap images = new HashMap(); /** * Creates a new label provider for workbench parts. @@ -54,8 +54,7 @@ public Image getImage(Object element) { if (element instanceof IWorkbenchPart) { return ((IWorkbenchPart) element).getTitleImage(); } - if (element instanceof Saveable) { - Saveable model = (Saveable) element; + if (element instanceof Saveable model) { ImageDescriptor imageDesc = model.getImageDescriptor(); // convert from ImageDescriptor to Image if (imageDesc == null) { @@ -77,16 +76,14 @@ public Image getImage(Object element) { @Override public String getText(Object element) { - if (element instanceof IWorkbenchPart) { - IWorkbenchPart part = (IWorkbenchPart) element; + if (element instanceof IWorkbenchPart part) { String path = part.getTitleToolTip(); if (path == null || path.trim().isEmpty()) { return part.getTitle(); } return part.getTitle() + " [" + path + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } - if (element instanceof Saveable) { - Saveable model = (Saveable) element; + if (element instanceof Saveable model) { String path = model.getToolTipText(); if (path == null || path.trim().isEmpty()) { return model.getName(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/LinearUndoViolationUserApprover.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/LinearUndoViolationUserApprover.java index d1db420c1f0..0dba67d4191 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/LinearUndoViolationUserApprover.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/LinearUndoViolationUserApprover.java @@ -43,9 +43,9 @@ */ public final class LinearUndoViolationUserApprover extends LinearUndoViolationDetector { - private IWorkbenchPart part; + private final IWorkbenchPart part; - private IUndoContext context; + private final IUndoContext context; /** * Create a LinearUndoViolationUserApprover associated with the specified diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/NonLocalUndoUserApprover.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/NonLocalUndoUserApprover.java index 5dc8e8d9f6e..587474fd548 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/NonLocalUndoUserApprover.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/NonLocalUndoUserApprover.java @@ -57,13 +57,13 @@ */ public final class NonLocalUndoUserApprover implements IOperationApprover { - private IUndoContext context; + private final IUndoContext context; - private IEditorPart part; + private final IEditorPart part; - private Object[] elements; + private final Object[] elements; - private Class affectedObjectsClass; + private final Class affectedObjectsClass; private ArrayList elementsAndAdapters; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/OperationHistoryActionHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/OperationHistoryActionHandler.java index 26e64802cfa..bc268c549b9 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/OperationHistoryActionHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/OperationHistoryActionHandler.java @@ -135,12 +135,14 @@ private class HistoryListener implements IOperationHistoryListener { @Override public void historyNotification(final OperationHistoryEvent event) { IWorkbenchWindow workbenchWindow = getWorkbenchWindow(); - if (workbenchWindow == null) + if (workbenchWindow == null) { return; + } Display display = workbenchWindow.getWorkbench().getDisplay(); - if (display == null) + if (display == null) { return; + } switch (event.getEventType()) { case OperationHistoryEvent.OPERATION_ADDED: @@ -183,9 +185,9 @@ public void historyNotification(final OperationHistoryEvent event) { private boolean pruning = false; - private IPartListener partListener = new PartListener(); + private final IPartListener partListener = new PartListener(); - private IOperationHistoryListener historyListener = new HistoryListener(); + private final IOperationHistoryListener historyListener = new HistoryListener(); private TimeTriggeredProgressMonitorDialog progressDialog; @@ -313,8 +315,8 @@ public final void run() { && schedulableOperation instanceof TriggeredOperations) { schedulableOperation = ((TriggeredOperations) schedulableOperation).getTriggeringOperation(); } - final ISchedulingRule rule = (schedulableOperation instanceof ISchedulableOperation) - ? ((ISchedulableOperation) schedulableOperation).getSchedulingRule() + final ISchedulingRule rule = (schedulableOperation instanceof ISchedulableOperation i) + ? i.getSchedulingRule() : null; if (rule == null) { progressDialog.run(runInBackground, true, runnable); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/UndoRedoActionGroup.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/UndoRedoActionGroup.java index ae9839ae9c0..1bd740aa2fa 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/UndoRedoActionGroup.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/operations/UndoRedoActionGroup.java @@ -32,9 +32,9 @@ */ public final class UndoRedoActionGroup extends ActionGroup { - private UndoActionHandler undoActionHandler; + private final UndoActionHandler undoActionHandler; - private RedoActionHandler redoActionHandler; + private final RedoActionHandler redoActionHandler; /** * Construct an undo redo action group for the specified workbench part site, diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/CellEditorActionHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/CellEditorActionHandler.java index 5a323ef4f9b..246f4cd90aa 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/CellEditorActionHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/CellEditorActionHandler.java @@ -52,21 +52,21 @@ * @noextend This class is not intended to be subclassed by clients. */ public class CellEditorActionHandler { - private CutActionHandler cellCutAction = new CutActionHandler(); + private final CutActionHandler cellCutAction = new CutActionHandler(); - private CopyActionHandler cellCopyAction = new CopyActionHandler(); + private final CopyActionHandler cellCopyAction = new CopyActionHandler(); - private PasteActionHandler cellPasteAction = new PasteActionHandler(); + private final PasteActionHandler cellPasteAction = new PasteActionHandler(); - private DeleteActionHandler cellDeleteAction = new DeleteActionHandler(); + private final DeleteActionHandler cellDeleteAction = new DeleteActionHandler(); - private SelectAllActionHandler cellSelectAllAction = new SelectAllActionHandler(); + private final SelectAllActionHandler cellSelectAllAction = new SelectAllActionHandler(); - private FindActionHandler cellFindAction = new FindActionHandler(); + private final FindActionHandler cellFindAction = new FindActionHandler(); - private UndoActionHandler cellUndoAction = new UndoActionHandler(); + private final UndoActionHandler cellUndoAction = new UndoActionHandler(); - private RedoActionHandler cellRedoAction = new RedoActionHandler(); + private final RedoActionHandler cellRedoAction = new RedoActionHandler(); private IAction cutAction; @@ -84,29 +84,29 @@ public class CellEditorActionHandler { private IAction redoAction; - private IPropertyChangeListener cutActionListener = new ActionEnabledChangeListener(cellCutAction); + private final IPropertyChangeListener cutActionListener = new ActionEnabledChangeListener(cellCutAction); - private IPropertyChangeListener copyActionListener = new ActionEnabledChangeListener(cellCopyAction); + private final IPropertyChangeListener copyActionListener = new ActionEnabledChangeListener(cellCopyAction); - private IPropertyChangeListener pasteActionListener = new ActionEnabledChangeListener(cellPasteAction); + private final IPropertyChangeListener pasteActionListener = new ActionEnabledChangeListener(cellPasteAction); - private IPropertyChangeListener deleteActionListener = new ActionEnabledChangeListener(cellDeleteAction); + private final IPropertyChangeListener deleteActionListener = new ActionEnabledChangeListener(cellDeleteAction); - private IPropertyChangeListener selectAllActionListener = new ActionEnabledChangeListener(cellSelectAllAction); + private final IPropertyChangeListener selectAllActionListener = new ActionEnabledChangeListener(cellSelectAllAction); - private IPropertyChangeListener findActionListener = new ActionEnabledChangeListener(cellFindAction); + private final IPropertyChangeListener findActionListener = new ActionEnabledChangeListener(cellFindAction); - private IPropertyChangeListener undoActionListener = new ActionEnabledChangeListener(cellUndoAction); + private final IPropertyChangeListener undoActionListener = new ActionEnabledChangeListener(cellUndoAction); - private IPropertyChangeListener redoActionListener = new ActionEnabledChangeListener(cellRedoAction); + private final IPropertyChangeListener redoActionListener = new ActionEnabledChangeListener(cellRedoAction); private CellEditor activeEditor; - private IPropertyChangeListener cellListener = new CellChangeListener(); + private final IPropertyChangeListener cellListener = new CellChangeListener(); - private Listener controlListener = new ControlListener(); + private final Listener controlListener = new ControlListener(); - private HashMap controlToEditor = new HashMap<>(); + private final HashMap controlToEditor = new HashMap<>(); private class ControlListener implements Listener { @Override @@ -133,7 +133,7 @@ public void handleEvent(Event event) { } private class ActionEnabledChangeListener implements IPropertyChangeListener { - private IAction actionHandler; + private final IAction actionHandler; protected ActionEnabledChangeListener(IAction actionHandler) { super(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/DrillDownAdapter.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/DrillDownAdapter.java index a528d1a2d27..ace963c8710 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/DrillDownAdapter.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/DrillDownAdapter.java @@ -49,9 +49,9 @@ *

*/ public class DrillDownAdapter implements ISelectionChangedListener { - private TreeViewer fChildTree; + private final TreeViewer fChildTree; - private DrillStack fDrillStack; + private final DrillStack fDrillStack; private Action homeAction; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/DrillFrame.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/DrillFrame.java index 926a025b19c..9d5fa74153b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/DrillFrame.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/DrillFrame.java @@ -56,12 +56,11 @@ public boolean equals(Object obj) { } // Compare class. - if (!(obj instanceof DrillFrame)) { + if (!(obj instanceof DrillFrame oOther)) { return false; } // Compare contents. - DrillFrame oOther = (DrillFrame) obj; return ((fElement == oOther.fElement) && (fPropertyName.equals(oOther.fPropertyName))); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/EditorInputTransfer.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/EditorInputTransfer.java index 4f6ff24865f..7ccf345973e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/EditorInputTransfer.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/EditorInputTransfer.java @@ -135,11 +135,11 @@ protected String[] getTypeNames() { @Override public void javaToNative(Object data, TransferData transferData) { - if (!(data instanceof EditorInputData[])) { + if (!(data instanceof EditorInputData[] editorInputs)) { return; } - EditorInputData[] editorInputs = (EditorInputData[]) data; + /** * The editor input serialization format is: (int) number of editor inputs Then, * the following for each editor input: (String) editorId (String) factoryId diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/IntroPart.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/IntroPart.java index 93cfd320434..e72888b986b 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/IntroPart.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/IntroPart.java @@ -277,8 +277,9 @@ protected void setTitleImage(Image titleImage) { */ protected void setTitle(String titleLabel) { Assert.isNotNull(titleLabel); - if (Objects.equals(this.titleLabel, titleLabel)) + if (Objects.equals(this.titleLabel, titleLabel)) { return; + } this.titleLabel = titleLabel; firePropertyChange(IIntroPart.PROP_TITLE); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiEditorInput.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiEditorInput.java index 5852043abc9..3e915dd4912 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiEditorInput.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiEditorInput.java @@ -109,10 +109,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (!(obj instanceof MultiEditorInput)) { + if (!(obj instanceof MultiEditorInput other)) { return false; } - MultiEditorInput other = (MultiEditorInput) obj; return Arrays.equals(this.editors, other.editors) && Arrays.equals(this.input, other.input); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageEditorPart.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageEditorPart.java index 68ecd674ead..cc415b94423 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageEditorPart.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageEditorPart.java @@ -145,13 +145,13 @@ public abstract class MultiPageEditorPart extends EditorPart implements IPageCha * here, in addition to using get/setData on the items, because dispose() needs * to access them, but widgetry has already been disposed at that point. */ - private ArrayList nestedEditors = new ArrayList<>(3); + private final ArrayList nestedEditors = new ArrayList<>(3); - private List pageSites = new ArrayList<>(3); + private final List pageSites = new ArrayList<>(3); private IServiceLocator pageContainerSite; - private ListenerList pageChangeListeners = new ListenerList<>(ListenerList.IDENTITY); + private final ListenerList pageChangeListeners = new ListenerList<>(ListenerList.IDENTITY); private org.eclipse.jface.util.IPropertyChangeListener propertyChangeListenerToUpdateContainer; @@ -307,12 +307,15 @@ protected CTabFolder createContainer(Composite parent) { e.detail = SWT.TRAVERSE_NONE; Control control = newContainer.getParent(); do { - if (control.traverse(detail)) + if (control.traverse(detail)) { return; - if (control.getListeners(SWT.Traverse).length != 0) + } + if (control.getListeners(SWT.Traverse).length != 0) { return; - if (control instanceof Shell) + } + if (control instanceof Shell) { return; + } control = control.getParent(); } while (control != null); } @@ -425,8 +428,9 @@ public String getName(Object page) { @Override public ImageDescriptor getImageDescriptor(Object page) { Image image = getPageImage(((Integer) page).intValue()); - if (image == null) + if (image == null) { return null; + } return ImageDescriptor.createFromImage(image); } @@ -459,12 +463,14 @@ private void initializeSubTabSwitching() { @Override public Object execute(ExecutionEvent event) throws ExecutionException { int n = getPageCount(); - if (n == 0) + if (n == 0) { return null; + } int i = getActivePage() + 1; - if (i >= n) + if (i >= n) { i = 0; + } setActivePage(i); return null; } @@ -479,12 +485,14 @@ public Object execute(ExecutionEvent event) throws ExecutionException { @Override public Object execute(ExecutionEvent event) throws ExecutionException { int n = getPageCount(); - if (n == 0) + if (n == 0) { return null; + } int i = getActivePage() - 1; - if (i < 0) + if (i < 0) { i = n - 1; + } setActivePage(i); return null; } @@ -867,11 +875,10 @@ protected void pageChange(int newPageIndex) { ISelectionProvider selectionProvider = activeEditor.getSite().getSelectionProvider(); if (selectionProvider != null) { ISelectionProvider outerProvider = getSite().getSelectionProvider(); - if (outerProvider instanceof MultiPageSelectionProvider) { + if (outerProvider instanceof MultiPageSelectionProvider provider) { SelectionChangedEvent event = new SelectionChangedEvent(selectionProvider, selectionProvider.getSelection()); - MultiPageSelectionProvider provider = (MultiPageSelectionProvider) outerProvider; provider.fireSelectionChanged(event); provider.firePostSelectionChanged(event); } else if (Policy.DEBUG_MPE) { @@ -923,8 +930,7 @@ protected final void deactivateSite(boolean immediate, boolean containerSiteActi final IKeyBindingService service = getSite().getKeyBindingService(); if (pageIndex < 0 || pageIndex >= getPageCount() || immediate) { // There is no selected page, so deactivate the active service. - if (service instanceof INestableKeyBindingService) { - final INestableKeyBindingService nestableService = (INestableKeyBindingService) service; + if (service instanceof final INestableKeyBindingService nestableService) { nestableService.activateKeyBindingService(null); } else { WorkbenchPlugin.log( @@ -972,8 +978,7 @@ protected final void activateSite() { if (editor != null) { // active the service for this inner editor - if (service instanceof INestableKeyBindingService) { - final INestableKeyBindingService nestableService = (INestableKeyBindingService) service; + if (service instanceof final INestableKeyBindingService nestableService) { nestableService.activateKeyBindingService(editor.getEditorSite()); } else { @@ -992,8 +997,7 @@ protected final void activateSite() { Item item = getItem(pageIndex); // There is no selected editor, so deactivate the active service. - if (service instanceof INestableKeyBindingService) { - final INestableKeyBindingService nestableService = (INestableKeyBindingService) service; + if (service instanceof final INestableKeyBindingService nestableService) { nestableService.activateKeyBindingService(null); } else { WorkbenchPlugin.log( diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageEditorSite.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageEditorSite.java index c79f7fcfa2f..d9511444811 100755 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageEditorSite.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageEditorSite.java @@ -224,8 +224,7 @@ public void dispose() { // Remove myself from the list of nested key binding services. if (service != null) { IKeyBindingService parentService = getMultiPageEditor().getEditorSite().getKeyBindingService(); - if (parentService instanceof INestableKeyBindingService) { - INestableKeyBindingService nestableParent = (INestableKeyBindingService) parentService; + if (parentService instanceof INestableKeyBindingService nestableParent) { nestableParent.removeKeyBindingService(this); } if (service instanceof KeyBindingService) { @@ -311,8 +310,7 @@ public String getId() { public IKeyBindingService getKeyBindingService() { if (service == null) { service = getMultiPageEditor().getEditorSite().getKeyBindingService(); - if (service instanceof INestableKeyBindingService) { - INestableKeyBindingService nestableService = (INestableKeyBindingService) service; + if (service instanceof INestableKeyBindingService nestableService) { service = nestableService.getKeyBindingService(this); } else { @@ -469,9 +467,8 @@ protected IWorkbenchPartSite getNestedEditorSite() { */ protected void handlePostSelectionChanged(SelectionChangedEvent event) { ISelectionProvider parentProvider = getNestedEditorSite().getSelectionProvider(); - if (parentProvider instanceof MultiPageSelectionProvider) { + if (parentProvider instanceof MultiPageSelectionProvider prov) { SelectionChangedEvent newEvent = new SelectionChangedEvent(parentProvider, event.getSelection()); - MultiPageSelectionProvider prov = (MultiPageSelectionProvider) parentProvider; prov.firePostSelectionChanged(newEvent); } } @@ -489,9 +486,8 @@ protected void handlePostSelectionChanged(SelectionChangedEvent event) { */ protected void handleSelectionChanged(SelectionChangedEvent event) { ISelectionProvider parentProvider = getNestedEditorSite().getSelectionProvider(); - if (parentProvider instanceof MultiPageSelectionProvider) { + if (parentProvider instanceof MultiPageSelectionProvider prov) { SelectionChangedEvent newEvent = new SelectionChangedEvent(parentProvider, event.getSelection()); - MultiPageSelectionProvider prov = (MultiPageSelectionProvider) parentProvider; prov.fireSelectionChanged(newEvent); } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageSelectionProvider.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageSelectionProvider.java index a9146add70f..232288e4586 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageSelectionProvider.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/MultiPageSelectionProvider.java @@ -43,17 +43,17 @@ public class MultiPageSelectionProvider implements IPostSelectionProvider { * Registered selection changed listeners (element type: * ISelectionChangedListener). */ - private ListenerList listeners = new ListenerList<>(); + private final ListenerList listeners = new ListenerList<>(); /** * Registered post selection changed listeners. */ - private ListenerList postListeners = new ListenerList<>(); + private final ListenerList postListeners = new ListenerList<>(); /** * The multi-page editor. */ - private MultiPageEditorPart multiPageEditor; + private final MultiPageEditorPart multiPageEditor; /** * Creates a selection provider for the given multi-page editor. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/PageBookView.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/PageBookView.java index e06f6f5aef3..78759a84805 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/PageBookView.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/PageBookView.java @@ -147,7 +147,7 @@ public abstract class PageBookView extends ViewPart implements IPartListener { /** * The action bar property listener. */ - private IPropertyChangeListener actionBarPropListener = event -> { + private final IPropertyChangeListener actionBarPropListener = event -> { if (event.getProperty().equals(SubActionBars.P_ACTION_HANDLERS) && activeRec != null && event.getSource() == activeRec.subActionBars) { refreshGlobalActionHandlers(); @@ -157,17 +157,17 @@ public abstract class PageBookView extends ViewPart implements IPartListener { /** * Selection change listener to listen for page selection changes */ - private ISelectionChangedListener selectionChangedListener = this::pageSelectionChanged; + private final ISelectionChangedListener selectionChangedListener = this::pageSelectionChanged; /** * Selection change listener to listen for page selection changes */ - private ISelectionChangedListener postSelectionListener = this::postSelectionChanged; + private final ISelectionChangedListener postSelectionListener = this::postSelectionChanged; /** * Selection provider for this view's site */ - private SelectionProvider selectionProvider = new SelectionProvider(); + private final SelectionProvider selectionProvider = new SelectionProvider(); /** * A data structure used to store the information about a single page within a @@ -252,9 +252,9 @@ public void run() { */ protected class SelectionProvider implements IPostSelectionProvider { - private SelectionManager fSelectionListener = new SelectionManager(); + private final SelectionManager fSelectionListener = new SelectionManager(); - private SelectionManager fPostSelectionListeners = new SelectionManager(); + private final SelectionManager fPostSelectionListeners = new SelectionManager(); @Override public void addSelectionChangedListener(ISelectionChangedListener listener) { @@ -987,7 +987,7 @@ protected SelectionProvider getSelectionProvider() { return selectionProvider; } - private IPartListener2 partListener = new IPartListener2() { + private final IPartListener2 partListener = new IPartListener2() { @Override public void partActivated(IWorkbenchPartReference partRef) { if (partRef == null) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/PageSite.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/PageSite.java index 4e973deb0b8..02dbc36b6de 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/PageSite.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/PageSite.java @@ -59,7 +59,7 @@ public class PageSite implements IPageSite, INestable { /** * The "parent" view site */ - private IViewSite parentSite; + private final IViewSite parentSite; /** * A selection provider set by the page. Value is null until set. @@ -75,9 +75,9 @@ public class PageSite implements IPageSite, INestable { /** * The action bars for this site */ - private SubActionBars subActionBars; + private final SubActionBars subActionBars; - private IEclipseContext e4Context; + private final IEclipseContext e4Context; private NestableContextService contextService; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/WorkbenchPart.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/WorkbenchPart.java index 19bc7d378e6..e50a3844858 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/WorkbenchPart.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/part/WorkbenchPart.java @@ -78,7 +78,7 @@ public abstract class WorkbenchPart extends EventManager private String contentDescription = ""; //$NON-NLS-1$ - private ListenerList partChangeListeners = new ListenerList<>(); + private final ListenerList partChangeListeners = new ListenerList<>(); /** * Creates a new workbench part. @@ -421,8 +421,7 @@ void internalSetContentDescription(String description) { } this.contentDescription = description; - if (partSite instanceof PartSite) { - PartSite site = (PartSite) partSite; + if (partSite instanceof PartSite site) { ContributedPartRenderer.setDescription(site.getModel(), description); } firePropertyChange(IWorkbenchPartConstants.PROP_CONTENT_DESCRIPTION); @@ -473,7 +472,7 @@ protected void firePartPropertyChanged(String key, String oldValue, String newVa } } - private Map partProperties = new HashMap<>(); + private final Map partProperties = new HashMap<>(); @Override public void setPartProperty(String key, String value) { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/plugin/AbstractUIPlugin.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/plugin/AbstractUIPlugin.java index 8c3b5e0a00c..fa809e76b46 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/plugin/AbstractUIPlugin.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/plugin/AbstractUIPlugin.java @@ -547,8 +547,9 @@ public void stop(BundleContext context) throws Exception { // saveDialogSettings(); -> now done by DialogSettingsProvider savePreferenceStore(); preferenceStore = null; - if (imageRegistry != null) + if (imageRegistry != null) { imageRegistry.dispose(); + } imageRegistry = null; } finally { super.stop(context); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/ScopedPreferenceStore.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/ScopedPreferenceStore.java index 42a3cb7269a..65ffaf9f820 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/ScopedPreferenceStore.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/ScopedPreferenceStore.java @@ -58,7 +58,7 @@ public class ScopedPreferenceStore extends EventManager implements IPreferenceSt * methods. If there are no searchContexts this will be the search context. * (along with the "default" context) */ - private IScopeContext storeContext; + private final IScopeContext storeContext; /** * The searchContext is the array of contexts that will be used by the get @@ -81,7 +81,7 @@ public class ScopedPreferenceStore extends EventManager implements IPreferenceSt * The default context is the context where getDefault and setDefault methods * will search. This context is also used in the search. */ - private IScopeContext defaultContext = DefaultScope.INSTANCE; + private final IScopeContext defaultContext = DefaultScope.INSTANCE; /** * The nodeQualifer is the string used to look up the node in the contexts. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/WizardPropertyPage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/WizardPropertyPage.java index 36e2d08f23b..9701749984d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/WizardPropertyPage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/WizardPropertyPage.java @@ -77,18 +77,19 @@ public void updateMessage() { IWizardPage page = getCurrentPage(); String message = fPage.getMessage(); - if (message != null && fMessage == null) + if (message != null && fMessage == null) { fMessage = message; + } if (page.getErrorMessage() != null) { fPage.setMessage(page.getErrorMessage(), ERROR); - } else if (page instanceof IMessageProvider) { - IMessageProvider messageProvider = (IMessageProvider) page; + } else if (page instanceof IMessageProvider messageProvider) { if (messageProvider.getMessageType() != IMessageProvider.NONE) { fPage.setMessage(messageProvider.getMessage(), messageProvider.getMessageType()); } else { - if (messageProvider.getMessage() != null && fMessage == null) + if (messageProvider.getMessage() != null && fMessage == null) { fMessage = messageProvider.getMessage(); + } fPage.setMessage(fMessage, NONE); } @@ -101,8 +102,9 @@ public void updateMessage() { public void updateTitleBar() { IWizardPage page = getCurrentPage(); String name = page.getTitle(); - if (name == null) + if (name == null) { name = page.getName(); + } fPage.setMessage(name); } @@ -166,8 +168,9 @@ protected Control createContents(final Composite parent) { private void createWizardPageContent(Composite parent) { fWizard = createWizard(); - if (fWizard == null) + if (fWizard == null) { return; + } fWizard.addPages(); @@ -190,8 +193,9 @@ private void createWizardPageContent(Composite parent) { fWizard.createPageControls(parent); IWizardPage page = fWizard.getPages()[0]; - if (page.getControl() == null) + if (page.getControl() == null) { page.createControl(parent); + } Control pageControl = page.getControl(); pageControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); @@ -206,8 +210,9 @@ private void createWizardPageContent(Composite parent) { private void setPageName(IWizardPage page) { String name = page.getTitle(); - if (name == null) + if (name == null) { name = page.getName(); + } setMessage(name); } @@ -216,8 +221,7 @@ private void setDescription(IWizardPage page, Label messageLabel) { String description = null; if (page.getDescription() != null) { description = page.getDescription(); - } else if (page instanceof IMessageProvider) { - IMessageProvider messageProvider = (IMessageProvider) page; + } else if (page instanceof IMessageProvider messageProvider) { if (messageProvider.getMessageType() == IMessageProvider.NONE) { description = messageProvider.getMessage(); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/WorkingCopyManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/WorkingCopyManager.java index d0fcec55033..b5a22bff4ae 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/WorkingCopyManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/preferences/WorkingCopyManager.java @@ -33,7 +33,7 @@ public class WorkingCopyManager implements IWorkingCopyManager { private static final String EMPTY_STRING = "";//$NON-NLS-1$ // all working copies - maps absolute path to PreferencesWorkingCopy instance - private Map workingCopies = new HashMap<>(); + private final Map workingCopies = new HashMap<>(); @Override public IEclipsePreferences getWorkingCopy(IEclipsePreferences original) { @@ -54,8 +54,9 @@ public void applyChanges() throws BackingStoreException { Collection values = workingCopies.values(); WorkingCopyPreferences[] valuesArray = values.toArray(new WorkingCopyPreferences[values.size()]); for (WorkingCopyPreferences prefs : valuesArray) { - if (prefs.nodeExists(EMPTY_STRING)) + if (prefs.nodeExists(EMPTY_STRING)) { prefs.flush(); + } } } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/progress/DeferredTreeContentManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/progress/DeferredTreeContentManager.java index 1defb7d61ad..5b51a404299 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/progress/DeferredTreeContentManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/progress/DeferredTreeContentManager.java @@ -221,8 +221,7 @@ public IStatus run(IProgressMonitor monitor) { @Override public boolean belongsTo(Object family) { - if (family instanceof DeferredContentFamily) { - DeferredContentFamily contentFamily = (DeferredContentFamily) family; + if (family instanceof DeferredContentFamily contentFamily) { if (contentFamily.manager == DeferredTreeContentManager.this) { return isParent(contentFamily, parent); } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/splash/BasicSplashHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/splash/BasicSplashHandler.java index f3b33a84c9f..53abe6325f5 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/splash/BasicSplashHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/splash/BasicSplashHandler.java @@ -73,8 +73,9 @@ public Label getProgressText() { public void beginTask(final String name, final int totalWork) { updateUI(() -> { - if (isDisposed()) + if (isDisposed()) { return; + } AbsolutePositionProgressMonitorPart.super.beginTask(name, totalWork); }); @@ -84,8 +85,9 @@ public void beginTask(final String name, final int totalWork) { public void done() { updateUI(() -> { - if (isDisposed()) + if (isDisposed()) { return; + } AbsolutePositionProgressMonitorPart.super.done(); }); @@ -95,8 +97,9 @@ public void done() { public void internalWorked(final double work) { updateUI(() -> { - if (isDisposed()) + if (isDisposed()) { return; + } AbsolutePositionProgressMonitorPart.super.internalWorked(work); }); @@ -106,8 +109,9 @@ public void internalWorked(final double work) { public void setFont(final Font font) { updateUI(() -> { - if (isDisposed()) + if (isDisposed()) { return; + } AbsolutePositionProgressMonitorPart.super.setFont(font); }); @@ -117,8 +121,9 @@ public void setFont(final Font font) { protected void updateLabel() { updateUI(() -> { - if (isDisposed()) + if (isDisposed()) { return; + } AbsolutePositionProgressMonitorPart.super.updateLabel(); }); @@ -138,18 +143,21 @@ public IProgressMonitor getBundleProgressMonitor() { parent.setBounds(new Rectangle(0, 0, size.x, size.y)); monitor = new AbsolutePositionProgressMonitorPart(parent); monitor.setSize(size); - if (progressRect != null) + if (progressRect != null) { monitor.getProgressIndicator().setBounds(progressRect); - else + } else { monitor.getProgressIndicator().setVisible(false); + } - if (messageRect != null) + if (messageRect != null) { monitor.getProgressText().setBounds(messageRect); - else + } else { monitor.getProgressText().setVisible(false); + } - if (foreground != null) + if (foreground != null) { monitor.getProgressText().setForeground(foreground); + } monitor.setBackgroundMode(SWT.INHERIT_FORCE); monitor.setBackgroundImage(getSplash().getShell().getBackgroundImage()); } @@ -163,8 +171,9 @@ public IProgressMonitor getBundleProgressMonitor() { * @param foregroundRGB the color */ protected void setForeground(RGB foregroundRGB) { - if (monitor != null) + if (monitor != null) { return; + } this.foreground = new Color(getSplash().getShell().getDisplay(), foregroundRGB); } @@ -231,14 +240,15 @@ protected Composite getContent() { */ private void updateUI(final Runnable r) { Shell splashShell = getSplash(); - if (splashShell == null || splashShell.isDisposed()) + if (splashShell == null || splashShell.isDisposed()) { return; + } Display display = splashShell.getDisplay(); - if (Thread.currentThread() == display.getThread()) + if (Thread.currentThread() == display.getThread()) { r.run(); // run immediatley if we're on the UI thread - else { + } else { // wrapper with a StartupRunnable to ensure that it will run before // the UI is fully initialized StartupRunnable startupRunnable = new StartupRunnable() { diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/statushandlers/StatusManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/statushandlers/StatusManager.java index 36717440ba9..ce14d1684a2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/statushandlers/StatusManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/statushandlers/StatusManager.java @@ -116,11 +116,11 @@ public class StatusManager { private volatile AbstractStatusHandler statusHandler; - private List loggedStatuses = new Vector<>(); + private final List loggedStatuses = new Vector<>(); - private ListenerList listeners = new ListenerList<>(); + private final ListenerList listeners = new ListenerList<>(); - private StatusManagerLogListener statusManagerLogListener; + private final StatusManagerLogListener statusManagerLogListener; /** * Returns StatusManager singleton instance. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java index a574f23e37f..5168ac8d122 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java @@ -68,7 +68,7 @@ public class WorkbenchStatusDialogManager { static final QualifiedName HINT = new QualifiedName(IStatusAdapterConstants.PROPERTY_PREFIX, "hint"); //$NON-NLS-1$ - private WorkbenchStatusDialogManagerImpl manager; + private final WorkbenchStatusDialogManagerImpl manager; /** * Creates workbench status dialog. diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/themes/RGBBlendColorFactory.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/themes/RGBBlendColorFactory.java index 3f788e54913..c62ba527511 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/themes/RGBBlendColorFactory.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/themes/RGBBlendColorFactory.java @@ -81,8 +81,7 @@ public RGB createColor() { public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { - if (data instanceof Hashtable) { - Hashtable table = (Hashtable) data; + if (data instanceof Hashtable table) { color1 = (String) table.get("color1"); //$NON-NLS-1$ color2 = (String) table.get("color2"); //$NON-NLS-1$ }