diff --git a/Jenkinsfile b/Jenkinsfile index 4410731e9e..ce18ecc5a1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { } tools { maven 'apache-maven-latest' - jdk 'temurin-jdk11-latest' + jdk 'openjdk-latest' } stages { stage('get m2e-core-tests') { diff --git a/m2e-core-tests b/m2e-core-tests index d74ab38782..4eea7e46d1 160000 --- a/m2e-core-tests +++ b/m2e-core-tests @@ -1 +1 @@ -Subproject commit d74ab38782bf89dc31ca7390aaddb2f5b6010bea +Subproject commit 4eea7e46d11035c3f908934e71231f1e0cce072a diff --git a/org.eclipse.m2e.core.ui/.classpath b/org.eclipse.m2e.core.ui/.classpath index 4a00becd81..3628e33687 100644 --- a/org.eclipse.m2e.core.ui/.classpath +++ b/org.eclipse.m2e.core.ui/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.m2e.core.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.core.ui/.settings/org.eclipse.jdt.core.prefs index 30b95bdc46..70cb335670 100644 --- a/org.eclipse.m2e.core.ui/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.m2e.core.ui/.settings/org.eclipse.jdt.core.prefs @@ -28,9 +28,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul org.eclipse.jdt.core.compiler.annotation.nullable.secondary= org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -144,8 +144,8 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,HIGH org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX diff --git a/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF index e4d3045dd7..9194e48be5 100644 --- a/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.m2e.core.ui;singleton:=true Bundle-Version: 2.0.0.qualifier -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor Bundle-Localization: plugin diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/MavenVersionDecorator.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/MavenVersionDecorator.java index a54336a9ed..4b56b7ccb4 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/MavenVersionDecorator.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/MavenVersionDecorator.java @@ -48,8 +48,7 @@ public Image decorateImage(Image image, Object element) { @Override public String decorateText(String text, Object element) { - if(element instanceof IResource) { - IResource resource = (IResource) element; + if(element instanceof IResource resource) { IProject project = resource.getProject(); if(project != null) { IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/ChangeNatureAction.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/ChangeNatureAction.java index 74a82deb80..f63aee8b55 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/ChangeNatureAction.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/ChangeNatureAction.java @@ -91,15 +91,14 @@ public void setActivePart(IAction action, IWorkbenchPart targetPart) { @Override public void run(IAction action) { - if(selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection) selection; + if(selection instanceof IStructuredSelection structuredSelection) { Set projects = new LinkedHashSet<>(); for(Object element : structuredSelection) { IProject project = null; - if(element instanceof IProject) { - project = (IProject) element; - } else if(element instanceof IAdaptable) { - project = ((IAdaptable) element).getAdapter(IProject.class); + if(element instanceof IProject p) { + project = p; + } else if(element instanceof IAdaptable adaptable) { + project = adaptable.getAdapter(IProject.class); } if(project != null) { projects.add(project); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/DisableNatureAction.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/DisableNatureAction.java index 53de9b9e2e..92c4b5266c 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/DisableNatureAction.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/DisableNatureAction.java @@ -42,14 +42,13 @@ public class DisableNatureAction implements IObjectActionDelegate { */ @Override public void run(IAction action) { - if(selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection) selection; + if(selection instanceof IStructuredSelection structuredSelection) { for(Object element : structuredSelection) { IProject project = null; - if(element instanceof IProject) { - project = (IProject) element; - } else if(element instanceof IAdaptable) { - project = ((IAdaptable) element).getAdapter(IProject.class); + if(element instanceof IProject p) { + project = p; + } else if(element instanceof IAdaptable adaptable) { + project = adaptable.getAdapter(IProject.class); } if(project != null) { try { diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/EnableNatureAction.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/EnableNatureAction.java index 81caa1b4cf..cbdd6a9feb 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/EnableNatureAction.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/EnableNatureAction.java @@ -84,14 +84,13 @@ public void setActivePart(IAction action, IWorkbenchPart targetPart) { @Override public void run(IAction action) { - if(selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection) selection; + if(selection instanceof IStructuredSelection structuredSelection) { for(Object element : structuredSelection) { IProject project = null; - if(element instanceof IProject) { - project = (IProject) element; - } else if(element instanceof IAdaptable) { - project = ((IAdaptable) element).getAdapter(IProject.class); + if(element instanceof IProject p) { + project = p; + } else if(element instanceof IAdaptable adaptable) { + project = adaptable.getAdapter(IProject.class); } if(project != null) { enableNature(project, structuredSelection.size() == 1); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenActionSupport.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenActionSupport.java index 642e2fa5e0..b06240952b 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenActionSupport.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenActionSupport.java @@ -71,11 +71,7 @@ public void setActivePart(IAction action, IWorkbenchPart targetPart) { @Override public void selectionChanged(IAction action, ISelection selection) { - if(selection instanceof IStructuredSelection) { - this.selection = (IStructuredSelection) selection; - } else { - this.selection = null; - } + this.selection = selection instanceof IStructuredSelection structuredSelection ? structuredSelection : null; } protected Shell getShell() { diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java index 0b944fd767..206c8657a0 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java @@ -93,21 +93,18 @@ public boolean test(Object receiver, String property, Object[] args, Object expe } if(IS_TRANSITIVE_DEPENDENCY_TREE_NODE.equals(property)) { - if(receiver instanceof DependencyNode) { - DependencyNode nd = (DependencyNode) receiver; + if(receiver instanceof DependencyNode nd) { return nd.getData().get("LEVEL") == null; } } if(IS_DIRECT_DEPENDENCY_TREE_NODE.equals(property)) { - if(receiver instanceof DependencyNode) { - DependencyNode nd = (DependencyNode) receiver; + if(receiver instanceof DependencyNode nd) { return "DIRECT".equals(nd.getData().get("LEVEL")); } } if(IS_BUILD_DIRECTORY.equals(property)) { - if(receiver instanceof IFolder) { - IFolder folder = (IFolder) receiver; + if(receiver instanceof IFolder folder) { IProject project = folder.getProject(); if(project != null) { IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); @@ -130,12 +127,11 @@ public boolean test(Object receiver, String property, Object[] args, Object expe } if(HAS_MAVEN_NATURE.equals(property)) { - if(receiver instanceof IFileEditorInput) { - var editor = (IFileEditorInput) receiver; + if(receiver instanceof IFileEditorInput editor) { return checkProjectNature(editor.getFile().getProject(), expectedValue); } - if(receiver instanceof IResource) { - IProject project = ((IResource) receiver).getProject(); + if(receiver instanceof IResource resource) { + IProject project = resource.getProject(); return checkProjectNature(project, expectedValue); } } @@ -145,7 +141,7 @@ public boolean test(Object receiver, String property, Object[] args, Object expe } private boolean checkProjectNature(IProject project, Object expectedValue) { - boolean expectedBoolean = expectedValue instanceof Boolean ? (Boolean) expectedValue : true; + boolean expectedBoolean = expectedValue instanceof Boolean b ? b : true; try { return project.hasNature(IMavenConstants.NATURE_ID) == expectedBoolean; } catch(CoreException ex) { diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/ModuleProjectWizardAction.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/ModuleProjectWizardAction.java index b9d1f9978c..2f1632277c 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/ModuleProjectWizardAction.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/ModuleProjectWizardAction.java @@ -57,8 +57,8 @@ public void setActivePart(IAction action, IWorkbenchPart part) { /** Handles the selection change */ @Override public void selectionChanged(IAction action, ISelection selection) { - if(selection instanceof IStructuredSelection) { - this.selection = (IStructuredSelection) selection; + if(selection instanceof IStructuredSelection sel) { + this.selection = sel; } } } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/OpenPomAction.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/OpenPomAction.java index fbea8e7316..f2a860d753 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/OpenPomAction.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/OpenPomAction.java @@ -92,11 +92,7 @@ public void init(IWorkbenchWindow window) { @Override public void selectionChanged(IAction action, ISelection selection) { - if(selection instanceof IStructuredSelection) { - this.selection = (IStructuredSelection) selection; - } else { - this.selection = null; - } + this.selection = selection instanceof IStructuredSelection sel ? sel : null; } @Override diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/SelectionUtil.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/SelectionUtil.java index a60a4ae4ec..8f8fa10f7e 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/SelectionUtil.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/SelectionUtil.java @@ -143,8 +143,8 @@ public static T getType(Object element, Class type) { if(type.isInstance(element)) { return type.cast(element); } - if(element instanceof IAdaptable) { - T adapter = ((IAdaptable) element).getAdapter(type); + if(element instanceof IAdaptable adaptable) { + T adapter = adaptable.getAdapter(type); if(adapter != null) { return adapter; } @@ -218,9 +218,8 @@ public static ArtifactKey getArtifactKey(Object element) { if(element instanceof Artifact) { return new ArtifactKey(((Artifact) element)); - } else if(element instanceof org.eclipse.aether.graph.DependencyNode) { - org.eclipse.aether.artifact.Artifact artifact = ((org.eclipse.aether.graph.DependencyNode) element) - .getDependency().getArtifact(); + } else if(element instanceof org.eclipse.aether.graph.DependencyNode depNode) { + org.eclipse.aether.artifact.Artifact artifact = depNode.getDependency().getArtifact(); return new ArtifactKey(artifact); //getArtifactKey() used only in a handful of actions, to my knowledge none of these are currently available on @@ -249,16 +248,15 @@ public static ArtifactKey getArtifactKey(Object element) { } public static MavenProject getMavenProject(IEditorInput editorInput, IProgressMonitor monitor) throws CoreException { - if(editorInput instanceof IFileEditorInput) { - IFile pomFile = ((IFileEditorInput) editorInput).getFile(); + if(editorInput instanceof IFileEditorInput fileInput) { + IFile pomFile = fileInput.getFile(); IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); IMavenProjectFacade facade = projectManager.create(pomFile, true, monitor); if(facade != null) { return facade.getMavenProject(monitor); } - } else if(editorInput instanceof IStorageEditorInput) { - IStorageEditorInput storageInput = (IStorageEditorInput) editorInput; + } else if(editorInput instanceof IStorageEditorInput storageInput) { IStorage storage = storageInput.getStorage(); IPath path = storage.getFullPath(); if(path == null || !new File(path.toOSString()).exists()) { @@ -335,13 +333,13 @@ public static IFile getPomFileFromPomEditorOrViewSelection(ISelection selection) //350136 we need to process the selection first! that's what is relevant for any popup menu action we have. //the processing of active editor first might have been only relevant when we had the actions in main menu, but even // then the popups were wrong.. - if(selection instanceof IStructuredSelection) { - Object o = ((IStructuredSelection) selection).iterator().next(); + if(selection instanceof IStructuredSelection structuredSelection) { + Object o = structuredSelection.iterator().next(); - if(o instanceof IProject) { - file = ((IProject) o).getFile(IMavenConstants.POM_FILE_NAME); - } else if(o instanceof IFile) { - file = (IFile) o; + if(o instanceof IProject project) { + file = project.getFile(IMavenConstants.POM_FILE_NAME); + } else if(o instanceof IFile f) { + file = f; } if(file != null) { return file; @@ -358,8 +356,7 @@ public static IFile getPomFileFromPomEditorOrViewSelection(ISelection selection) IEditorPart editor = page.getActiveEditor(); if(editor != null) { IEditorInput input = editor.getEditorInput(); - if(input instanceof IFileEditorInput) { - IFileEditorInput fileInput = (IFileEditorInput) input; + if(input instanceof IFileEditorInput fileInput) { file = fileInput.getFile(); if(IMavenConstants.POM_FILE_NAME.equals(file.getName())) { return file; @@ -383,20 +380,18 @@ public static IFile getPomFileFromPomEditorOrViewSelection(ISelection selection) */ public static IProject[] getProjects(ISelection selection, boolean includeAll) { ArrayList projectList = new ArrayList<>(); - if(selection instanceof IStructuredSelection) { - for(Object o : ((IStructuredSelection) selection)) { - if(o instanceof IProject) { - safeAdd((IProject) o, projectList); - } else if(o instanceof IWorkingSet) { - IWorkingSet workingSet = (IWorkingSet) o; + if(selection instanceof IStructuredSelection structuredSelection) { + for(Object o : structuredSelection) { + if(o instanceof IProject project) { + safeAdd(project, projectList); + } else if(o instanceof IWorkingSet workingSet) { for(IAdaptable adaptable : workingSet.getElements()) { IProject project = adaptable.getAdapter(IProject.class); safeAdd(project, projectList); } - } else if(o instanceof IResource) { - safeAdd(((IResource) o).getProject(), projectList); - } else if(o instanceof IAdaptable) { - IAdaptable adaptable = (IAdaptable) o; + } else if(o instanceof IResource resource) { + safeAdd(resource.getProject(), projectList); + } else if(o instanceof IAdaptable adaptable) { IProject project = adaptable.getAdapter(IProject.class); safeAdd(project, projectList); } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/StaticMavenStorageEditorInput.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/StaticMavenStorageEditorInput.java index 49bc58f940..e8d06ebba9 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/StaticMavenStorageEditorInput.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/StaticMavenStorageEditorInput.java @@ -94,8 +94,8 @@ public StaticMavenPathStorageEditorInput(String name, String tooltip, String pat @Override public boolean equals(Object obj) { IPath path = getPath(); - if(path != null && obj instanceof StaticMavenPathStorageEditorInput) { - return path.equals(((StaticMavenPathStorageEditorInput) obj).getPath()); + if(path != null && obj instanceof StaticMavenPathStorageEditorInput other) { + return path.equals(other.getPath()); } return super.equals(obj); } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectCommandHandler.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectCommandHandler.java index 51c86ce556..b07c1ed284 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectCommandHandler.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectCommandHandler.java @@ -76,10 +76,8 @@ public Object execute(final ExecutionEvent event) { private IProject[] getProjectInActiveEditor(ExecutionEvent event) { try { IWorkbenchPart activePart = HandlerUtil.getActivePart(event); - if(activePart instanceof IEditorPart) { - IEditorPart editorPart = (IEditorPart) activePart; - if(editorPart.getEditorInput() instanceof IFileEditorInput) { - IFileEditorInput fileInput = (IFileEditorInput) editorPart.getEditorInput(); + if(activePart instanceof IEditorPart editorPart) { + if(editorPart.getEditorInput() instanceof IFileEditorInput fileInput) { IProject project = fileInput.getFile().getProject(); if(project != null && project.isAccessible() && project.hasNature(IMavenConstants.NATURE_ID)) { return new IProject[] {project}; diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/MavenProjectLabelProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/MavenProjectLabelProvider.java index 3ff387d008..036fdba5c9 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/MavenProjectLabelProvider.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/MavenProjectLabelProvider.java @@ -37,7 +37,7 @@ public Image getImage(Object element) { return null; } ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); - if(element instanceof IProject && !((IProject) element).isAccessible()) { + if(element instanceof IProject project && !project.isAccessible()) { return sharedImages.getImage(IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED); } @@ -49,7 +49,7 @@ public Image getImage(Object element) { @Override public String getText(Object element) { - return element instanceof IProject ? ((IProject) element).getName() : ""; //$NON-NLS-1$ + return element instanceof IProject project ? project.getName() : ""; //$NON-NLS-1$ } } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/NestedProjectsComposite.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/NestedProjectsComposite.java index ab3a4ca14e..748ef1373c 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/NestedProjectsComposite.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/NestedProjectsComposite.java @@ -114,8 +114,8 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @Override public Object[] getElements(Object element) { - if(element instanceof Collection) { - return ((Collection) element).toArray(); + if(element instanceof Collection collection) { + return collection.toArray(); } return null; } @@ -135,8 +135,8 @@ public Object[] getChildren(Object parentElement) { } } return children.toArray(); - } else if(parentElement instanceof Collection) { - return ((Collection) parentElement).toArray(); + } else if(parentElement instanceof Collection collection) { + return collection.toArray(); } return null; } @@ -163,8 +163,8 @@ public boolean hasChildren(Object element) { return true; } } - } else if(element instanceof Collection) { - return !((Collection) element).isEmpty(); + } else if(element instanceof Collection collection) { + return !collection.isEmpty(); } return false; } @@ -351,8 +351,7 @@ protected void createButtons(Composite selectionActionComposite) { } String getElePath(Object element) { - if(element instanceof IProject) { - IProject project = (IProject) element; + if(element instanceof IProject project) { URI locationURI = project.getLocationURI(); try { @@ -416,8 +415,8 @@ protected boolean isInteresting(IProject project) throws CoreException { private static void addProject(Collection projects, String location) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for(IContainer container : root.findContainersForLocationURI(new File(location).toURI())) { - if(container instanceof IProject) { - projects.add((IProject) container); + if(container instanceof IProject project) { + projects.add(project); break; } } @@ -461,8 +460,8 @@ public void run() { public IProject getSelection() { ISelection selection = codebaseViewer.getSelection(); - if(selection instanceof IStructuredSelection) { - return (IProject) ((IStructuredSelection) selection).getFirstElement(); + if(selection instanceof IStructuredSelection structuredSelection) { + return (IProject) structuredSelection.getFirstElement(); } return null; } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java index a22d2ff0b7..413d79a0c2 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java @@ -109,10 +109,10 @@ public static class DepLabelProvider extends LabelProvider implements IColorProv @Override public String getText(Object element) { ParentHierarchyEntry project = null; - if(element instanceof ParentHierarchyEntry) { - project = (ParentHierarchyEntry) element; - } else if(element instanceof Object[]) { - project = (ParentHierarchyEntry) ((Object[]) element)[0]; + if(element instanceof ParentHierarchyEntry entry) { + project = entry; + } else if(element instanceof Object[] array) { + project = (ParentHierarchyEntry) array[0]; } else { return ""; //$NON-NLS-1$ } @@ -126,8 +126,7 @@ public String getText(Object element) { @Override public Color getForeground(Object element) { - if(element instanceof ParentHierarchyEntry) { - ParentHierarchyEntry project = (ParentHierarchyEntry) element; + if(element instanceof ParentHierarchyEntry project) { if(project.getFacade() == null) { // This project is not in the workspace return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); @@ -143,8 +142,7 @@ public Color getBackground(Object element) { @Override public Image getImage(Object element) { - if(element instanceof ParentHierarchyEntry) { - ParentHierarchyEntry project = (ParentHierarchyEntry) element; + if(element instanceof ParentHierarchyEntry project) { if(project.getFacade() == null) { // This project is not in the workspace return MavenImages.getOverlayImage(MavenImages.PATH_JAR, MavenImages.PATH_LOCK, IDecoration.BOTTOM_LEFT); @@ -207,12 +205,11 @@ public Object[] getElements(Object inputElement) { @Override public Object[] getChildren(Object parentElement) { - if(parentElement instanceof ParentHierarchyEntry) { + if(parentElement instanceof ParentHierarchyEntry parent) { /* * Walk the hierarchy list until we find the parentElement and * return the previous element, which is the child. */ - ParentHierarchyEntry parent = (ParentHierarchyEntry) parentElement; if(projects.size() == 1) { // No parent exists, only one element in the tree @@ -269,10 +266,10 @@ public List getHierarchy() { public ParentHierarchyEntry fromSelection() { ISelection selection = pomsViewer.getSelection(); - if(selection instanceof IStructuredSelection) { - Object obj = ((IStructuredSelection) selection).getFirstElement(); - if(obj instanceof ParentHierarchyEntry) { - return (ParentHierarchyEntry) obj; + if(selection instanceof IStructuredSelection structuredSelection) { + Object obj = structuredSelection.getFirstElement(); + if(obj instanceof ParentHierarchyEntry entry) { + return entry; } } return null; diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/WorkingSetGroup.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/WorkingSetGroup.java index d6138cdb0b..e59c5b2919 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/WorkingSetGroup.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/WorkingSetGroup.java @@ -103,12 +103,12 @@ private void createControl(Composite container) { workingsetComboViewer.setContentProvider(new IStructuredContentProvider() { @Override public Object[] getElements(Object input) { - if(input instanceof IWorkingSet[]) { - return (IWorkingSet[]) input; + if(input instanceof IWorkingSet[] workingSets) { + return workingSets; } else if(input instanceof List) { return new Object[] {input}; - } else if(input instanceof Set) { - return ((Set) input).toArray(); + } else if(input instanceof Set set) { + return set.toArray(); } return new IWorkingSet[0]; } @@ -126,9 +126,9 @@ public void dispose() { @Override public Image getImage(Object element) { - if(element instanceof IWorkingSet) { + if(element instanceof IWorkingSet workingSet) { - ImageDescriptor imageDescriptor = ((IWorkingSet) element).getImageDescriptor(); + ImageDescriptor imageDescriptor = workingSet.getImageDescriptor(); if(imageDescriptor != null) { try { return (Image) images.create(imageDescriptor); @@ -142,16 +142,16 @@ public Image getImage(Object element) { @Override public String getText(Object element) { - if(element instanceof IWorkingSet) { - return ((IWorkingSet) element).getLabel(); - } else if(element instanceof List) { + if(element instanceof IWorkingSet workingSet) { + return workingSet.getLabel(); + } else if(element instanceof List list) { StringBuilder sb = new StringBuilder(); - for(Object o : (List) element) { - if(o instanceof IWorkingSet) { + for(Object o : list) { + if(o instanceof IWorkingSet workingSet) { if(sb.length() > 0) { sb.append(", "); //$NON-NLS-1$ } - sb.append(((IWorkingSet) o).getLabel()); + sb.append(workingSet.getLabel()); } } return sb.toString(); @@ -211,8 +211,8 @@ protected void updateConfiguration() { Object o = selection.getFirstElement(); if(o != null) { workingSets.clear(); - if(o instanceof IWorkingSet) { - workingSets.add((IWorkingSet) o); + if(o instanceof IWorkingSet workingSet) { + workingSets.add(workingSet); } else if(o instanceof List) { @SuppressWarnings("unchecked") List l = (List) o; diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/InputHistory.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/InputHistory.java index d27b32203e..c4cdc179c5 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/InputHistory.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/InputHistory.java @@ -124,10 +124,10 @@ public void add(String id, final Control combo) { combos = new ArrayList<>(); comboMap.put(id, combos); } - if(combo instanceof Combo) { - combos.add(new ComboWrapper((Combo) combo)); - } else if(combo instanceof CCombo) { - combos.add(new CComboWrapper((CCombo) combo)); + if(combo instanceof Combo regularCombo) { + combos.add(new ComboWrapper(regularCombo)); + } else if(combo instanceof CCombo ccombo) { + combos.add(new CComboWrapper(ccombo)); } } } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java index 0e6bb596c4..a51cac0682 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java @@ -155,8 +155,7 @@ public static Element findChild(Element parent, String name) { NodeList rootList = parent.getChildNodes(); for(int i = 0; i < rootList.getLength(); i++ ) { Node nd = rootList.item(i); - if(nd instanceof Element) { - Element el = (Element) nd; + if(nd instanceof Element el) { if(name.equals(el.getNodeName())) { return el; } @@ -171,8 +170,7 @@ public static List findChilds(Element parent, String name) { NodeList rootList = parent.getChildNodes(); for(int i = 0; i < rootList.getLength(); i++ ) { Node nd = rootList.item(i); - if(nd instanceof Element) { - Element el = (Element) nd; + if(nd instanceof Element el) { if(name.equals(el.getNodeName())) { toRet.add(el); } @@ -189,8 +187,7 @@ public static String getTextValue(Node element) { NodeList list = element.getChildNodes(); for(int i = 0; i < list.getLength(); i++ ) { Node child = list.item(i); - if(child instanceof Text) { - Text text = (Text) child; + if(child instanceof Text text) { buff.append(text.getData().trim()); //352416 the value is trimmed because of the multiline values //that get trimmed by maven itself as well, any comparison to resolved model needs to do the trimming // or risks false negative results. @@ -310,8 +307,7 @@ public static Element getChild(Element parent, String... names) { public static void removeChild(Element parent, Element child) { if(child != null) { Node prev = child.getPreviousSibling(); - if(prev instanceof Text) { - Text txt = (Text) prev; + if(prev instanceof Text txt) { int lastnewline = getLastEolIndex(txt.getData()); if(lastnewline >= 0) { txt.setData(txt.getData().substring(0, lastnewline)); @@ -357,21 +353,19 @@ public static void removeIfNoChildElement(Element el) { } if(!hasChilds) { Node parent = el.getParentNode(); - if(parent instanceof Element) { - removeChild((Element) parent, el); - removeIfNoChildElement((Element) parent); + if(parent instanceof Element parentElement) { + removeChild(parentElement, el); + removeIfNoChildElement(parentElement); } } } public static Element insertAt(Element newElement, int offset) { Document doc = newElement.getOwnerDocument(); - if(doc instanceof IDOMDocument) { - IDOMDocument domDoc = (IDOMDocument) doc; + if(doc instanceof IDOMDocument domDoc) { IndexedRegion ir = domDoc.getModel().getIndexedRegion(offset); Node parent = ((Node) ir).getParentNode(); - if(ir instanceof Text) { - Text txt = (Text) ir; + if(ir instanceof Text txt) { String data = txt.getData(); int dataSplitIndex = offset - ir.getStartOffset(); String beforeText = data.substring(0, dataSplitIndex); @@ -381,12 +375,12 @@ public static Element insertAt(Element newElement, int offset) { parent.replaceChild(after, txt); parent.insertBefore(newElement, after); parent.insertBefore(before, newElement); - } else if(ir instanceof Element) { + } else if(ir instanceof Element element) { if(ir.getStartOffset() == offset) { // caret is before the tag, not within its bounds - parent.insertBefore(newElement, (Element) ir); + parent.insertBefore(newElement, element); } else { - ((Element) ir).appendChild(newElement); + element.appendChild(newElement); } } else { throw new IllegalArgumentException(); @@ -405,11 +399,9 @@ public static Element insertAt(Element newElement, int offset) { * @return */ public static Element elementAtOffset(Document doc, int offset) { - if(doc instanceof IDOMDocument) { - IDOMDocument domDoc = (IDOMDocument) doc; + if(doc instanceof IDOMDocument domDoc) { IndexedRegion ir = domDoc.getModel().getIndexedRegion(offset); - if(ir instanceof Element) { - Element elem = (Element) ir; + if(ir instanceof Element elem) { if(ir.getStartOffset() == offset) { // caret is before the tag, not within its bounds elem = (Element) elem.getParentNode(); @@ -417,8 +409,8 @@ public static Element elementAtOffset(Document doc, int offset) { return elem; } Node parent = ((Node) ir).getParentNode(); - if(parent instanceof Element) { - return (Element) parent; + if(parent instanceof Element parentElement) { + return parentElement; } } return null; @@ -434,8 +426,8 @@ public static void format(Node newNode) { if(parentNode != null && newNode.equals(parentNode.getLastChild())) { //add a new line to get the newly generated content correctly formatted. Document ownerDocument; - if(parentNode instanceof Document) { - ownerDocument = (Document) parentNode; + if(parentNode instanceof Document doc) { + ownerDocument = doc; } else { ownerDocument = parentNode.getOwnerDocument(); } @@ -479,8 +471,7 @@ public static void performOnDOMDocument(PomEdits.OperationTuple... fileOperation domModel.aboutToChangeModel(); undo = domModel.getStructuredDocument().getUndoManager(); //let the document know we make changes - if(domModel.getStructuredDocument() instanceof IDocumentExtension4) { - IDocumentExtension4 ext4 = (IDocumentExtension4) domModel.getStructuredDocument(); + if(domModel.getStructuredDocument() instanceof IDocumentExtension4 ext4) { session = ext4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED_SMALL); } undo.beginRecording(domModel); @@ -514,8 +505,7 @@ public static void performOnDOMDocument(PomEdits.OperationTuple... fileOperation } finally { if(!tuple.isReadOnly()) { undo.endRecording(domModel); - if(session != null && domModel.getStructuredDocument() instanceof IDocumentExtension4) { - IDocumentExtension4 ext4 = (IDocumentExtension4) domModel.getStructuredDocument(); + if(session != null && domModel.getStructuredDocument() instanceof IDocumentExtension4 ext4) { ext4.stopRewriteSession(session); } domModel.changedModel(); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomHelper.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomHelper.java index a2383ede31..0cee68d4f6 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomHelper.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomHelper.java @@ -123,8 +123,8 @@ public static TextChange createChange(IFile file, Operation operation, String la if(forceSave) assert change instanceof TextFileChange; //if assert not fullfilled, we will not get the file saved.. - if(forceSave && change instanceof TextFileChange) { - ((TextFileChange) change).setSaveMode(TextFileChange.FORCE_SAVE); + if(forceSave && change instanceof TextFileChange textFileChange) { + textFileChange.setSaveMode(TextFileChange.FORCE_SAVE); } return change; } catch(Exception exc) { diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/AggregateMappingLabelProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/AggregateMappingLabelProvider.java index 23cf3b9def..3b774a76ca 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/AggregateMappingLabelProvider.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/lifecyclemapping/AggregateMappingLabelProvider.java @@ -50,16 +50,16 @@ public AggregateMappingLabelProvider(ILifecycleMappingRequirement element, @Override public String getMavenText() { - if(element instanceof LifecycleStrategyMappingRequirement) { - return NLS.bind("Connector {0}", ((LifecycleStrategyMappingRequirement) element).getLifecycleMappingId()); - } else if(element instanceof MojoExecutionMappingRequirement) { - MojoExecutionKey exec = ((MojoExecutionMappingRequirement) element).getExecution(); + if(element instanceof LifecycleStrategyMappingRequirement lifecycleStrategyMappingRequirement) { + return NLS.bind("Connector {0}", lifecycleStrategyMappingRequirement.getLifecycleMappingId()); + } else if(element instanceof MojoExecutionMappingRequirement req) { + MojoExecutionKey exec = req.getExecution(); return NLS.bind("{0}:{1}:{2}", new String[] {exec.getArtifactId(), exec.getVersion(), exec.getGoal(), String.valueOf(content.size())}); - } else if(element instanceof PackagingTypeMappingRequirement) { - return NLS.bind("Packaging {0}", ((PackagingTypeMappingRequirement) element).getPackaging()); - } else if(element instanceof ProjectConfiguratorMappingRequirement) { - MojoExecutionKey exec = ((ProjectConfiguratorMappingRequirement) element).getExecution(); + } else if(element instanceof PackagingTypeMappingRequirement req) { + return NLS.bind("Packaging {0}", req.getPackaging()); + } else if(element instanceof ProjectConfiguratorMappingRequirement req) { + MojoExecutionKey exec = req.getExecution(); return NLS.bind("{0}:{1}:{2}", new String[] {exec.getArtifactId(), exec.getVersion(), exec.getGoal(), String.valueOf(content.size())}); } @@ -101,9 +101,6 @@ public int hashCode() { @Override public boolean equals(Object other) { - if(other instanceof AggregateMappingLabelProvider) { - return other.hashCode() == hashCode(); - } - return false; + return other instanceof AggregateMappingLabelProvider && other.hashCode() == hashCode(); } } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/markers/MarkerLocationService.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/markers/MarkerLocationService.java index 849b420a6a..839bd84d9c 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/markers/MarkerLocationService.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/markers/MarkerLocationService.java @@ -228,8 +228,7 @@ private Element findPlugin(Element build, String groupId, String artifactId) { private void annotateMarker(final IMarker marker, IStructuredDocument structuredDocument, Element ourMarkerPlacement) { - if(ourMarkerPlacement instanceof IndexedRegion) { - IndexedRegion region = (IndexedRegion) ourMarkerPlacement; + if(ourMarkerPlacement instanceof IndexedRegion region) { try { marker.setAttribute(IMarker.CHAR_START, region.getStartOffset()); //as end, mark just the end of line where the region starts to prevent marking the entire section. @@ -383,8 +382,7 @@ private static void checkManagedDependencies(IMavenMarkerManager mavenMarkerMana if(managed.containsKey(id)) { Dependency managedDep = managed.get(id); String managedVersion = managedDep == null ? null : managedDep.getVersion(); - if(version instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) version; + if(version instanceof IndexedRegion off) { if(lookForIgnoreMarker(document, version, off, IMavenConstants.MARKER_IGNORE_MANAGED)) { continue; } @@ -521,8 +519,7 @@ private static void checkManagedPlugins(IMavenMarkerManager mavenMarkerManager, if(managed.containsKey(id)) { Plugin managedPlugin = managed.get(id); String managedVersion = managedPlugin == null ? null : managedPlugin.getVersion(); - if(version instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) version; + if(version instanceof IndexedRegion off) { if(lookForIgnoreMarker(document, version, off, IMavenConstants.MARKER_IGNORE_MANAGED)) { continue; } @@ -562,8 +559,7 @@ private static void checkParentMatchingGroupIdVersion(IMavenMarkerManager mavenM String childString = getTextValue(groupId); if(parentString != null && parentString.equals(childString)) { //now figure out the offset - if(groupId instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) groupId; + if(groupId instanceof IndexedRegion off) { IMarker mark = mavenMarkerManager.addMarker(pomFile, type, org.eclipse.m2e.core.internal.Messages.MavenMarkerManager_duplicate_groupid, document.getLineOfOffset(off.getStartOffset()) + 1, matchingParentGroupIdSeverity.getSeverity()); @@ -582,8 +578,7 @@ private static void checkParentMatchingGroupIdVersion(IMavenMarkerManager mavenM String childString = getTextValue(version); if(parentString != null && parentString.equals(childString)) { //now figure out the offset - if(version instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) version; + if(version instanceof IndexedRegion off) { IMarker mark = mavenMarkerManager.addMarker(pomFile, type, org.eclipse.m2e.core.internal.Messages.MavenMarkerManager_duplicate_version, document.getLineOfOffset(off.getStartOffset()) + 1, matchingParentVersionSeverity.getSeverity()); @@ -653,8 +648,7 @@ private static boolean lookForIgnoreMarker(IStructuredDocument document, Element int start = off.getStartOffset(); while(reg != null && start < lineend) { reg = reg.getNextSibling(); - if(reg instanceof Comment) { - Comment comm = (Comment) reg; + if(reg instanceof Comment comm) { String data = comm.getData(); if(data != null && data.contains(ignoreString)) { return true; diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/markers/MavenProblemResolution.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/markers/MavenProblemResolution.java index a9bb944193..da20b92930 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/markers/MavenProblemResolution.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/markers/MavenProblemResolution.java @@ -208,8 +208,7 @@ public static List getResolutions(IMarker marker) { } public static int getOrder(IMarkerResolution res) { - if(res instanceof MavenProblemResolution) { - MavenProblemResolution mr = (MavenProblemResolution) res; + if(res instanceof MavenProblemResolution mr) { return mr.getOrder(); } return Integer.MAX_VALUE; diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java index d0ec6503cd..c001548631 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java @@ -294,16 +294,15 @@ public void removeListener(ILabelProviderListener listener) { @Override public Image getColumnImage(Object element, int columnIndex) { - if(columnIndex == 0 && element instanceof MojoExecutionKey) { - return isErrorMapping((MojoExecutionKey) element) ? MavenImages.IMG_ERROR : MavenImages.IMG_PASSED; + if(columnIndex == 0 && element instanceof MojoExecutionKey key) { + return isErrorMapping(key) ? MavenImages.IMG_ERROR : MavenImages.IMG_PASSED; } return null; } @Override public String getColumnText(Object element, int columnIndex) { - if(element instanceof MojoExecutionKey) { - MojoExecutionKey execution = (MojoExecutionKey) element; + if(element instanceof MojoExecutionKey execution) { switch(columnIndex) { case 0: return LifecycleMappingsViewer.this.toString(execution); @@ -329,8 +328,7 @@ public String getColumnText(Object element, int columnIndex) { mappingsTreeViewer.setInput(phases); mappingsTreeViewer.addSelectionChangedListener(e -> { Object element = e.getStructuredSelection().getFirstElement(); - if(element instanceof MojoExecutionKey) { - MojoExecutionKey execution = (MojoExecutionKey) element; + if(element instanceof MojoExecutionKey execution) { infoLabel.setText(getSourcelabel(execution, mappings.get().get(execution), true)); } else { infoLabel.setText(""); @@ -455,14 +453,14 @@ String getSourcelabel(MojoExecutionKey execution, List LifecycleMappingMetadataSource metadata = ((PluginExecutionMetadata) mapping).getSource(); if(metadata != null) { Object source = metadata.getSource(); - if(source instanceof String) { - sources.add((String) source); - } else if(source instanceof Artifact) { - sources.add(getSourceLabel((Artifact) source, detailed)); - } else if(source instanceof MavenProject) { - sources.add(getSourceLabel((MavenProject) source, detailed)); - } else if(source instanceof Bundle) { - sources.add(getSourceLabel((Bundle) source, detailed)); + if(source instanceof String s) { + sources.add(s); + } else if(source instanceof Artifact artifact) { + sources.add(getSourceLabel(artifact, detailed)); + } else if(source instanceof MavenProject mavenProject) { + sources.add(getSourceLabel(mavenProject, detailed)); + } else if(source instanceof Bundle bundle) { + sources.add(getSourceLabel(bundle, detailed)); } else { sources.add("unknown"); //$NON-NLS-1$ } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenArchetypesPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenArchetypesPreferencePage.java index 83a9be210e..d2657a9df5 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenArchetypesPreferencePage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenArchetypesPreferencePage.java @@ -26,10 +26,10 @@ import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.StructuredSelection; @@ -157,17 +157,7 @@ protected void createFieldEditors() { archetypesViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION); archetypesViewer.setLabelProvider(new CatalogsLabelProvider()); - - archetypesViewer.setContentProvider(new IStructuredContentProvider() { - - @Override - public Object[] getElements(Object input) { - if(input instanceof Collection) { - return ((Collection) input).toArray(); - } - return new Object[0]; - } - }); + archetypesViewer.setContentProvider(new ArrayContentProvider()); Table table = archetypesViewer.getTable(); table.setLinesVisible(false); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java index 5605387417..f14243bb73 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java @@ -142,8 +142,8 @@ public Image getImage(Object element) { @Override public String getText(Object element) { - if(element instanceof ProjectClasspathEntry) { - return ((ProjectClasspathEntry) element).getProject(); + if(element instanceof ProjectClasspathEntry entry) { + return entry.getProject(); } return element.toString(); } @@ -328,8 +328,7 @@ protected void addProjectExtensionAction() { protected boolean contains(List entries, IProject project) { for(ClasspathEntry entry : entries) { - if(entry instanceof ProjectClasspathEntry - && ((ProjectClasspathEntry) entry).getProject().equals(project.getName())) { + if(entry instanceof ProjectClasspathEntry projectEntry && projectEntry.getProject().equals(project.getName())) { return true; } } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java index d6f91a7b00..e2f857c306 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java @@ -173,8 +173,7 @@ private void createTable(Composite composite) { @Override public Object[] getElements(Object input) { - if(input instanceof List) { - List list = (List) input; + if(input instanceof List list) { if(!list.isEmpty()) { return list.toArray(new AbstractMavenRuntime[list.size()]); } @@ -293,18 +292,18 @@ static class RuntimesLabelProvider implements ITableLabelProvider, IColorProvide @Override public String getColumnText(Object element, int columnIndex) { AbstractMavenRuntime runtime = (AbstractMavenRuntime) element; - switch(columnIndex) { - case 0: - return !runtime.isLegacy() ? runtime.getName() : null; - case 1: + return switch(columnIndex) { + case 0 -> !runtime.isLegacy() ? runtime.getName() : null; + case 1 -> { StringBuilder sb = new StringBuilder(); if(!runtime.isAvailable()) { sb.append(Messages.MavenInstallationsPreferencePage_runtimeUnavailable); } sb.append(runtime.toString()); - return sb.toString(); - } - return null; + yield sb.toString(); + } + default -> null; + }; } @Override diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/M2EErrorDialog.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/M2EErrorDialog.java index e44236f1c9..e2ab2ccb89 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/M2EErrorDialog.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/M2EErrorDialog.java @@ -153,8 +153,8 @@ class ErrorTableContentProvider implements IStructuredContentProvider { @Override public Object[] getElements(Object inputElement) { - if(inputElement instanceof Map) { - return ((Map) inputElement).keySet().toArray(); + if(inputElement instanceof Map map) { + return map.keySet().toArray(); } return new Object[0]; } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/XmlUtils.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/XmlUtils.java index 5deb681b16..9876477cb4 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/XmlUtils.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/XmlUtils.java @@ -115,8 +115,8 @@ public static IProject extractProject(ITextViewer sourceViewer) { } while(path.segmentCount() > 1) { IResource ires = ResourcesPlugin.getWorkspace().getRoot().findMember(path); - if(ires instanceof IFile) { - stack.push((IFile) ires); + if(ires instanceof IFile f) { + stack.push(f); } path = path.removeFirstSegments(1); } @@ -136,8 +136,8 @@ public static IProject extractProject(ITextViewer sourceViewer) { public static MavenProject extractMavenProject(ITextViewer sourceViewer) { //look in the sourceViewer's cache only - if(sourceViewer instanceof IAdaptable) { - return ((IAdaptable) sourceViewer).getAdapter(MavenProject.class); + if(sourceViewer instanceof IAdaptable adaptable) { + return adaptable.getAdapter(MavenProject.class); } return null; } @@ -210,8 +210,8 @@ public static void performOnCurrentElement(IDocument document, int offset, NodeO if(inode == null) { inode = sModel.getIndexedRegion(offset - 1); } - if(inode instanceof Node) { - operation.process((Node) inode, sModel.getStructuredDocument()); + if(inode instanceof Node node) { + operation.process(node, sModel.getStructuredDocument()); } } } finally { diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenLifecycleMappingsView.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenLifecycleMappingsView.java index 561c422a3c..fd5a85ef95 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenLifecycleMappingsView.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenLifecycleMappingsView.java @@ -57,8 +57,8 @@ public void init(IViewSite site) throws PartInitException { @Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { Object element; - if(selection instanceof IStructuredSelection) { - element = ((IStructuredSelection) selection).getFirstElement(); + if(selection instanceof IStructuredSelection structuredSelection) { + element = structuredSelection.getFirstElement(); } else { element = null; } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java index 3a7e86c912..18b3777cda 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java @@ -154,8 +154,8 @@ protected List getSelectedRepositoryNodes(List elements ArrayList list = new ArrayList<>(); if(elements != null) { for(Object elem : elements) { - if(elem instanceof IMavenRepositoryNode) { - list.add((IMavenRepositoryNode) elem); + if(elem instanceof IMavenRepositoryNode repoNode) { + list.add(repoNode); } } } @@ -168,8 +168,7 @@ protected List getArtifactNodes(List elements) { } ArrayList list = new ArrayList<>(); for(Object elem : elements) { - if(elem instanceof IArtifactNode) { - IArtifactNode node = (IArtifactNode) elem; + if(elem instanceof IArtifactNode node) { list.add(node); } } @@ -238,8 +237,8 @@ public IStatus runInWorkspace(IProgressMonitor monitor) { public void run() { ISelection selection = viewer.getSelection(); Object element = ((IStructuredSelection) selection).getFirstElement(); - if(element instanceof IArtifactNode) { - Artifact f = ((IArtifactNode) element).getArtifact(); + if(element instanceof IArtifactNode node) { + Artifact f = node.getArtifact(); OpenPomAction.openEditor(f.getGroupId(), f.getArtifactId(), f.getVersion(), null); } } @@ -257,8 +256,8 @@ protected boolean updateSelection(IStructuredSelection selection) { public void run() { Object element = getStructuredSelection().getFirstElement(); String url = null; - if(element instanceof RepositoryNode) { - url = ((RepositoryNode) element).getRepositoryUrl(); + if(element instanceof RepositoryNode repoNode) { + url = repoNode.getRepositoryUrl(); } else if(element instanceof IndexedArtifact) { // } else if(element instanceof IndexedArtifactFile) { @@ -308,8 +307,7 @@ protected RepositoryNode getSelectedRepositoryNode(IStructuredSelection selectio if(elements.size() != 1) { return null; } - Object element = elements.get(0); - return element instanceof RepositoryNode ? (RepositoryNode) element : null; + return elements.get(0) instanceof RepositoryNode repoNode ? repoNode : null; } @Override diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewContentProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewContentProvider.java index 4407af7133..e6846741f5 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewContentProvider.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewContentProvider.java @@ -63,10 +63,7 @@ public Object getParent(Object child) { @Override public boolean hasChildren(Object parent) { - if(parent instanceof IMavenRepositoryNode) { - return ((IMavenRepositoryNode) parent).hasChildren(); - } - return false; + return parent instanceof IMavenRepositoryNode repoNode && repoNode.hasChildren(); } public Object[] getRootNodes() { @@ -90,8 +87,8 @@ public Object[] getRootNodes() { public Object[] getChildren(Object parent) { if(parent instanceof IViewSite) { return getRootNodes(); - } else if(parent instanceof IMavenRepositoryNode) { - return ((IMavenRepositoryNode) parent).getChildren(); + } else if(parent instanceof IMavenRepositoryNode repoNode) { + return repoNode.getChildren(); } return new Object[0]; } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewLabelProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewLabelProvider.java index 7a1f0a33ba..09a31160b2 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewLabelProvider.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewLabelProvider.java @@ -63,16 +63,16 @@ public void dispose() { @Override public String getText(Object obj) { - if(obj instanceof IMavenRepositoryNode) { - return ((IMavenRepositoryNode) obj).getName(); + if(obj instanceof IMavenRepositoryNode repoNode) { + return repoNode.getName(); } return obj.toString(); } @Override public Image getImage(Object obj) { - if(obj instanceof IMavenRepositoryNode) { - return ((IMavenRepositoryNode) obj).getImage(); + if(obj instanceof IMavenRepositoryNode repoNode) { + return repoNode.getImage(); } return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); } @@ -84,7 +84,7 @@ public Color getBackground(Object element) { @Override public Color getForeground(Object element) { - if(element instanceof RepositoryNode && !(((RepositoryNode) element).hasChildren())) { + if(element instanceof RepositoryNode repoNode && !repoNode.hasChildren()) { return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); } return null; @@ -92,11 +92,7 @@ public Color getForeground(Object element) { @Override public Font getFont(Object element) { - if(element instanceof IMavenRepositoryNode) { - boolean updating = ((IMavenRepositoryNode) element).isUpdating(); - return updating ? italicFont : null; - } - return null; + return element instanceof IMavenRepositoryNode repoNode && repoNode.isUpdating() ? italicFont : null; } @Override diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/build/BuildDebugView.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/build/BuildDebugView.java index 8d73c7130c..b126ea1ca8 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/build/BuildDebugView.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/build/BuildDebugView.java @@ -122,8 +122,8 @@ public void addListener(ILabelProviderListener listener) { @Override public String getColumnText(Object element, int columnIndex) { - if(element instanceof Node) { - return getColumnText((Node) element, columnIndex); + if(element instanceof Node node) { + return getColumnText(node, columnIndex); } if(columnIndex == 0) { @@ -134,15 +134,12 @@ public String getColumnText(Object element, int columnIndex) { } private String getColumnText(Node element, int columnIndex) { - switch(columnIndex) { - case 0: - return element.getName(); - case 1: - return Integer.toString(element.getBuildCount()); - default: + return switch(columnIndex) { + case 0 -> element.getName(); + case 1 -> Integer.toString(element.getBuildCount()); + default -> null; // fall through - } - return null; + }; } @Override @@ -163,11 +160,11 @@ public void dispose() { @Override public boolean hasChildren(Object element) { - if(element instanceof ContainerNode) { - return !((ContainerNode) element).getResources().isEmpty(); + if(element instanceof ContainerNode containerNode) { + return !containerNode.getResources().isEmpty(); } - if(element instanceof CollectionNode) { - return !((CollectionNode) element).getMembers().isEmpty(); + if(element instanceof CollectionNode collectionNode) { + return !collectionNode.getMembers().isEmpty(); } return false; } @@ -192,11 +189,9 @@ public Object[] getElements(Object inputElement) { @Override public Object[] getChildren(Object parentElement) { - if(parentElement instanceof ProjectNode) { + if(parentElement instanceof ProjectNode projectNode) { ArrayList result = new ArrayList<>(); - final ProjectNode projectNode = (ProjectNode) parentElement; - final List resources = new ArrayList<>(projectNode.getResources()); if(!resources.isEmpty()) { Collections.sort(resources, NODE_COMPARATOR); @@ -210,10 +205,10 @@ public Object[] getChildren(Object parentElement) { } return result.toArray(); - } else if(parentElement instanceof CollectionNode) { - return ((CollectionNode) parentElement).getMembers().toArray(); - } else if(parentElement instanceof ContainerNode) { - return ((ContainerNode) parentElement).getResources().toArray(); + } else if(parentElement instanceof CollectionNode collectionNode) { + return collectionNode.getMembers().toArray(); + } else if(parentElement instanceof ContainerNode containerNode) { + return containerNode.getResources().toArray(); } return null; } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java index 1ad15de8b6..c4669dc0cb 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractCreateMavenProjectsOperation.java @@ -65,8 +65,8 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException { public static IStatus toStatus(InvocationTargetException e) { Throwable t = e.getCause(); - if(t instanceof CoreException) { - return ((CoreException) t).getStatus(); + if(t instanceof CoreException ex) { + return ex.getStatus(); } return new Status(IStatus.ERROR, M2EUIPluginActivator.PLUGIN_ID, t.getMessage(), t); } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java index e58e411da4..78abe9dc64 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/LifecycleMappingPage.java @@ -175,8 +175,7 @@ public void createControl(Composite parent) { @SuppressWarnings("synthetic-access") @Override protected void setValue(Object element, Object value) { - if(element instanceof ILifecycleMappingLabelProvider) { - ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) element; + if(element instanceof ILifecycleMappingLabelProvider prov) { int intVal = ((Integer) value).intValue(); List all = mappingConfiguration.getProposals(prov.getKey()); @@ -217,8 +216,7 @@ protected void setValue(Object element, Object value) { @Override protected Object getValue(Object element) { - if(element instanceof ILifecycleMappingLabelProvider) { - ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) element; + if(element instanceof ILifecycleMappingLabelProvider prov) { IMavenDiscoveryProposal prop = mappingConfiguration.getSelectedProposal(prov.getKey()); List all = mappingConfiguration.getProposals(prov.getKey()); if(ignore.contains(element)) { @@ -237,8 +235,7 @@ protected Object getValue(Object element) { @Override protected CellEditor getCellEditor(Object element) { - if(element instanceof ILifecycleMappingLabelProvider) { - ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) element; + if(element instanceof ILifecycleMappingLabelProvider prov) { List all = mappingConfiguration.getProposals(prov.getKey()); List values = new ArrayList<>(); for(IMavenDiscoveryProposal prop : all) { @@ -254,8 +251,7 @@ protected CellEditor getCellEditor(Object element) { Control cont = edit.getControl(); //this attempts to disable text edits in the combo.. - if(cont instanceof CCombo) { - CCombo combo = (CCombo) cont; + if(cont instanceof CCombo combo) { combo.setEditable(false); } return edit; @@ -265,8 +261,7 @@ protected CellEditor getCellEditor(Object element) { @Override protected boolean canEdit(Object element) { - if(element instanceof AggregateMappingLabelProvider) { - ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) element; + if(element instanceof AggregateMappingLabelProvider prov) { List all = mappingConfiguration.getProposals(prov.getKey()); return all != null && !all.isEmpty() || prov.getKey() instanceof MojoExecutionMappingRequirement; } @@ -286,11 +281,10 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @Override public Object[] getElements(Object inputElement) { - if(inputElement instanceof LifecycleMappingDiscoveryRequest) { + if(inputElement instanceof LifecycleMappingDiscoveryRequest request) { Map> packagings = new HashMap<>(); Map> mojos = new HashMap<>(); - Map> projects = ((LifecycleMappingDiscoveryRequest) inputElement) - .getProjects(); + Map> projects = request.getProjects(); for(final Entry> entry : projects.entrySet()) { final String relPath = entry.getKey().getProject().getFile(IMavenConstants.POM_FILE_NAME).getFullPath() .toPortableString(); @@ -307,11 +301,10 @@ public Object[] getElements(Object inputElement) { @Override public String getMavenText() { String executionId = null; - if(requirement instanceof MojoExecutionMappingRequirement) { - executionId = ((MojoExecutionMappingRequirement) requirement).getExecutionId(); - } else if(requirement instanceof ProjectConfiguratorMappingRequirement) { - executionId = ((ProjectConfiguratorMappingRequirement) requirement).getExecution() - .getExecutionId(); + if(requirement instanceof MojoExecutionMappingRequirement mojo) { + executionId = mojo.getExecutionId(); + } else if(requirement instanceof ProjectConfiguratorMappingRequirement conf) { + executionId = conf.getExecution().getExecutionId(); } if(executionId != null) { @@ -365,8 +358,8 @@ public Collection getProjects() { @Override public Object[] getChildren(Object parentElement) { - if(parentElement instanceof AggregateMappingLabelProvider) { - return ((AggregateMappingLabelProvider) parentElement).getChildren(); + if(parentElement instanceof AggregateMappingLabelProvider prov) { + return prov.getChildren(); } return new Object[0]; } @@ -404,13 +397,12 @@ public void addListener(ILabelProviderListener listener) { @Override public String getColumnText(Object element, int columnIndex) { - if(element instanceof ILifecycleMappingLabelProvider) { - ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) element; + if(element instanceof ILifecycleMappingLabelProvider prov) { if(columnIndex == MAVEN_INFO_IDX) { String text = prov.getMavenText(); - if(prov instanceof AggregateMappingLabelProvider && !isHandled(prov)) { + if(prov instanceof AggregateMappingLabelProvider aggProv && !isHandled(prov)) { text = NLS.bind(Messages.LifecycleMappingPage_errorMavenBuild, - new String[] {text, String.valueOf(((AggregateMappingLabelProvider) prov).getChildren().length)}); + new String[] {text, String.valueOf(aggProv.getChildren().length)}); } return text; } else if(columnIndex == ACTION_INFO_IDX && element instanceof AggregateMappingLabelProvider) { @@ -438,8 +430,7 @@ public Image getColumnImage(Object element, int columnIndex) { if(columnIndex != 0) { return null; } - if(element instanceof AggregateMappingLabelProvider) { - ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) element; + if(element instanceof AggregateMappingLabelProvider prov) { if(prov.isError(mappingConfiguration)) { if(!isHandled(prov)) { return MavenImages.IMG_ERROR; @@ -452,10 +443,8 @@ public Image getColumnImage(Object element, int columnIndex) { }); treeViewer.addSelectionChangedListener(event -> { - if(event.getSelection() instanceof IStructuredSelection - && ((IStructuredSelection) event.getSelection()).size() == 1) { - ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) ((IStructuredSelection) event - .getSelection()).getFirstElement(); + if(event.getSelection() instanceof IStructuredSelection structuredSelection && structuredSelection.size() == 1) { + ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) structuredSelection.getFirstElement(); if(ignore.contains(prov)) { details.setText(Messages.LifecycleMappingPage_doNotExecutePomDescription); license.setText(EMPTY_STRING); @@ -562,9 +551,10 @@ protected boolean shouldDeslectProposal(ILifecycleMappingLabelProvider prov) { if(proposal != null) { TreeItem[] items = treeViewer.getTree().getItems(); for(TreeItem item : items) { - if(item.getData() instanceof ILifecycleMappingLabelProvider && item.getData() != prov) { + if(item.getData() instanceof ILifecycleMappingLabelProvider lifecycleMappingProvider + && item.getData() != prov) { if(proposal.equals( - mappingConfiguration.getSelectedProposal(((ILifecycleMappingLabelProvider) item.getData()).getKey()))) { + mappingConfiguration.getSelectedProposal(lifecycleMappingProvider.getKey()))) { return false; } } @@ -677,8 +667,8 @@ private void updateErrorCount() { for(TreeItem item : treeViewer.getTree().getItems()) { ILifecycleMappingLabelProvider prov = (ILifecycleMappingLabelProvider) item.getData(); if(!isHandled(prov)) { - if(prov instanceof AggregateMappingLabelProvider) { - count += ((AggregateMappingLabelProvider) prov).getChildren().length; + if(prov instanceof AggregateMappingLabelProvider aggProv) { + count += aggProv.getChildren().length; } else { ++count; } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDependenciesWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDependenciesWizardPage.java index 58d92fb138..ae250055de 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDependenciesWizardPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDependenciesWizardPage.java @@ -130,15 +130,15 @@ private void createArtifacts(Composite composite) { org.eclipse.m2e.core.ui.internal.Messages.MavenDependenciesWizardPage_searchDialog_title, null, null, false); if(dialog.open() == Window.OK) { Object result = dialog.getFirstResult(); - if(result instanceof IndexedArtifactFile) { - Dependency dependency = ((IndexedArtifactFile) result).getDependency(); + if(result instanceof IndexedArtifactFile indexArtifactFile) { + Dependency dependency = indexArtifactFile.getDependency(); dependency.setScope(dialog.getSelectedScope()); dependencyViewer.add(dependency); notifyListeners(); - } else if(result instanceof IndexedArtifact) { + } else if(result instanceof IndexedArtifact indexArtifact) { // If we have an ArtifactInfo, we add the first FileInfo it contains // which corresponds to the latest version of the artifact. - Set files = ((IndexedArtifact) result).getFiles(); + Set files = indexArtifact.getFiles(); if(files != null && !files.isEmpty()) { dependencyViewer.add(files.iterator().next().getDependency()); notifyListeners(); @@ -233,8 +233,7 @@ public static class ArtifactLabelProvider extends LabelProvider { */ @Override public String getText(Object element) { - if(element instanceof Dependency) { - Dependency d = (Dependency) element; + if(element instanceof Dependency d) { return d.getGroupId() + ":" + d.getArtifactId() + ":" + d.getVersion() //$NON-NLS-1$//$NON-NLS-2$ + (d.getClassifier() == null ? "" : ":" + d.getClassifier()); //$NON-NLS-1$ //$NON-NLS-2$ } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDiscoveryProposalWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDiscoveryProposalWizard.java index f8b15235d3..e0d240ab55 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDiscoveryProposalWizard.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenDiscoveryProposalWizard.java @@ -139,25 +139,25 @@ public void run(IProgressMonitor monitor) { List changed = new LinkedList<>(); for(ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnore()) { ILifecycleMappingRequirement req = prov.getKey(); - if(req instanceof MojoExecutionMappingRequirement) { + if(req instanceof MojoExecutionMappingRequirement mojo) { changed.addAll(getProject(prov.getProjects())); - ignore(((MojoExecutionMappingRequirement) req).getExecution(), prov.getProjects()); + ignore(mojo.getExecution(), prov.getProjects()); } } for(ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnoreParent()) { ILifecycleMappingRequirement req = prov.getKey(); - if(req instanceof MojoExecutionMappingRequirement) { + if(req instanceof MojoExecutionMappingRequirement mojo) { changed.addAll(getProject(prov.getProjects())); - ignoreAtDefinition(((MojoExecutionMappingRequirement) req).getExecution(), prov.getProjects()); + ignoreAtDefinition(mojo.getExecution(), prov.getProjects()); } } for(ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnoreWorkspace()) { ILifecycleMappingRequirement req = prov.getKey(); - if(req instanceof MojoExecutionMappingRequirement) { + if(req instanceof MojoExecutionMappingRequirement mojo) { changed.addAll(getProject(prov.getProjects())); - ignoreWorkspace(((MojoExecutionMappingRequirement) req).getExecution()); + ignoreWorkspace(mojo.getExecution()); } } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java index e4b1f32fef..07eba25542 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java @@ -262,8 +262,7 @@ public Object[] getChildren(Object parentElement) { @SuppressWarnings("unchecked") List projects = (List) parentElement; return projects.toArray(new MavenProjectInfo[projects.size()]); - } else if(parentElement instanceof MavenProjectInfo) { - MavenProjectInfo mavenProjectInfo = (MavenProjectInfo) parentElement; + } else if(parentElement instanceof MavenProjectInfo mavenProjectInfo) { Collection projects = mavenProjectInfo.getProjects(); return projects.toArray(new MavenProjectInfo[projects.size()]); } @@ -277,11 +276,9 @@ public Object getParent(Object element) { @Override public boolean hasChildren(Object parentElement) { - if(parentElement instanceof List) { - List projects = (List) parentElement; + if(parentElement instanceof List projects) { return !projects.isEmpty(); - } else if(parentElement instanceof MavenProjectInfo) { - MavenProjectInfo mavenProjectInfo = (MavenProjectInfo) parentElement; + } else if(parentElement instanceof MavenProjectInfo mavenProjectInfo) { return !mavenProjectInfo.getProjects().isEmpty(); } return false; @@ -407,10 +404,9 @@ public void scanProjects() { StringBuilder sb = new StringBuilder(NLS.bind(Messages.wizardImportPageScanningErrors, errors.size())); int n = 1; for(Throwable ex : errors) { - if(ex instanceof CoreException) { - String msg = ((CoreException) ex).getStatus().getMessage(); + if(ex instanceof CoreException coreEx) { + String msg = coreEx.getStatus().getMessage(); sb.append("\n ").append(n).append(" ").append(msg.trim()); //$NON-NLS-1$ //$NON-NLS-2$ - } else { String msg = ex.getMessage() == null ? ex.toString() : ex.getMessage(); sb.append("\n ").append(n).append(" ").append(msg.trim()); //$NON-NLS-1$ //$NON-NLS-2$ @@ -512,8 +508,7 @@ void setAllChecked(boolean state) { void updateCheckedState() { Object[] elements = projectTreeViewer.getCheckedElements(); for(Object element : elements) { - if(element instanceof MavenProjectInfo) { - MavenProjectInfo info = (MavenProjectInfo) element; + if(element instanceof MavenProjectInfo info) { if(isWorkspaceFolder(info) || isAlreadyExists(info)) { projectTreeViewer.setChecked(info, false); } @@ -654,8 +649,8 @@ protected void validate() { } Object[] elements = projectTreeViewer.getCheckedElements(); for(Object element : elements) { - if(element instanceof MavenProjectInfo) { - String errorMsg = validateProjectInfo((MavenProjectInfo) element); + if(element instanceof MavenProjectInfo info) { + String errorMsg = validateProjectInfo(info); if(errorMsg != null) { setPageComplete(false); return; @@ -687,8 +682,7 @@ class ProjectLabelProvider extends LabelProvider implements IColorProvider, @Override public String getText(Object element) { - if(element instanceof MavenProjectInfo) { - MavenProjectInfo info = (MavenProjectInfo) element; + if(element instanceof MavenProjectInfo info) { if(info.getProfiles().isEmpty()) { return info.getLabel() + " - " + getId(info); //$NON-NLS-1$ @@ -728,8 +722,7 @@ private String getId(MavenProjectInfo info) { @Override public Color getForeground(Object element) { - if(element instanceof MavenProjectInfo) { - MavenProjectInfo info = (MavenProjectInfo) element; + if(element instanceof MavenProjectInfo info) { if(isWorkspaceFolder(info)) { return Display.getDefault().getSystemColor(SWT.COLOR_RED); } else if(isAlreadyExists(info)) { @@ -746,8 +739,7 @@ public Color getBackground(Object element) { @Override public StyledString getStyledText(Object element) { - if(element instanceof MavenProjectInfo) { - MavenProjectInfo info = (MavenProjectInfo) element; + if(element instanceof MavenProjectInfo info) { StyledString ss = new StyledString(); ss.append(info.getLabel() + " "); //$NON-NLS-1$ ss.append(getId(info), StyledString.DECORATIONS_STYLER); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenInstallFileWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenInstallFileWizard.java index 9e2cad0797..4a4bd6cb6f 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenInstallFileWizard.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenInstallFileWizard.java @@ -121,8 +121,8 @@ public boolean performFinish() { @Override public void init(IWorkbench workbench, IStructuredSelection selection) { Object element = selection.getFirstElement(); - if(element instanceof IFile) { - selectedFile = (IFile) element; + if(element instanceof IFile file) { + selectedFile = file; } } } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenModuleWizardParentPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenModuleWizardParentPage.java index 133cda1fe3..94d42bf26b 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenModuleWizardParentPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenModuleWizardParentPage.java @@ -212,8 +212,8 @@ protected void loadParent() { pom = project.getFile(IMavenConstants.POM_FILE_NAME); workingSetGroup.selectWorkingSets(WorkingSets.getAssignedWorkingSets(project)); - } else if(parentObject instanceof IContainer) { - pom = ((IContainer) parentObject).getFile(new Path(IMavenConstants.POM_FILE_NAME)); + } else if(parentObject instanceof IContainer container) { + pom = container.getFile(new Path(IMavenConstants.POM_FILE_NAME)); } if(pom != null && pom.exists()) { diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomSelectionComponent.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomSelectionComponent.java index 6360e4627c..8cb72b5d04 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomSelectionComponent.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomSelectionComponent.java @@ -312,8 +312,8 @@ void setStatus(int severity, String message) { public IndexedArtifact getIndexedArtifact() { IStructuredSelection selection = (IStructuredSelection) searchResultViewer.getSelection(); Object element = selection.getFirstElement(); - if(element instanceof IndexedArtifact) { - return (IndexedArtifact) element; + if(element instanceof IndexedArtifact indexedArtifact) { + return indexedArtifact; } TreeItem[] treeItems = searchResultViewer.getTree().getSelection(); if(treeItems.length == 0) { @@ -331,10 +331,9 @@ public IndexedArtifactFile getIndexedArtifactFile() { List getSelectedIndexedArtifactFiles(IStructuredSelection selection) { ArrayList result = new ArrayList<>(); for(Object element : selection.toList()) { - if(element instanceof IndexedArtifact) { + if(element instanceof IndexedArtifact ia) { //the idea here is that if we have a managed version for something, then the IndexedArtifact shall //represent that value.. - IndexedArtifact ia = (IndexedArtifact) element; if(managedKeys.contains(getKey(ia))) { for(IndexedArtifactFile file : ia.getFiles()) { if(managedKeys.contains(getKey(file))) { @@ -356,8 +355,8 @@ List getSelectedIndexedArtifactFiles(IStructuredSelection s result.add(ia.getFiles().iterator().next()); } } - } else if(element instanceof IndexedArtifactFile) { - result.add((IndexedArtifactFile) element); + } else if(element instanceof IndexedArtifactFile indexedArtifactFile) { + result.add(indexedArtifactFile); } } @@ -481,13 +480,11 @@ protected String getRepoDisplayName(String repo) { @Override public Color getForeground(Object element) { - if(element instanceof IndexedArtifactFile) { - IndexedArtifactFile f = (IndexedArtifactFile) element; + if(element instanceof IndexedArtifactFile f) { if(artifactKeys.contains(getKey(f))) { return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); } - } else if(element instanceof IndexedArtifact) { - IndexedArtifact i = (IndexedArtifact) element; + } else if(element instanceof IndexedArtifact i) { if(artifactKeys.contains(getKey(i))) { return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); } @@ -513,8 +510,7 @@ public Image getImage(Object element) { // return MavenImages.IMG_VERSION_SRC; // } return MavenImages.IMG_VERSION; - } else if(element instanceof IndexedArtifact) { - IndexedArtifact i = (IndexedArtifact) element; + } else if(element instanceof IndexedArtifact i) { if(managedKeys.contains(getKey(i))) { return MavenImages.getOverlayImage(MavenImages.PATH_JAR, MavenImages.PATH_LOCK, IDecoration.BOTTOM_LEFT); } @@ -528,8 +524,7 @@ public Image getImage(Object element) { */ @Override public StyledString getStyledText(Object element) { - if(element instanceof IndexedArtifact) { - IndexedArtifact a = (IndexedArtifact) element; + if(element instanceof IndexedArtifact a) { String name = (a.getClassname() == null ? "" : a.getClassname() + " " + a.getPackageName() + " ") + a.getGroupId() + " " + a.getArtifactId(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ StyledString ss = new StyledString(); ss.append(name); @@ -537,8 +532,7 @@ public StyledString getStyledText(Object element) { ss.append(Messages.MavenPomSelectionComponent_managed_decoration, StyledString.DECORATIONS_STYLER); } return ss; - } else if(element instanceof IndexedArtifactFile) { - IndexedArtifactFile f = (IndexedArtifactFile) element; + } else if(element instanceof IndexedArtifactFile f) { StyledString ss = new StyledString(); String name = f.version + " [" + (f.type == null ? "jar" : f.type) + (f.classifier != null ? ", " + f.classifier : "") + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ @@ -562,16 +556,15 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @Override public Object[] getElements(Object inputElement) { - if(inputElement instanceof Map) { - return ((Map) inputElement).values().toArray(); + if(inputElement instanceof Map map) { + return map.values().toArray(); } return EMPTY; } @Override public Object[] getChildren(Object parentElement) { - if(parentElement instanceof IndexedArtifact) { - IndexedArtifact a = (IndexedArtifact) parentElement; + if(parentElement instanceof IndexedArtifact a) { return a.getFiles().toArray(); } return EMPTY; diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomWizardPage.java index e5f4998173..f2845a6c9e 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomWizardPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomWizardPage.java @@ -96,27 +96,21 @@ public void createControl(Composite parent) { private void initialize() { String packagingToUse = MavenArtifactComponent.DEFAULT_PACKAGING; String[] availablePackagingTypes = MavenArtifactComponent.PACKAGING_OPTIONS; - if(selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) selection; + if(selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection ssel) { if(ssel.size() > 1) { return; } Object obj = ssel.getFirstElement(); - if(obj instanceof IResource) { - IContainer container; - if(obj instanceof IContainer) { - container = (IContainer) obj; - } else { - container = ((IResource) obj).getParent(); - } + if(obj instanceof IResource resource) { + IContainer container = obj instanceof IContainer c ? c : resource.getParent(); projectText.setText(container.getFullPath().toString()); pomComponent.setArtifactId(container.getName()); pomComponent.setGroupId(container.getName()); - if(container instanceof IProject) { + if(container instanceof IProject project) { IProjectConversionManager pcm = MavenPlugin.getProjectConversionManager(); - projectConversionEnabler = pcm.getConversionEnablerForProject((IProject) container); + projectConversionEnabler = pcm.getConversionEnablerForProject(project); if(projectConversionEnabler != null) { - availablePackagingTypes = projectConversionEnabler.getPackagingTypes((IProject) container); + availablePackagingTypes = projectConversionEnabler.getPackagingTypes(project); packagingToUse = availablePackagingTypes[0]; } } @@ -213,8 +207,8 @@ void dialogChanged() { return; } - if(container instanceof IProject && projectConversionEnabler != null) { - IStatus status = projectConversionEnabler.canBeConverted((IProject) container); + if(container instanceof IProject project && projectConversionEnabler != null) { + IStatus status = projectConversionEnabler.canBeConverted(project); if(status.getSeverity() == IStatus.ERROR) { updateStatus(status.getMessage()); return; diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectSelectionDialog.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectSelectionDialog.java index bce8a6cce3..0d37ab16a4 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectSelectionDialog.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectSelectionDialog.java @@ -131,8 +131,8 @@ protected static class MavenContainerContentProvider implements ITreeContentProv /** Returns the children of the parent node. */ @Override public Object[] getChildren(Object parent) { - if(parent instanceof IWorkspace) { - IProject[] projects = ((IWorkspace) parent).getRoot().getProjects(); + if(parent instanceof IWorkspace workspace) { + IProject[] projects = workspace.getRoot().getProjects(); List children = new ArrayList<>(); for(IProject project : projects) { @@ -145,15 +145,14 @@ public Object[] getChildren(Object parent) { } } return children.toArray(); - } else if(parent instanceof IContainer) { - IContainer container = (IContainer) parent; + } else if(parent instanceof IContainer container) { if(container.isAccessible()) { try { List children = new ArrayList<>(); IResource[] members = container.members(); for(IResource member : members) { - if(member instanceof IContainer - && ((IContainer) member).exists(new Path(IMavenConstants.POM_FILE_NAME))) { + if(member instanceof IContainer memberContainer + && memberContainer.exists(new Path(IMavenConstants.POM_FILE_NAME))) { children.add(member); } } @@ -169,8 +168,8 @@ public Object[] getChildren(Object parent) { /** Returns the parent of the given element. */ @Override public Object getParent(Object element) { - if(element instanceof IResource) { - return ((IResource) element).getParent(); + if(element instanceof IResource resource) { + return resource.getParent(); } return null; } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypePage.java index 61a2a484a4..496a2153ae 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypePage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypePage.java @@ -36,11 +36,11 @@ import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; +import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.IElementComparer; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; @@ -194,32 +194,15 @@ private void createViewer(Composite parent) { catalogsComboViewer = new ComboViewer(catalogsComposite); catalogsComboViewer.getControl().setData("name", "catalogsCombo"); //$NON-NLS-1$ //$NON-NLS-2$ catalogsComboViewer.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - catalogsComboViewer.setContentProvider(new IStructuredContentProvider() { - @Override - public Object[] getElements(Object input) { - - if(input instanceof Collection) { - return ((Collection) input).toArray(); - } - return new Object[0]; - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - @Override - public void dispose() { - } - }); + catalogsComboViewer.setContentProvider(new ArrayContentProvider()); catalogsComboViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { - if(element instanceof ArchetypeCatalogFactory) { - return ((ArchetypeCatalogFactory) element).getDescription(); - } else if(element instanceof String) { - return element.toString(); + if(element instanceof ArchetypeCatalogFactory archetypeCatalogFactory) { + return archetypeCatalogFactory.getDescription(); + } else if(element instanceof String s) { + return s; } return super.getText(element); } @@ -229,11 +212,11 @@ public String getText(Object element) { ISelection selection = event.getSelection(); boolean loadAll = false; //hide previous archetypes when switching catalog - if(selection instanceof IStructuredSelection) { - Object factory = ((IStructuredSelection) selection).getFirstElement(); + if(selection instanceof IStructuredSelection structuredSelection) { + Object factory = structuredSelection.getFirstElement(); ArchetypeCatalogFactory newCatalogFactory = null; - if(factory instanceof ArchetypeCatalogFactory) { - newCatalogFactory = (ArchetypeCatalogFactory) factory; + if(factory instanceof ArchetypeCatalogFactory archetypeCatalogFactory) { + newCatalogFactory = archetypeCatalogFactory; } if(factory != null && newCatalogFactory == null) { loadAll = true; @@ -383,40 +366,23 @@ public int compare(Viewer viewer, Object e1, Object e2) { viewer.setComparer(new IElementComparer() { @Override public int hashCode(Object obj) { - if(obj instanceof Archetype) { - return ArchetypeUtil.getHashCode((Archetype) obj); + if(obj instanceof Archetype archetype) { + return ArchetypeUtil.getHashCode(archetype); } return obj.hashCode(); } @Override public boolean equals(Object one, Object another) { - if(one instanceof Archetype && another instanceof Archetype) { - return ArchetypeUtil.areEqual((Archetype) one, (Archetype) another); + if(one instanceof Archetype first && another instanceof Archetype second) { + return ArchetypeUtil.areEqual(first, second); } return one.equals(another); } }); viewer.setFilters(versionFilter, quickViewerFilter); - - viewer.setContentProvider(new IStructuredContentProvider() { - @Override - public Object[] getElements(Object inputElement) { - if(inputElement instanceof Collection) { - return ((Collection) inputElement).toArray(); - } - return new Object[0]; - } - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - }); + viewer.setContentProvider(new ArrayContentProvider()); viewer.addSelectionChangedListener(event -> { Archetype archetype = getArchetype(); @@ -882,8 +848,7 @@ protected static class ArchetypeLabelProvider extends LabelProvider implements I /** Returns the element text */ @Override public String getColumnText(Object element, int columnIndex) { - if(element instanceof Archetype) { - Archetype archetype = (Archetype) element; + if(element instanceof Archetype archetype) { switch(columnIndex) { case 0: return archetype.getGroupId(); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypeParametersPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypeParametersPage.java index cb467a2243..1d9deb8600 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypeParametersPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypeParametersPage.java @@ -232,16 +232,16 @@ public boolean canModify(Object element, String property) { @Override public void modify(Object element, String property, Object value) { - if(element instanceof TableItem) { - ((TableItem) element).setText(getTextIndex(property), String.valueOf(value)); + if(element instanceof TableItem item) { + item.setText(getTextIndex(property), String.valueOf(value)); validate(); } } @Override public Object getValue(Object element, String property) { - if(element instanceof TableItem) { - return ((TableItem) element).getText(getTextIndex(property)); + if(element instanceof TableItem item) { + return item.getText(getTextIndex(property)); } return null; } @@ -380,8 +380,7 @@ void loadArchetypeDescriptor() { List properties = propertiesLoader.getProperties(); if(properties != null) { for(Object o : properties) { - if(o instanceof RequiredProperty) { - RequiredProperty rp = (RequiredProperty) o; + if(o instanceof RequiredProperty rp) { requiredProperties.add(rp.getKey()); addTableItem(rp.getKey(), rp.getDefaultValue()); } @@ -588,8 +587,8 @@ public void updatePropertyEditors() { TextComboBoxCellEditor comboEditor = null; // if there was a plain text editor previously defined, and the current // archetype has properties, replace it with a combo editor - if(ce[KEY_INDEX] instanceof TextComboBoxCellEditor) { - comboEditor = (TextComboBoxCellEditor) ce[KEY_INDEX]; + if(ce[KEY_INDEX] instanceof TextComboBoxCellEditor textComboCellEditor) { + comboEditor = textComboCellEditor; } else { ce[KEY_INDEX].dispose(); comboEditor = new TextComboBoxCellEditor(propertiesTable, SWT.FLAT); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardLocationPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardLocationPage.java index 5d32eb288a..cf8f5c2108 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardLocationPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardLocationPage.java @@ -294,9 +294,9 @@ protected void validate() { //this wizardpage is used in multiple wizards, not only in MavenProjectWizard // the other wizard don't seem to have any getModel() methods. //see MNGECLIPSE-1252 for more. - if(getWizard() instanceof MavenProjectWizard) { + if(getWizard() instanceof MavenProjectWizard mavenWizard) { String projectName = org.eclipse.m2e.core.internal.project.ProjectConfigurationManager - .getProjectName(getImportConfiguration(), ((MavenProjectWizard) getWizard()).getModel()); + .getProjectName(getImportConfiguration(), mavenWizard.getModel()); if(projectName.length() > 0) { final IStatus locationStatus = workspace.validateProjectLocation(workspace.getRoot().getProject(projectName), projectPath); diff --git a/org.eclipse.m2e.core/.classpath b/org.eclipse.m2e.core/.classpath index dfa5bf5642..7359b62f7e 100644 --- a/org.eclipse.m2e.core/.classpath +++ b/org.eclipse.m2e.core/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.m2e.core/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.core/.settings/org.eclipse.jdt.core.prefs index 8248cf2486..6a2a57cc59 100644 --- a/org.eclipse.m2e.core/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.m2e.core/.settings/org.eclipse.jdt.core.prefs @@ -29,9 +29,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable.secondary= org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -146,7 +146,7 @@ org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.source=17 org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,HIGH org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF index 1b3d7e7b0d..80ab780885 100644 --- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF @@ -15,7 +15,7 @@ Require-Bundle: org.eclipse.osgi;bundle-version="3.10.0", org.eclipse.core.filesystem;bundle-version="1.7.700", org.apache.commons.codec;bundle-version="1.14.0" Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Export-Package: org.eclipse.m2e.core, org.eclipse.m2e.core.archetype;x-friends:="org.eclipse.m2e.core.ui", org.eclipse.m2e.core.embedder, diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java index d386f0b125..c5e2233651 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java @@ -14,6 +14,7 @@ package org.eclipse.m2e.core.embedder; import java.io.Serializable; +import java.util.Objects; import org.eclipse.osgi.util.NLS; @@ -53,26 +54,15 @@ public ArtifactKey(String groupId, String artifactId, String version, String cla public boolean equals(Object o) { if(this == o) return true; - if(o instanceof ArtifactKey) { - ArtifactKey other = (ArtifactKey) o; - return equals(groupId, other.groupId) && equals(artifactId, other.artifactId) && equals(version, other.version) - && equals(classifier, other.classifier); - } - return false; + return o instanceof ArtifactKey other && // + + Objects.equals(groupId, other.groupId) && Objects.equals(artifactId, other.artifactId) + && Objects.equals(version, other.version) && Objects.equals(classifier, other.classifier); } @Override public int hashCode() { - int hash = 17; - hash = hash * 31 + (groupId != null ? groupId.hashCode() : 0); - hash = hash * 31 + (artifactId != null ? artifactId.hashCode() : 0); - hash = hash * 31 + (version != null ? version.hashCode() : 0); - hash = hash * 31 + (classifier != null ? classifier.hashCode() : 0); - return hash; - } - - private static boolean equals(Object o1, Object o2) { - return o1 == null ? o2 == null : o1.equals(o2); + return Objects.hash(groupId, artifactId, version, classifier); } // XXX this method does not belong here, it compares versions, while ArtifactKey uses baseVersions in many cases @@ -83,8 +73,8 @@ public static boolean equals(Artifact a1, Artifact a2) { if(a2 == null) { return false; } - return equals(a1.getGroupId(), a2.getGroupId()) && equals(a1.getArtifactId(), a2.getArtifactId()) - && equals(a1.getVersion(), a2.getVersion()) && equals(a1.getClassifier(), a2.getClassifier()); + return Objects.equals(a1.getGroupId(), a2.getGroupId()) && Objects.equals(a1.getArtifactId(), a2.getArtifactId()) + && Objects.equals(a1.getVersion(), a2.getVersion()) && Objects.equals(a1.getClassifier(), a2.getClassifier()); } @Override diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactRepositoryRef.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactRepositoryRef.java index e8ae2c02c3..f13c921c15 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactRepositoryRef.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactRepositoryRef.java @@ -14,6 +14,7 @@ package org.eclipse.m2e.core.embedder; import java.io.Serializable; +import java.util.Objects; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -48,11 +49,7 @@ public String getUsername() { @Override public int hashCode() { - int hash = 17; - hash = hash * 31 + (id != null ? id.hashCode() : 0); - hash = hash * 31 + (url != null ? url.hashCode() : 0); - hash = hash * 31 + (username != null ? username.hashCode() : 0); - return hash; + return Objects.hash(id, url, username); } @Override @@ -60,14 +57,7 @@ public boolean equals(Object o) { if(o == this) { return true; } - if(!(o instanceof ArtifactRepositoryRef)) { - return false; - } - ArtifactRepositoryRef other = (ArtifactRepositoryRef) o; - return eq(id, other.id) && eq(url, other.url) && eq(username, other.username); - } - - private static boolean eq(T a, T b) { - return a != null ? a.equals(b) : b == null; + return o instanceof ArtifactRepositoryRef other && // + Objects.equals(id, other.id) && Objects.equals(url, other.url) && Objects.equals(username, other.username); } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/M2EUtils.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/M2EUtils.java index 31b6407d31..5fc0ad444f 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/M2EUtils.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/M2EUtils.java @@ -114,8 +114,8 @@ public static IFile getPomFile(MavenProject project) { } while(path.segmentCount() > 1) { IResource ires = ResourcesPlugin.getWorkspace().getRoot().findMember(path); - if(ires instanceof IFile) { - stack.push((IFile) ires); + if(ires instanceof IFile f) { + stack.push(f); } path = path.removeFirstSegments(1); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java index ae174da051..d9422989d9 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java @@ -126,8 +126,8 @@ public Set build(MavenSession session, IMavenProjectFacade projectFaca participant.setGetDeltaCallback(getDeltaProvider()); participant.setSession(session); participant.setBuildContext((AbstractEclipseBuildContext) incrementalContexts.get(0)); - if(participant instanceof InternalBuildParticipant2) { - ((InternalBuildParticipant2) participant).setArgs(args); + if(participant instanceof InternalBuildParticipant2 participant2) { + participant2.setArgs(args); } long executionStartTime = System.currentTimeMillis(); try { @@ -146,8 +146,8 @@ public Set build(MavenSession session, IMavenProjectFacade projectFaca participant.setGetDeltaCallback(null); participant.setSession(null); participant.setBuildContext(null); - if(participant instanceof InternalBuildParticipant2) { - ((InternalBuildParticipant2) participant).setArgs(Collections. emptyMap()); + if(participant instanceof InternalBuildParticipant2 participant2) { + participant2.setArgs(Collections. emptyMap()); } processMavenSessionErrors(session, mojoExecutionKey, buildErrors); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java index aee7c10f03..7bbaa45959 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java @@ -74,8 +74,8 @@ protected IResource getResource(File file) { return null; } IResource baseResource = getBaseResource(); - if(baseResource instanceof IContainer) { - return ((IContainer) baseResource).findMember(relpath); + if(baseResource instanceof IContainer container) { + return container.findMember(relpath); } return null; } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java index 8f83c755ef..714c412c0a 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java @@ -91,8 +91,8 @@ protected void collectExtensions(IMavenLauncherConfiguration collector, IProgres if(extensions != null) { IMavenProjectRegistry registry = MavenPlugin.getMavenProjectRegistry(); for(ClasspathEntry entry : extensions) { - if(entry instanceof ProjectClasspathEntry) { - collectProject(collector, (ProjectClasspathEntry) entry, registry, monitor); + if(entry instanceof ProjectClasspathEntry projectClasspathEntry) { + collectProject(collector, projectClasspathEntry, registry, monitor); } } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/ClasspathEntry.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/ClasspathEntry.java index 8acc15b17c..78979c600b 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/ClasspathEntry.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/ClasspathEntry.java @@ -20,8 +20,8 @@ */ public abstract class ClasspathEntry { public String toExternalForm() { - if(this instanceof ProjectClasspathEntry) { - return "P/" + ((ProjectClasspathEntry) this).getProject(); + if(this instanceof ProjectClasspathEntry projectClasspathEntry) { + return "P/" + projectClasspathEntry.getProject(); } throw new IllegalArgumentException(); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java index c589a8a9f7..6395cb8364 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java @@ -147,8 +147,8 @@ public void setAppMain(String mainClassName, String mainRealmName) { try (FileInputStream is = new FileInputStream(getLauncherConfigurationFile())) { parser.parse(is); } catch(Exception e) { - if(e instanceof ExceptionWrapper && e.getCause() instanceof CoreException) { - throw (CoreException) e.getCause(); + if(e instanceof ExceptionWrapper && e.getCause() instanceof CoreException coreException) { + throw coreException; } throw new CoreException(Status.error(Messages.MavenExternalRuntime_error_cannot_parse, e)); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/AnnotationMappingMetadataSource.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/AnnotationMappingMetadataSource.java index ab095559c9..0fa6235140 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/AnnotationMappingMetadataSource.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/AnnotationMappingMetadataSource.java @@ -247,21 +247,19 @@ private static Xpp3Dom parse(String pi) { if(a == null) { return null; } - switch(a) { - case ignore: - return new Xpp3Dom("ignore"); //$NON-NLS-1$ - - case configurator: + return switch(a) { + case ignore -> new Xpp3Dom("ignore"); //$NON-NLS-1$ + case configurator -> { if(split.size() != 2) { - return null; + yield null; } Xpp3Dom conf = new Xpp3Dom("configurator"); //$NON-NLS-1$ Xpp3Dom id = new Xpp3Dom("id"); //$NON-NLS-1$ id.setValue(split.get(1)); conf.addChild(id); - return conf; - - case execute: + yield conf; + } + case execute -> { Xpp3Dom exec = new Xpp3Dom("execute"); //$NON-NLS-1$ if(split.size() > 1) { EXECUTE_SPLITTER.splitAsStream(split.get(1)).map(String::strip).map(EXECUTE_OPTIONS::get) @@ -271,11 +269,10 @@ private static Xpp3Dom parse(String pi) { exec.addChild(opt); }); } - return exec; - - default: - return null; - } + yield exec; + } + default -> null; + }; } private static PluginExecutionAction getAction(String value) { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java index 6bdc79c74d..1498159e2c 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java @@ -758,15 +758,11 @@ private static List applyParametersFilter(List true; + case configurator -> isConfigurator(metadata); + default -> false; + }; } static boolean isConfigurator(PluginExecutionMetadata metadata) { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java index 630cf23018..89404fac18 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java @@ -14,6 +14,8 @@ package org.eclipse.m2e.core.internal.lifecyclemapping.discovery; +import java.util.Objects; + import org.eclipse.core.runtime.Assert; import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; @@ -67,14 +69,7 @@ public boolean equals(Object obj) { return true; } - if(!(obj instanceof MojoExecutionMappingRequirement)) { - return false; - } - - MojoExecutionMappingRequirement other = (MojoExecutionMappingRequirement) obj; - - return execution.equals(other.execution); - + return obj instanceof MojoExecutionMappingRequirement other && execution.equals(other.execution); } /** @@ -118,13 +113,8 @@ public boolean equals(Object obj) { return true; } - if(!(obj instanceof ProjectConfiguratorMappingRequirement)) { - return false; - } - - ProjectConfiguratorMappingRequirement other = (ProjectConfiguratorMappingRequirement) obj; - - return configuratorId.equals(other.configuratorId) && execution.equals(other.execution); + return obj instanceof ProjectConfiguratorMappingRequirement other && configuratorId.equals(other.configuratorId) + && execution.equals(other.execution); } public MojoExecutionKey getExecution() { @@ -212,39 +202,31 @@ public boolean equals(Object obj) { if(this == obj) { return true; } - if(!(obj instanceof MojoExecutionMappingConfiguration)) { - return false; - } - MojoExecutionMappingConfiguration other = (MojoExecutionMappingConfiguration) obj; - - if(!execution.equals(other.execution)) { - return false; - } - - if(mapping == null) { - return other.mapping == null; - } - - if(other.mapping == null) { - return false; - } + if(obj instanceof MojoExecutionMappingConfiguration other) { + if(!execution.equals(other.execution)) { + return false; + } - if(mapping.getAction() != other.mapping.getAction()) { - return false; - } + if(mapping == null) { + return other.mapping == null; + } - if(mapping.getAction() == PluginExecutionAction.configurator) { - String configuratorId = LifecycleMappingFactory.getProjectConfiguratorId(mapping); - String otherConfiguratorId = LifecycleMappingFactory.getProjectConfiguratorId(other.mapping); - if(!eq(configuratorId, otherConfiguratorId)) { + if(other.mapping == null) { return false; } - } - return true; - } + if(mapping.getAction() != other.mapping.getAction()) { + return false; + } - private static boolean eq(T a, T b) { - return a != null ? a.equals(b) : b == null; + if(mapping.getAction() == PluginExecutionAction.configurator) { + String configuratorId = LifecycleMappingFactory.getProjectConfiguratorId(mapping); + String otherConfiguratorId = LifecycleMappingFactory.getProjectConfiguratorId(other.mapping); + if(!Objects.equals(configuratorId, otherConfiguratorId)) { + return false; + } + } + } + return false; } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/PackagingTypeMappingConfiguration.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/PackagingTypeMappingConfiguration.java index a6ba61be99..f11714b86e 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/PackagingTypeMappingConfiguration.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/PackagingTypeMappingConfiguration.java @@ -13,6 +13,8 @@ package org.eclipse.m2e.core.internal.lifecyclemapping.discovery; +import java.util.Objects; + /** * Represents project packaging type and corresponding lifecycle mapping metadata. */ @@ -36,13 +38,7 @@ public boolean equals(Object obj) { return true; } - if(!(obj instanceof PackagingTypeMappingRequirement)) { - return false; - } - - PackagingTypeMappingRequirement other = (PackagingTypeMappingRequirement) obj; - - return packaging.equals(other.packaging); + return obj instanceof PackagingTypeMappingRequirement other && packaging.equals(other.packaging); } public String getPackaging() { @@ -71,13 +67,8 @@ public boolean equals(Object obj) { return true; } - if(!(obj instanceof LifecycleStrategyMappingRequirement)) { - return false; - } - - LifecycleStrategyMappingRequirement other = (LifecycleStrategyMappingRequirement) obj; - - return lifecycleMappingId.equals(other.lifecycleMappingId); + return obj instanceof LifecycleStrategyMappingRequirement other + && lifecycleMappingId.equals(other.lifecycleMappingId); } public String getLifecycleMappingId() { @@ -127,17 +118,8 @@ public boolean equals(Object obj) { return true; } - if(!(obj instanceof PackagingTypeMappingConfiguration)) { - return false; - } - - PackagingTypeMappingConfiguration other = (PackagingTypeMappingConfiguration) obj; - - return packaging.equals(other.packaging) && eq(lifecycleMappingId, other.lifecycleMappingId); - } - - private static boolean eq(T a, T b) { - return a != null ? a.equals(b) : b == null; + return obj instanceof PackagingTypeMappingConfiguration other && // + packaging.equals(other.packaging) && Objects.equals(lifecycleMappingId, other.lifecycleMappingId); } @Override diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MavenMarkerManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MavenMarkerManager.java index cf6c9eb7d1..e936c58b0e 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MavenMarkerManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MavenMarkerManager.java @@ -194,17 +194,15 @@ private List toMavenProblemInfos(IResource pomResource, Source } for(Throwable ex : exceptions) { - if(ex instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) { - org.eclipse.aether.transfer.ArtifactNotFoundException artifactNotFoundException = (org.eclipse.aether.transfer.ArtifactNotFoundException) ex; + if(ex instanceof org.eclipse.aether.transfer.ArtifactNotFoundException artifactNotFoundException) { ArtifactNotFoundProblemInfo problem = new ArtifactNotFoundProblemInfo(artifactNotFoundException.getArtifact(), mavenConfiguration.isOffline(), location); result.add(problem); - } else if(ex instanceof AbstractArtifactResolutionException) { - AbstractArtifactResolutionException abstractArtifactResolutionException = (AbstractArtifactResolutionException) ex; + } else if(ex instanceof AbstractArtifactResolutionException abstractArtifactResolutionException) { String errorMessage = getArtifactId(abstractArtifactResolutionException) + " " + getRootErrorMessage(ex); //$NON-NLS-1$ result.add(new MavenProblemInfo(errorMessage, location)); - } else if(ex instanceof ProjectBuildingException) { - Collection modelProblems = getModelProblems((ProjectBuildingException)ex); + } else if(ex instanceof ProjectBuildingException projectBuildingException) { + Collection modelProblems = getModelProblems(projectBuildingException); if (modelProblems != null && !modelProblems.isEmpty()) { for(ModelProblem problem : modelProblems) { String message = NLS.bind(Messages.pluginMarkerBuildError, problem.getMessage()); @@ -225,8 +223,8 @@ private List toMavenProblemInfos(IResource pomResource, Source } private Collection getModelProblems(ProjectBuildingException ex) { - if (ex.getCause() instanceof ModelBuildingException) { - return ((ModelBuildingException)ex.getCause()).getProblems(); + if(ex.getCause() instanceof ModelBuildingException modelBuildingException) { + return modelBuildingException.getProblems(); } Set problems = new HashSet<>(); for(ProjectBuildingResult projectBuildingResult : ex.getResults()) { @@ -274,8 +272,7 @@ private void addMissingArtifactProblemInfos(MavenProject mavenProject, SourceLoc if(!mavenArtifact.isResolved()) { org.eclipse.aether.artifact.Artifact artifact = RepositoryUtils.toArtifact(mavenArtifact); for(MavenProblemInfo problem : knownProblems) { - if(problem instanceof ArtifactNotFoundProblemInfo) { - ArtifactNotFoundProblemInfo artifactNotFoundProblemInfo = (ArtifactNotFoundProblemInfo) problem; + if(problem instanceof ArtifactNotFoundProblemInfo artifactNotFoundProblemInfo) { if(equals(artifactNotFoundProblemInfo.getArtifact(), artifact)) { continue all_artifacts_loop; } @@ -290,8 +287,7 @@ private void addMissingArtifactProblemInfos(MavenProject mavenProject, SourceLoc @Override public void addErrorMarkers(IResource resource, String type, Throwable ex) { Throwable cause = getRootCause(ex); - if(cause instanceof CoreException) { - CoreException cex = (CoreException) cause; + if(cause instanceof CoreException cex) { IStatus status = cex.getStatus(); if(status != null) { addMarker(resource, type, status.getMessage(), 1, IMarker.SEVERITY_ERROR, false /*isTransient*/); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ArtifactKeyAdapterFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ArtifactKeyAdapterFactory.java index 85704869e7..2ded0400d4 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ArtifactKeyAdapterFactory.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ArtifactKeyAdapterFactory.java @@ -41,14 +41,12 @@ public T getAdapter(Object adaptable, Class adapterType) { } IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); - if(adaptable instanceof IProject) { - IProject project = (IProject) adaptable; + if(adaptable instanceof IProject project) { IMavenProjectFacade facade = projectManager.create(project, new NullProgressMonitor()); if(facade != null) { return adapterType.cast(facade.getArtifactKey()); } - } else if(adaptable instanceof IFile) { - IFile file = (IFile) adaptable; + } else if(adaptable instanceof IFile file) { if(IMavenConstants.POM_FILE_NAME.equals(file.getName())) { IMavenProjectFacade facade = projectManager.create(file, true, new NullProgressMonitor()); if(facade != null) { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/LifecycleMappingConfiguration.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/LifecycleMappingConfiguration.java index aa0c8b046c..2f043dcb50 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/LifecycleMappingConfiguration.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/LifecycleMappingConfiguration.java @@ -143,8 +143,8 @@ public static LifecycleMappingConfiguration restore(IMavenProjectFacade facade, File configFile = getConfigurationFile(facade.getProject()); try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(configFile))) { Object obj = ois.readObject(); - if(obj instanceof LifecycleMappingConfiguration) { - return (LifecycleMappingConfiguration) obj; + if(obj instanceof LifecycleMappingConfiguration lifecycleMappingConfiguration) { + return lifecycleMappingConfiguration; } } catch(ClassNotFoundException ex) { log.warn("Could not read persistent build lifecycle mapping configuration for {}.", facade.toString(), ex); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java index 21e39c7933..261ec19ff7 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java @@ -1024,8 +1024,8 @@ public ILifecycleMapping getLifecycleMapping(IMavenProjectFacade projectFacade) @Override public void resourceChanged(IResourceChangeEvent event) { - if(event.getType() == IResourceChangeEvent.PRE_DELETE && event.getResource() instanceof IProject) { - LifecycleMappingConfiguration.remove((IProject) event.getResource()); + if(event.getType() == IResourceChangeEvent.PRE_DELETE && event.getResource() instanceof IProject project) { + LifecycleMappingConfiguration.remove(project); } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/BasicProjectRegistry.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/BasicProjectRegistry.java index 825ba721c8..efba693bed 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/BasicProjectRegistry.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/BasicProjectRegistry.java @@ -95,12 +95,12 @@ protected final void replaceWith(BasicProjectRegistry other) { private static void copy(Map from, Map to) { for(Map.Entry entry : (Set) from.entrySet()) { Object value = entry.getValue(); - if(value instanceof Map) { + if(value instanceof Map mapValue) { Map map = new LinkedHashMap(); - copy((Map) value, map); + copy(mapValue, map); value = map; - } else if(value instanceof Set) { - Set set = new LinkedHashSet((Set) value); + } else if(value instanceof Set setValue) { + Set set = new LinkedHashSet(setValue); value = set; } to.put(entry.getKey(), value); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenCapability.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenCapability.java index 595e4a517e..3811311271 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenCapability.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenCapability.java @@ -68,11 +68,8 @@ public boolean equals(Object obj) { if(this == obj) { return true; } - if(!(obj instanceof MavenCapability)) { - return false; - } - MavenCapability other = (MavenCapability) obj; - return getVersionlessKey().equals(other.getVersionlessKey()) && version.equals(other.version); + return obj instanceof MavenCapability other && // + getVersionlessKey().equals(other.getVersionlessKey()) && version.equals(other.version); } public static MavenCapability createMavenArtifact(ArtifactKey key) { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenRequiredCapability.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenRequiredCapability.java index 4227a4ac88..58c72be653 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenRequiredCapability.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenRequiredCapability.java @@ -13,6 +13,8 @@ package org.eclipse.m2e.core.internal.project.registry; +import java.util.Objects; + import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; @@ -73,8 +75,9 @@ public static MavenRequiredCapability createResolvedMavenParent(ArtifactKey key) @Override public boolean isPotentialMatch(Capability capability, boolean narrowMatch) { - if(capability instanceof MavenCapability && getVersionlessKey().equals(capability.getVersionlessKey())) { - String version = ((MavenCapability) capability).getVersion(); + if(capability instanceof MavenCapability mavenCapability + && getVersionlessKey().equals(capability.getVersionlessKey())) { + String version = mavenCapability.getVersion(); // not interested in any version, but just in the resolved one if(resolved && narrowMatch) { @@ -120,12 +123,9 @@ public boolean equals(Object obj) { if(this == obj) { return true; } - if(!(obj instanceof MavenRequiredCapability)) { - return false; - } - MavenRequiredCapability other = (MavenRequiredCapability) obj; - return getVersionlessKey().equals(other.getVersionlessKey()) && versionRange.equals(other.versionRange) - && eq(scope, other.scope) && optional == other.optional; + return obj instanceof MavenRequiredCapability other && // + getVersionlessKey().equals(other.getVersionlessKey()) && versionRange.equals(other.versionRange) + && Objects.equals(scope, other.scope) && optional == other.optional; } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectFacadeAdapterFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectFacadeAdapterFactory.java index ba42437ab7..c9c0bfdef3 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectFacadeAdapterFactory.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectFacadeAdapterFactory.java @@ -31,8 +31,7 @@ public class ProjectFacadeAdapterFactory implements IAdapterFactory { @Override public T getAdapter(Object adaptableObject, Class adapterType) { - if(adaptableObject instanceof IResource) { - IResource resource = (IResource) adaptableObject; + if(adaptableObject instanceof IResource resource) { if(adapterType == IMavenProjectFacade.class) { return adapterType.cast(mavenProjectRegistry.getProject(resource.getProject())); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java index 263b13564a..864986f57e 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java @@ -697,8 +697,8 @@ private AbstractMavenDependencyResolver getMavenDependencyResolver(MavenProjectF IProgressMonitor monitor) { ILifecycleMapping lifecycleMapping = LifecycleMappingFactory.getLifecycleMapping(newFacade); - if(lifecycleMapping instanceof ILifecycleMapping2) { - AbstractMavenDependencyResolver resolver = ((ILifecycleMapping2) lifecycleMapping).getDependencyResolver(monitor); + if(lifecycleMapping instanceof ILifecycleMapping2 lifecycleMapping2) { + AbstractMavenDependencyResolver resolver = lifecycleMapping2.getDependencyResolver(monitor); resolver.setManager(this); return resolver; } @@ -1046,8 +1046,8 @@ MavenProject getMavenProject(MavenProjectFacade facade, IProgressMonitor monitor f -> readProjectWithDependencies(f.getPom(), f.getResolverConfiguration(), monitor))); } catch(RuntimeException ex) { // thrown by method called in lambda to carry CoreException Throwable cause = ex.getCause(); - if(cause instanceof CoreException) { - throw (CoreException) cause; + if(cause instanceof CoreException coreException) { + throw coreException; } throw new CoreException(Status.error("Unexpected internal Error occured", ex)); // this really should never happen } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryReader.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryReader.java index 994c3ad261..a745e8fee0 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryReader.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryReader.java @@ -84,10 +84,10 @@ private ObjectInputStream createObjectInputStream(ProjectRegistryManager manager @Override protected Object resolveObject(Object o) throws IOException { - if(o instanceof IPathReplace) { - return ((IPathReplace) o).getPath(); - } else if(o instanceof IFileReplace) { - return ((IFileReplace) o).getFile(); + if(o instanceof IPathReplace pathReplace) { + return pathReplace.getPath(); + } else if(o instanceof IFileReplace fileReplace) { + return fileReplace.getFile(); } else if(o instanceof MavenProjectManagerImplReplace) { return managerImpl; } @@ -132,10 +132,10 @@ private ObjectOutputStream createObjectOutputStream() throws IOException { @Override protected Object replaceObject(Object o) throws IOException { - if(o instanceof IPath) { - return new IPathReplace((IPath) o); - } else if(o instanceof IFile) { - return new IFileReplace((IFile) o); + if(o instanceof IPath path) { + return new IPathReplace(path); + } else if(o instanceof IFile file) { + return new IFileReplace(file); } else if(o instanceof ProjectRegistryManager) { return new MavenProjectManagerImplReplace(); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java index f5a3ab44e3..2f37a1bf79 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java @@ -249,8 +249,8 @@ public void preferenceChange(PreferenceChangeEvent event) { boolean offline = mavenConfiguration.isOffline(); boolean updateSnapshots = false; - if(event.getSource() instanceof IProject) { - queue(new MavenUpdateRequest((IProject) event.getSource(), offline, updateSnapshots)); + if(event.getSource() instanceof IProject project) { + queue(new MavenUpdateRequest(project, offline, updateSnapshots)); } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/RequiredCapability.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/RequiredCapability.java index a5f6043307..578c8c24a1 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/RequiredCapability.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/RequiredCapability.java @@ -49,7 +49,4 @@ public VersionlessKey getVersionlessKey() { */ public abstract boolean isPotentialMatch(Capability capability, boolean versionMatch); - protected static boolean eq(T a, T b) { - return a != null ? a.equals(b) : b == null; - } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/VersionlessKey.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/VersionlessKey.java index 69058075a1..208a440aca 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/VersionlessKey.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/VersionlessKey.java @@ -56,11 +56,8 @@ public boolean equals(Object obj) { if(obj == this) { return true; } - if(!(obj instanceof VersionlessKey)) { - return false; - } - VersionlessKey other = (VersionlessKey) obj; - return namespace.equals(other.namespace) && id.equals(other.id); + return obj instanceof VersionlessKey other && // + namespace.equals(other.namespace) && id.equals(other.id); } @Override diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenProjectInfo.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenProjectInfo.java index 91eb43fc27..86afa64460 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenProjectInfo.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenProjectInfo.java @@ -172,8 +172,7 @@ public Set getProfiles() { @Override public boolean equals(Object obj) { - if(obj instanceof MavenProjectInfo) { - MavenProjectInfo info = (MavenProjectInfo) obj; + if(obj instanceof MavenProjectInfo info) { if(pomFile == null) { return info.getPomFile() == null; } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenUpdateRequest.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenUpdateRequest.java index 13f48bfc96..f23e319906 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenUpdateRequest.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/MavenUpdateRequest.java @@ -127,13 +127,8 @@ public boolean equals(Object object) { return true; } - if(!(object instanceof MavenUpdateRequest)) { - return false; - } - - MavenUpdateRequest request = (MavenUpdateRequest) object; - - return this.offline == request.offline // + return object instanceof MavenUpdateRequest request && // + this.offline == request.offline // && this.forceDependencyUpdate == request.forceDependencyUpdate // && this.pomFiles.equals(request.pomFiles); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java index 410ba1e489..139d4c331e 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java @@ -85,8 +85,8 @@ public void configure(ProjectConfigurationRequest request, IProgressMonitor mon) if(directory != null) { IContainer container = projectFacade.getProject().getFolder(projectFacade.getProjectRelativePath(directory)); if(container != null) { - if(!container.exists() && container instanceof IFolder) { - M2EUtils.createFolder((IFolder) container, true, monitor.newChild(1)); + if(!container.exists() && container instanceof IFolder folder) { + M2EUtils.createFolder(folder, true, monitor.newChild(1)); } else { container.setDerived(true, monitor.newChild(1)); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/MojoExecutionKey.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/MojoExecutionKey.java index 33f3f46a8e..1961e2da5e 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/MojoExecutionKey.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/MojoExecutionKey.java @@ -14,6 +14,7 @@ package org.eclipse.m2e.core.project.configurator; import java.io.Serializable; +import java.util.Objects; import org.apache.maven.plugin.MojoExecution; @@ -69,14 +70,10 @@ public boolean equals(Object obj) { if(this == obj) { return true; } - if(!(obj instanceof MojoExecutionKey)) { - return false; - } - - MojoExecutionKey other = (MojoExecutionKey) obj; - - return eq(groupId, other.groupId) && eq(artifactId, other.artifactId) && eq(version, other.version) - && eq(goal, other.goal) && eq(executionId, other.executionId) && eq(lifecyclePhase, other.lifecyclePhase); + return obj instanceof MojoExecutionKey other && // + Objects.equals(groupId, other.groupId) && Objects.equals(artifactId, other.artifactId) + && Objects.equals(version, other.version) && Objects.equals(goal, other.goal) + && Objects.equals(executionId, other.executionId) && Objects.equals(lifecyclePhase, other.lifecyclePhase); } public String getGroupId() { @@ -121,8 +118,4 @@ public boolean match(MojoExecution mojoExecution) { && version.equals(mojoExecution.getVersion()) && goal.equals(mojoExecution.getGoal()) && executionId.equals(mojoExecution.getExecutionId()); } - - private static boolean eq(T a, T b) { - return a != null ? a.equals(b) : b == null; - } } diff --git a/org.eclipse.m2e.editor.lemminx/.classpath b/org.eclipse.m2e.editor.lemminx/.classpath index 685a6999c9..fe1a205326 100644 --- a/org.eclipse.m2e.editor.lemminx/.classpath +++ b/org.eclipse.m2e.editor.lemminx/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.m2e.editor.lemminx/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.editor.lemminx/.settings/org.eclipse.jdt.core.prefs index 7adc0fb9a0..d4540a53f9 100644 --- a/org.eclipse.m2e.editor.lemminx/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.m2e.editor.lemminx/.settings/org.eclipse.jdt.core.prefs @@ -1,10 +1,10 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.source=17 diff --git a/org.eclipse.m2e.editor.lemminx/META-INF/MANIFEST.MF b/org.eclipse.m2e.editor.lemminx/META-INF/MANIFEST.MF index e3a0bff671..14d8bc1c06 100644 --- a/org.eclipse.m2e.editor.lemminx/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.editor.lemminx/META-INF/MANIFEST.MF @@ -13,5 +13,5 @@ Require-Bundle: javax.inject, org.eclipse.lsp4j;bundle-version="0.9.0", org.eclipse.m2e.core, org.eclipse.m2e.maven.runtime -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-Vendor: Eclipse.org - m2e diff --git a/org.eclipse.m2e.editor/.classpath b/org.eclipse.m2e.editor/.classpath index 4a00becd81..3628e33687 100644 --- a/org.eclipse.m2e.editor/.classpath +++ b/org.eclipse.m2e.editor/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.m2e.editor/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.editor/.settings/org.eclipse.jdt.core.prefs index 30b95bdc46..70cb335670 100644 --- a/org.eclipse.m2e.editor/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.m2e.editor/.settings/org.eclipse.jdt.core.prefs @@ -28,9 +28,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul org.eclipse.jdt.core.compiler.annotation.nullable.secondary= org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -144,8 +144,8 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,HIGH org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX diff --git a/org.eclipse.m2e.editor/META-INF/MANIFEST.MF b/org.eclipse.m2e.editor/META-INF/MANIFEST.MF index 5b87d20246..8e3d701771 100644 --- a/org.eclipse.m2e.editor/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.editor/META-INF/MANIFEST.MF @@ -33,7 +33,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.m2e.model.edit;bundle-version="1.16.0", com.google.guava;bundle-version="30.1.0" Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-Vendor: %Bundle-Vendor Export-Package: org.eclipse.m2e.editor;x-friends:="org.eclipse.m2e.editor.xml", org.eclipse.m2e.editor.composites;x-friends:="org.eclipse.m2e.editor.xml", diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComparator.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComparator.java index f60fed03ad..a429f5d887 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComparator.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComparator.java @@ -35,8 +35,8 @@ public int compare(T o1, T o2) { } protected String[] toGAV(Object obj) { - if(obj instanceof Dependency) { - return toGAV((Dependency) obj); + if(obj instanceof Dependency dep) { + return toGAV(dep); } return toGAV((org.apache.maven.model.Dependency) obj); } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java index ff4058dbf4..248db80321 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java @@ -201,13 +201,11 @@ private void createDependenciesSection(SashForm verticalSash) { //TODO log return; } - for(Object dependency : dependencyList) { - if(dependency instanceof Dependency) { - Element dep = findChild(deps, DEPENDENCY, childEquals(GROUP_ID, ((Dependency) dependency).groupId), - childEquals(ARTIFACT_ID, ((Dependency) dependency).artifactId)); - removeChild(deps, dep); - } - } + dependencyList.stream() // + .filter(Dependency.class::isInstance).map(Dependency.class::cast) // + .map(dep -> findChild(deps, DEPENDENCY, childEquals(GROUP_ID, dep.groupId), + childEquals(ARTIFACT_ID, dep.artifactId))) // + .forEach(dep -> removeChild(deps, dep)); removeIfNoChildElement(deps); }, log, "error removing dependencies"); } finally { @@ -217,8 +215,7 @@ private void createDependenciesSection(SashForm verticalSash) { dependenciesEditor.setPropertiesListener(SelectionListener.widgetSelectedAdapter(e -> { Object selection = dependenciesEditor.getSelection().get(0); - if(selection instanceof Dependency) { - Dependency dependency = (Dependency) selection; + if(selection instanceof Dependency dependency) { EditDependencyDialog d = new EditDependencyDialog(getShell(), false, editorPage.getProject(), editorPage.getPomEditor().getMavenProject()); d.setDependency(toApacheDependency(dependency)); @@ -227,7 +224,7 @@ private void createDependenciesSection(SashForm verticalSash) { editorPage.performEditOperation(d.getEditOperation(), log, "Error updating dependency"); } finally { setDependenciesInput(); - dependenciesEditor.setSelection(Collections.singletonList((Object) dependency)); + dependenciesEditor.setSelection(Collections.singletonList(dependency)); } } } else if(selection instanceof org.apache.maven.model.Dependency) { @@ -623,11 +620,9 @@ public DependencyFilter(SearchMatcher searchMatcher) { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { - if(element instanceof Dependency) { - Dependency d = (Dependency) element; + if(element instanceof Dependency d) { return searchMatcher.isMatchingArtifact(d.groupId, d.artifactId); - } else if(element instanceof org.apache.maven.model.Dependency) { - org.apache.maven.model.Dependency dependency = (org.apache.maven.model.Dependency) element; + } else if(element instanceof org.apache.maven.model.Dependency dependency) { return searchMatcher.isMatchingArtifact(dependency.getGroupId(), dependency.getArtifactId()); } return false; diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java index 088ba1dea9..b109d4918e 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java @@ -28,7 +28,6 @@ import org.eclipse.swt.widgets.Display; import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.InputLocation; import org.apache.maven.project.MavenProject; @@ -142,9 +141,8 @@ private String[] findManaged(DependenciesComposite.Dependency dep) { @Override public StyledString getStyledText(Object element) { - if(element instanceof DependenciesComposite.Dependency) { + if(element instanceof DependenciesComposite.Dependency dep) { StyledString ss = new StyledString(getText(element)); - DependenciesComposite.Dependency dep = (DependenciesComposite.Dependency) element; String[] managed = findManaged(dep); if(managed != null && managed[0] != null) { String man = managed[0]; @@ -162,19 +160,15 @@ public StyledString getStyledText(Object element) { @Override public String getText(Object element) { - if(element instanceof DependenciesComposite.Dependency) { - DependenciesComposite.Dependency dependency = (DependenciesComposite.Dependency) element; + if(element instanceof DependenciesComposite.Dependency dependency) { return getText(dependency.groupId, dependency.artifactId, dependency.version, // dependency.classifier, dependency.type, dependency.scope); - } else if(element instanceof org.apache.maven.model.Dependency) { - org.apache.maven.model.Dependency dependency = (org.apache.maven.model.Dependency) element; + } else if(element instanceof org.apache.maven.model.Dependency dependency) { return getText(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getClassifier(), dependency.getType(), dependency.getScope()); -// } else if(element instanceof Exclusion) { -// Exclusion exclusion = (Exclusion) element; +// } else if(element instanceof Exclusion exclusion) { // return getText(exclusion.getGroupId(), exclusion.getArtifactId(), null, null, null, null); -// } else if(element instanceof Extension) { -// Extension extension = (Extension) element; +// } else if(element instanceof Extension extension) { // return getText(extension.getGroupId(), extension.getArtifactId(), extension.getVersion(), null, null, null); } return super.getText(element); @@ -182,25 +176,21 @@ public String getText(Object element) { @Override public Image getImage(Object element) { - if(element instanceof DependenciesComposite.Dependency) { - DependenciesComposite.Dependency dependency = (DependenciesComposite.Dependency) element; + if(element instanceof DependenciesComposite.Dependency dependency) { boolean isManaged = showManagedOverlay && findManaged(dependency) != null; return getImage(dependency.groupId, dependency.artifactId, dependency.version, isManaged); - } else if(element instanceof org.apache.maven.model.Dependency) { + } else if(element instanceof org.apache.maven.model.Dependency dependency) { if(!showManagedOverlay) { - org.apache.maven.model.Dependency dependency = (Dependency) element; //a workaround to handle display in ManagedDependenciesDialog //TODO shall have a switch of it's own.. the curse of blind code reuse return getImage(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), false); } //mkleint: all MavenDependency instances are inherited but only in *dependenciesComposite* return MavenEditorImages.IMG_INHERITED; -// }else if(element instanceof Exclusion) { -// Exclusion exclusion = (Exclusion) element; +// }else if(element instanceof Exclusion exclusion) { // return getImage(exclusion.getGroupId(), exclusion.getArtifactId(), null, false); -// } else if(element instanceof Extension) { -// Extension extension = (Extension) element; +// } else if(element instanceof Extension extension) { // return getImage(extension.getGroupId(), extension.getArtifactId(), extension.getVersion(), false); } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java index 15649e1083..94ff5d56c5 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java @@ -35,8 +35,7 @@ public class ListEditorContentProvider implements IStructuredContentProvider @Override @SuppressWarnings("unchecked") public Object[] getElements(Object input) { - if(input instanceof List) { - List list = (List) input; + if(input instanceof List list) { if(shouldSort) { T[] array = (T[]) list.toArray(); Arrays. sort(array, comparator); diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/SectionExpansionAdapter.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/SectionExpansionAdapter.java index eb70a0c6ef..b0edd31659 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/SectionExpansionAdapter.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/SectionExpansionAdapter.java @@ -35,9 +35,9 @@ public SectionExpansionAdapter(Section[] sections) { @Override public void expansionStateChanged(ExpansionEvent e) { - if(!inProgress && e.getSource() instanceof Section) { + if(!inProgress && e.getSource() instanceof Section sourceSection) { inProgress = true; - boolean expand = ((Section) e.getSource()).isExpanded(); + boolean expand = sourceSection.isExpanded(); for(Section section : sections) { section.setExpanded(expand); diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/StringLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/StringLabelProvider.java index c1dbf4fc45..5b2cd7edb1 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/StringLabelProvider.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/StringLabelProvider.java @@ -31,8 +31,8 @@ public StringLabelProvider(Image img) { @Override public String getText(Object element) { - if(element instanceof String) { - return (String) element; + if(element instanceof String s) { + return s; } return ""; //$NON-NLS-1$ } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java index f11836e84e..062d19d664 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java @@ -443,10 +443,10 @@ public static class DepLabelProvider extends LabelProvider implements IColorProv @Override public String getText(Object element) { MavenProject project = null; - if(element instanceof MavenProject) { - project = (MavenProject) element; - } else if(element instanceof Object[]) { - project = (MavenProject) ((Object[]) element)[0]; + if(element instanceof MavenProject mavenProject) { + project = mavenProject; + } else if(element instanceof Object[] array) { + project = (MavenProject) array[0]; } else { return ""; //$NON-NLS-1$ } @@ -459,8 +459,7 @@ public String getText(Object element) { @Override public Color getForeground(Object element) { - if(element instanceof MavenProject) { - MavenProject project = (MavenProject) element; + if(element instanceof MavenProject project) { IMavenProjectFacade search = MavenPlugin.getMavenProjectRegistry().getMavenProject(project.getGroupId(), project.getArtifactId(), project.getVersion()); if(search == null) { @@ -495,8 +494,7 @@ public boolean hasChildren(Object element) { @Override public Object getParent(Object element) { - if(element instanceof MavenProject) { - MavenProject project = (MavenProject) element; + if(element instanceof MavenProject project) { return project.getParent(); } return null; @@ -523,19 +521,17 @@ public Object[] getElements(Object inputElement) { @Override public Object[] getChildren(Object parentElement) { - if(parentElement instanceof MavenProject) { + if(parentElement instanceof MavenProject parent) { /* * Walk the hierarchy list until we find the parentElement and * return the previous element, which is the child. */ - MavenProject parent = (MavenProject) parentElement; - if(getProjectHierarchy().size() == 1) { //No parent exists, only one element in the tree return new Object[0]; } - if(getProjectHierarchy().get(0).equals(parent)) { + if(getProjectHierarchy().get(0).getProject().equals(parent)) { //We are the final child return new Object[0]; } @@ -543,7 +539,7 @@ public Object[] getChildren(Object parentElement) { ListIterator iter = getProjectHierarchy().listIterator(); while(iter.hasNext()) { ParentHierarchyEntry next = iter.next(); - if(next.equals(parent)) { + if(next.getProject().equals(parent)) { iter.previous(); ParentHierarchyEntry previous = iter.previous(); return new Object[] {previous}; diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/MavenModuleSelectionDialog.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/MavenModuleSelectionDialog.java index ce777fc321..c20745dfe3 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/MavenModuleSelectionDialog.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/MavenModuleSelectionDialog.java @@ -45,7 +45,7 @@ protected Control createDialogArea(Composite parent) { if(e.detail == SWT.CHECK) { TreeItem item = (TreeItem) e.item; Object data = item.getData(); - if(item.getChecked() && data instanceof IResource && knownModules.contains(((IResource) data).getLocation())) { + if(item.getChecked() && data instanceof IResource res && knownModules.contains(res.getLocation())) { item.setChecked(false); } } @@ -80,7 +80,7 @@ public Image getImage(Object element) { @Override public Color getForeground(Object element) { - if(element instanceof IResource && knownModules.contains(((IResource) element).getLocation())) { + if(element instanceof IResource res && knownModules.contains(res.getLocation())) { return Display.getDefault().getSystemColor(SWT.COLOR_GRAY); } return null; diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/FormHoverProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/FormHoverProvider.java index 9d8877c8e4..7dedb8faa7 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/FormHoverProvider.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/FormHoverProvider.java @@ -48,10 +48,7 @@ public static Consumer createHoverRunnable(final Shell parentShell, final Iterator it = sourceViewer.getAnnotationModel().getAnnotationIterator(); while(it.hasNext()) { Annotation ann = it.next(); - if(ann instanceof MarkerAnnotation) { - MarkerAnnotation mann = (MarkerAnnotation) ann; - if(markersSet.contains(mann.getMarker())) - ; + if(ann instanceof MarkerAnnotation mann) { compound.addRegion(new PomHyperlinkDetector.MarkerRegion(0, 0, mann)); } } @@ -64,8 +61,7 @@ public static Consumer createHoverRunnable(final Shell parentShell, final return; IInformationControl infoControl = mhc; - if(!infoControl.isFocusControl() && infoControl instanceof IInformationControlExtension3) { - IInformationControlExtension3 iControl3 = (IInformationControlExtension3) infoControl; + if(!infoControl.isFocusControl() && infoControl instanceof IInformationControlExtension3 iControl3) { Rectangle controlBounds = iControl3.getBounds(); if(controlBounds != null) { Point mouseLoc = event.display.map((Control) event.widget, null, event.x, event.y); diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/MarkerHoverControl.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/MarkerHoverControl.java index b12557dc96..91a4f7608f 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/MarkerHoverControl.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/MarkerHoverControl.java @@ -104,11 +104,7 @@ public MarkerHoverControl(Shell shell) { @Override public void setInput(Object input) { assert input instanceof CompoundRegion; - if(input instanceof CompoundRegion) { - region = (CompoundRegion) input; - } else { - throw new IllegalStateException("Not CompoundRegion"); //$NON-NLS-1$ - } + region = (CompoundRegion) input; disposeDeferredCreatedContent(); deferredCreateContent(); } @@ -209,8 +205,7 @@ public void handleEvent(Event e) { boolean lifecycleMarkers = false; for(IRegion reg : region.getRegions()) { - if(reg instanceof PomHyperlinkDetector.MarkerRegion) { - PomHyperlinkDetector.MarkerRegion markerReg = (PomHyperlinkDetector.MarkerRegion) reg; + if(reg instanceof PomHyperlinkDetector.MarkerRegion markerReg) { IMarker mark = markerReg.getAnnotation().getMarker(); if(MavenDiscoveryMarkerResolutionGenerator.canResolve(mark)) { lifecycleMarkers = true; @@ -221,8 +216,7 @@ public void handleEvent(Event e) { fillToolbar(lifecycleMarkers); for(IRegion reg : region.getRegions()) { - if(reg instanceof PomHyperlinkDetector.MarkerRegion) { - final PomHyperlinkDetector.MarkerRegion markerReg = (PomHyperlinkDetector.MarkerRegion) reg; + if(reg instanceof PomHyperlinkDetector.MarkerRegion markerReg) { createAnnotationInformation(composite, markerReg); final IMarker mark = markerReg.getAnnotation().getMarker(); @@ -231,8 +225,7 @@ public void handleEvent(Event e) { createResolutionsControl(composite, mark, resolutions); } } - if(reg instanceof ManagedArtifactRegion) { - final ManagedArtifactRegion man = (ManagedArtifactRegion) reg; + if(reg instanceof ManagedArtifactRegion man) { Composite comp = createTooltipComposite(composite, PomTextHover.getLabelForRegion(man)); //only create the hyperlink when the origin location for jumping is present. //in some cases (managed version comes from imported dependencies) we don't have the location and have nowhere to jump) @@ -245,8 +238,7 @@ public void handleEvent(Event e) { } } - if(reg instanceof ExpressionRegion) { - final ExpressionRegion expr = (ExpressionRegion) reg; + if(reg instanceof ExpressionRegion expr) { Composite tooltipComposite = createTooltipComposite(composite, PomTextHover.getLabelForRegion(expr)); if(PomHyperlinkDetector.canCreateHyperLink(expr)) { Link link = createHyperlink(tooltipComposite); @@ -335,8 +327,8 @@ private void setColorAndFont(Control control, Color foreground, Color background control.setBackground(background); control.setFont(font); - if(control instanceof Composite) { - Control[] children = ((Composite) control).getChildren(); + if(control instanceof Composite composite) { + Control[] children = composite.getChildren(); for(Control child : children) { setColorAndFont(child, foreground, background, font); } @@ -476,10 +468,10 @@ private Link createCompletionProposalLink(Composite parent, final IMarker mark, Label proposalImage = new Label(parent, SWT.NONE); proposalImage.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false)); Image image = null; - if(proposal instanceof ICompletionProposal) { - image = ((ICompletionProposal) proposal).getImage(); - } else if(proposal instanceof IMarkerResolution2) { - image = ((IMarkerResolution2) proposal).getImage(); + if(proposal instanceof ICompletionProposal completionProposal) { + image = completionProposal.getImage(); + } else if(proposal instanceof IMarkerResolution2 resolution) { + image = resolution.getImage(); } if(image != null) { proposalImage.setImage(image); @@ -515,8 +507,8 @@ public IInformationControlCreator getInformationPresenterControlCreator() { } private void apply(IMarkerResolution res, IMarker mark, ITextViewer viewer, int offset) { - if(res instanceof ICompletionProposal) { - apply((ICompletionProposal) res, viewer, offset, false); + if(res instanceof ICompletionProposal proposal) { + apply(proposal, viewer, offset, false); } else { dispose(); res.run(mark); @@ -531,19 +523,16 @@ private void apply(ICompletionProposal p, ITextViewer viewer, int offset, boolea try { IDocument document = viewer.getDocument(); - if(viewer instanceof ITextViewerExtension) { - ITextViewerExtension extension = (ITextViewerExtension) viewer; + if(viewer instanceof ITextViewerExtension extension) { target = extension.getRewriteTarget(); } if(target != null) target.beginCompoundChange(); - if(p instanceof ICompletionProposalExtension2) { - ICompletionProposalExtension2 e = (ICompletionProposalExtension2) p; + if(p instanceof ICompletionProposalExtension2 e) { e.apply(viewer, (char) 0, isMultiFix ? SWT.CONTROL : SWT.NONE, offset); - } else if(p instanceof ICompletionProposalExtension) { - ICompletionProposalExtension e = (ICompletionProposalExtension) p; + } else if(p instanceof ICompletionProposalExtension e) { e.apply(document, (char) 0, offset); } else { p.apply(document); diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/ShowDependencyHierarchyAction.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/ShowDependencyHierarchyAction.java index d311d100d9..8234b0b7ef 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/ShowDependencyHierarchyAction.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/ShowDependencyHierarchyAction.java @@ -43,8 +43,8 @@ public class ShowDependencyHierarchyAction extends ActionDelegate { @Override public void selectionChanged(IAction action, ISelection selection) { - if(selection instanceof IStructuredSelection) { - this.selection = (IStructuredSelection) selection; + if(selection instanceof IStructuredSelection structured) { + this.selection = structured; } else { this.selection = null; } @@ -71,8 +71,8 @@ private void showDependencyHierarchy(final ArtifactKey projectKey, final Artifac protected IStatus run(IProgressMonitor monitor) { final IEditorPart editor = OpenPomAction.openEditor(projectKey.getGroupId(), // projectKey.getArtifactId(), projectKey.getVersion(), monitor); - if(editor instanceof MavenPomEditor) { - Display.getDefault().asyncExec(() -> ((MavenPomEditor) editor).showDependencyHierarchy(artifactKey)); + if(editor instanceof MavenPomEditor pomEditor) { + Display.getDefault().asyncExec(() -> pomEditor.showDependencyHierarchy(artifactKey)); } return Status.OK_STATUS; } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/AbstractPomProblemResolution.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/AbstractPomProblemResolution.java index 5a7dd7c1c9..18514c4e35 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/AbstractPomProblemResolution.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/AbstractPomProblemResolution.java @@ -76,8 +76,7 @@ protected final void fix(IResource resource, List markers, IProgressMon } static String previewForRemovedElement(IDocument doc, Element removed) { - if(removed instanceof IndexedRegion) { - IndexedRegion reg = (IndexedRegion) removed; + if(removed instanceof IndexedRegion reg) { try { int maxl = doc.getNumberOfLines() - 1; diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/IdPartRemovalResolution.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/IdPartRemovalResolution.java index 55b0ccc0f3..31d7c0acd7 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/IdPartRemovalResolution.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/IdPartRemovalResolution.java @@ -90,9 +90,7 @@ protected void processFix(IStructuredDocument doc, Element root, List m //now check parent version and groupid against the current project's ones.. if(PROJECT_NODE.equals(root.getNodeName())) { Element value = XmlUtils.findChild(root, isVersion ? VERSION_NODE : GROUP_ID_NODE); - if(value instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) value; - + if(value instanceof IndexedRegion off) { int offset = off.getStartOffset(); if(offset <= 0) { return; diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/ManagedVersionRemovalResolution.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/ManagedVersionRemovalResolution.java index b7094c6c8f..ac21261191 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/ManagedVersionRemovalResolution.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/ManagedVersionRemovalResolution.java @@ -94,9 +94,7 @@ protected void processFix(IStructuredDocument doc, Element root, List m continue; } Element value = XmlUtils.findChild(artifact, VERSION_NODE); - if(value instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) value; - + if(value instanceof IndexedRegion off) { int offset = off.getStartOffset(); if(offset <= 0) { continue; diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/MarkerResolutionWrapper.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/MarkerResolutionWrapper.java index e977fd857c..8857ccb8b5 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/MarkerResolutionWrapper.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/MarkerResolutionWrapper.java @@ -47,8 +47,8 @@ public void apply(IDocument document) { @Override public String getAdditionalProposalInfo() { - if(resolution instanceof IMarkerResolution2) { - return ((IMarkerResolution2) resolution).getDescription(); + if(resolution instanceof IMarkerResolution2 resolution) { + return resolution.getDescription(); } String problemDesc = marker.getAttribute(IMarker.MESSAGE, null); return problemDesc; @@ -66,8 +66,8 @@ public String getDisplayString() { @Override public Image getImage() { - if(resolution instanceof IMarkerResolution2) { - return ((IMarkerResolution2) resolution).getImage(); + if(resolution instanceof IMarkerResolution2 resolution) { + return resolution.getImage(); } return null; //what is the default image here?? } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/SchemaCompletionResolution.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/SchemaCompletionResolution.java index f6b3efbb5b..9754eca98b 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/SchemaCompletionResolution.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/markers/SchemaCompletionResolution.java @@ -62,9 +62,7 @@ public String getDescription() { @Override protected void processFix(IStructuredDocument doc, Element root, List markers) { for(IMarker marker : markers) { - if(PROJECT_NODE.equals(root.getNodeName()) && root instanceof IndexedRegion) { - IndexedRegion off = (IndexedRegion) root; - + if(PROJECT_NODE.equals(root.getNodeName()) && root instanceof IndexedRegion off) { int offset = off.getStartOffset() + PROJECT_NODE.length() + 1; if(offset <= 0) { return; diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/mojo/MojoParameterMetadataProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/mojo/MojoParameterMetadataProvider.java index 0f3bbbd88c..e0686b16bf 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/mojo/MojoParameterMetadataProvider.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/mojo/MojoParameterMetadataProvider.java @@ -108,11 +108,11 @@ public MojoParameter getClassConfiguration(final ArtifactKey pluginKey, final St } catch(ExecutionException e) { Throwable t = e.getCause(); - if(t instanceof CoreException) { - throw (CoreException) t; + if(t instanceof CoreException coreEx) { + throw coreEx; } - if(t instanceof RuntimeException) { - throw (RuntimeException) t; + if(t instanceof RuntimeException runtimeEx) { + throw runtimeEx; } throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, e.getMessage(), e)); } @@ -162,11 +162,11 @@ public MojoParameter getMojoConfiguration(final ArtifactKey pluginKey, final Str } catch(ExecutionException e) { Throwable t = e.getCause(); - if(t instanceof CoreException) { - throw (CoreException) t; + if(t instanceof CoreException coreEx) { + throw coreEx; } - if(t instanceof RuntimeException) { - throw (RuntimeException) t; + if(t instanceof RuntimeException runtimeEx) { + throw runtimeEx; } throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, e.getMessage(), e)); } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/mojo/PlexusConfigHelper.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/mojo/PlexusConfigHelper.java index 3942d31b8e..083e708470 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/mojo/PlexusConfigHelper.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/mojo/PlexusConfigHelper.java @@ -227,11 +227,11 @@ public static MojoParameter configure(MojoParameter p, boolean required, String } public static Class getRawType(Type type) { - if(type instanceof Class) { - return (Class) type; + if(type instanceof Class clazz) { + return clazz; } - if(type instanceof ParameterizedType) { - return (Class) ((ParameterizedType) type).getRawType(); + if(type instanceof ParameterizedType parameterized) { + return (Class) parameterized.getRawType(); } return null; } @@ -247,9 +247,7 @@ public static Type getItemType(Type paramType) { return null; } - if(paramType instanceof ParameterizedType) { - ParameterizedType pt = (ParameterizedType) paramType; - + if(paramType instanceof ParameterizedType pt) { Type[] args = pt.getActualTypeArguments(); if(args.length > 0) { return args[0]; @@ -374,8 +372,7 @@ public static String getTypeDisplayName(Type type) { return getTypeDisplayName(clazz.getComponentType()) + "[]"; //$NON-NLS-1$ } - if(type instanceof ParameterizedType) { - ParameterizedType ptype = (ParameterizedType) type; + if(type instanceof ParameterizedType ptype) { StringBuilder sb = new StringBuilder(); sb.append(getTypeDisplayName(clazz)).append("<"); //$NON-NLS-1$ @@ -424,35 +421,16 @@ public String toSingularName(String name) { static { // @formatter:off - INLINE_TYPES = Set.of( - byte.class.getName(), - Byte.class.getName(), - short.class.getName(), - Short.class.getName(), - int.class.getName(), - Integer.class.getName(), - long.class.getName(), - Long.class.getName(), - float.class.getName(), - Float.class.getName(), - double.class.getName(), - Double.class.getName(), - boolean.class.getName(), - Boolean.class.getName(), - char.class.getName(), - Character.class.getName(), - - String.class.getName(), - StringBuilder.class.getName(), - StringBuffer.class.getName(), - - File.class.getName(), - URI.class.getName(), - URL.class.getName(), - Date.class.getName(), - - "org.codehaus.plexus.configuration.PlexusConfiguration" - ); + INLINE_TYPES = Set.of(byte.class.getName(), Byte.class.getName(), short.class.getName(), Short.class.getName(), + int.class.getName(), Integer.class.getName(), long.class.getName(), Long.class.getName(), float.class.getName(), + Float.class.getName(), double.class.getName(), Double.class.getName(), boolean.class.getName(), + Boolean.class.getName(), char.class.getName(), Character.class.getName(), + + String.class.getName(), StringBuilder.class.getName(), StringBuffer.class.getName(), + + File.class.getName(), URI.class.getName(), URL.class.getName(), Date.class.getName(), + + "org.codehaus.plexus.configuration.PlexusConfiguration"); // @formatter:on } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependencyTreePage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependencyTreePage.java index b3a80da3e8..2e341b13f3 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependencyTreePage.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependencyTreePage.java @@ -306,8 +306,8 @@ private void createHierarchySection(Composite sashForm, FormToolkit formToolkit) treeViewer.addOpenListener(event -> { IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); for(Object o : selection) { - if(o instanceof DependencyNode) { - org.eclipse.aether.artifact.Artifact a = ((DependencyNode) o).getDependency().getArtifact(); + if(o instanceof DependencyNode dep) { + org.eclipse.aether.artifact.Artifact a = dep.getDependency().getArtifact(); OpenPomAction.openEditor(a.getGroupId(), a.getArtifactId(), a.getVersion(), mavenProject, null); } } @@ -449,8 +449,7 @@ private void createListSection(SashForm sashForm, FormToolkit formToolkit) { listViewer.addOpenListener(event -> { IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection(); for(Object o : selection) { - if(o instanceof Artifact) { - Artifact a = (Artifact) o; + if(o instanceof Artifact a) { OpenPomAction.openEditor(a.getGroupId(), a.getArtifactId(), a.getVersion(), mavenProject, null); } } @@ -682,12 +681,10 @@ public DependencyFilter(Matcher matcher) { public boolean select(Viewer viewer, Object parentElement, Object element) { if(matcher != null && !matcher.isEmpty()) { // matcher = new TextMatcher(searchControl.getSearchText().getText()); - if(element instanceof Artifact) { - Artifact a = (Artifact) element; + if(element instanceof Artifact a) { return matcher.isMatchingArtifact(a.getGroupId(), a.getArtifactId()); - } else if(element instanceof DependencyNode) { - DependencyNode node = (DependencyNode) element; + } else if(element instanceof DependencyNode node) { org.eclipse.aether.artifact.Artifact a = node.getDependency().getArtifact(); if(matcher.isMatchingArtifact(a.getGroupId(), a.getArtifactId())) { return true; @@ -768,12 +765,7 @@ public Object[] getElements(Object input) { @Override public Object[] getChildren(Object element) { - if(element instanceof DependencyNode) { - DependencyNode node = (DependencyNode) element; - List children = node.getChildren(); - return children.toArray(new DependencyNode[children.size()]); - } - return new Object[0]; + return element instanceof DependencyNode node ? node.getChildren().toArray(DependencyNode[]::new) : new Object[0]; } @Override @@ -783,11 +775,7 @@ public Object getParent(Object element) { @Override public boolean hasChildren(Object element) { - if(element instanceof DependencyNode) { - DependencyNode node = (DependencyNode) element; - return !node.getChildren().isEmpty(); - } - return false; + return element instanceof DependencyNode node && !node.getChildren().isEmpty(); } @Override @@ -818,8 +806,7 @@ public void setShowGroupId(boolean showGroupId) { @Override public Color getForeground(Object element) { - if(element instanceof DependencyNode) { - DependencyNode node = (DependencyNode) element; + if(element instanceof DependencyNode node) { String scope = node.getDependency().getScope(); if(scope != null && !"compile".equals(scope) && !isMatching(node)) { //$NON-NLS-1$ return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); @@ -837,10 +824,7 @@ public Color getBackground(Object element) { } private boolean isMatching(Object element) { - if(element instanceof DependencyNode) { - return isMatching(((DependencyNode) element)); - } - return false; + return element instanceof DependencyNode node && isMatching(node); } private boolean isMatching(DependencyNode node) { @@ -855,9 +839,7 @@ private boolean isMatching(DependencyNode node) { @Override public String getText(Object element) { - if(element instanceof DependencyNode) { - DependencyNode node = (DependencyNode) element; - + if(element instanceof DependencyNode node) { org.eclipse.aether.artifact.Artifact a = node.getDependency().getArtifact(); StringBuilder label = new StringBuilder(128); @@ -904,8 +886,7 @@ public String getText(Object element) { @Override public Image getImage(Object element) { - if(element instanceof DependencyNode) { - DependencyNode node = (DependencyNode) element; + if(element instanceof DependencyNode node) { org.eclipse.aether.artifact.Artifact a = node.getDependency().getArtifact(); IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); IMavenProjectFacade projectFacade = projectManager.getMavenProject(a.getGroupId(), // @@ -935,8 +916,7 @@ public void setShowGroupId(boolean showGroupId) { @Override public Color getForeground(Object element) { - if(element instanceof Artifact) { - Artifact a = (Artifact) element; + if(element instanceof Artifact a) { String scope = a.getScope(); if(scope != null && !"compile".equals(scope) && !isMatching(a)) { return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); @@ -947,10 +927,7 @@ public Color getForeground(Object element) { @Override public Color getBackground(Object element) { - if(element instanceof Artifact && isMatching((Artifact) element)) { - return highlighter.getBackgroundColor(); - } - return null; + return element instanceof Artifact artifact && isMatching(artifact) ? highlighter.getBackgroundColor() : null; } private boolean isMatching(Artifact a) { @@ -963,8 +940,7 @@ private boolean isMatching(Artifact a) { @Override public String getText(Object element) { - if(element instanceof Artifact) { - Artifact a = (Artifact) element; + if(element instanceof Artifact a) { StringBuilder label = new StringBuilder(64); if(showGroupId) { @@ -988,8 +964,7 @@ public String getText(Object element) { @Override public Image getImage(Object element) { - if(element instanceof Artifact) { - Artifact a = (Artifact) element; + if(element instanceof Artifact a) { IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); IMavenProjectFacade projectFacade = projectManager.getMavenProject(a.getGroupId(), // a.getArtifactId(), // @@ -1005,8 +980,7 @@ public class DependencyListContentProvider implements IStructuredContentProvider @Override public Object[] getElements(Object input) { - if(input instanceof MavenProject) { - MavenProject project = (MavenProject) input; + if(input instanceof MavenProject project) { List artifacts = new ArrayList<>(); ArtifactFilter filter = new org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter(currentClasspath); for(Artifact artifact : project.getArtifacts()) { @@ -1050,8 +1024,7 @@ public boolean isMatchingArtifact(String groupId, String artifactId) { } protected void addArtifactKey(Object o) { - if(o instanceof Artifact) { - Artifact a = (Artifact) o; + if(o instanceof Artifact a) { artifactKeys.add(getKey(a.getGroupId(), a.getArtifactId())); } } @@ -1070,8 +1043,8 @@ public DependencyNodeMatcher(IStructuredSelection selection) { @Override protected void addArtifactKey(Object o) { - if(o instanceof DependencyNode) { - org.eclipse.aether.artifact.Artifact a = ((DependencyNode) o).getDependency().getArtifact(); + if(o instanceof DependencyNode node) { + org.eclipse.aether.artifact.Artifact a = node.getDependency().getArtifact(); artifactKeys.add(getKey(a.getGroupId(), a.getArtifactId())); } } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/FormUtils.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/FormUtils.java index 9f69a0c347..9e7c944440 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/FormUtils.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/FormUtils.java @@ -207,21 +207,16 @@ public static void setEnabled(Composite composite, boolean enabled) { static void setReadonly(Composite composite, boolean readonly) { if(composite != null) { for(Control control : composite.getChildren()) { - if(control instanceof Text) { - ((Text) control).setEditable(!readonly); - - } else if(control instanceof Combo) { - ((Combo) control).setEnabled(!readonly); - - } else if(control instanceof CCombo) { - ((CCombo) control).setEnabled(!readonly); - - } else if(control instanceof Button) { - ((Button) control).setEnabled(!readonly); - - } else if(control instanceof Composite) { - setReadonly((Composite) control, readonly); - + if(control instanceof Text text) { + text.setEditable(!readonly); + } else if(control instanceof Combo combo) { + combo.setEnabled(!readonly); + } else if(control instanceof CCombo ccombo) { + ccombo.setEnabled(!readonly); + } else if(control instanceof Button button) { + button.setEnabled(!readonly); + } else if(control instanceof Composite c) { + setReadonly(c, readonly); } } } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java index a9757c9e3e..d139e6ccb6 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java @@ -371,8 +371,8 @@ private void setModel() { if(sourceDocument == null) { initializeSourceDocument(); } - if(sourceDocument instanceof IStructuredDocument) { - this.structuredModel = this.modelManager.getModelForEdit((IStructuredDocument) sourceDocument); + if(sourceDocument instanceof IStructuredDocument structuredSelection) { + this.structuredModel = this.modelManager.getModelForEdit(structuredSelection); } else { // create a read-only copy of the document try (InputStream docStream = new DocumentInputStream(sourceDocument)) { @@ -390,13 +390,13 @@ private void initializeSourceDocument() { return; } sourceDocument = documentProvider.getDocument(this.getEditorInput()); - if(documentProvider instanceof TextFileDocumentProvider) { + if(documentProvider instanceof TextFileDocumentProvider textDocumentProvider) { try { // not clear why, but some documents are sometimes not synchronized at this stage // and this causes some strange dirtiness behavior or non-working refactorings. // It's most probably some disposal issue but no better solution was found yet. // so let's force synchronization... - ((TextFileDocumentProvider) documentProvider).synchronize(getEditorInput()); + textDocumentProvider.synchronize(getEditorInput()); } catch(CoreException ex) { log.error(ex.getMessage(), ex); } @@ -457,9 +457,9 @@ protected void pageChange(int newPageIndex) { } // a workaround for editor pages not returned IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor(); - if(contributor instanceof MultiPageEditorActionBarContributor) { + if(contributor instanceof MultiPageEditorActionBarContributor multiPageContributor) { IEditorPart activeEditor = getActivePageInstance(); - ((MultiPageEditorActionBarContributor) contributor).setActivePage(activeEditor); + multiPageContributor.setActivePage(activeEditor); } } @@ -525,8 +525,8 @@ protected IEditorSite createSite(IEditorPart editor) { public IEditorActionBarContributor getActionBarContributor() { IEditorActionBarContributor contributor = super.getActionBarContributor(); IEditorActionBarContributor multiContributor = MavenPomEditor.this.getEditorSite().getActionBarContributor(); - if(multiContributor instanceof MavenPomEditorContributor) { - contributor = ((MavenPomEditorContributor) multiContributor).sourceViewerActionContributor; + if(multiContributor instanceof MavenPomEditorContributor pomEditorContributor) { + contributor = pomEditorContributor.sourceViewerActionContributor; } return contributor; } @@ -633,11 +633,11 @@ public boolean isReadOnly() { private int addPomPage(IFormPage page) { try { - if(page instanceof MavenPomEditorPage) { - mavenpomEditorPages.add((MavenPomEditorPage) page); + if(page instanceof MavenPomEditorPage pomPage) { + mavenpomEditorPages.add(pomPage); } - if(page instanceof IPomFileChangedListener) { - fileChangeListeners.add((IPomFileChangedListener) page); + if(page instanceof IPomFileChangedListener listener) { + fileChangeListeners.add(listener); } return addPage(page); } catch(PartInitException ex) { @@ -700,8 +700,7 @@ public MavenProject readMavenProject(boolean force, IProgressMonitor monitor) th IEditorInput input = getEditorInput(); - if(input instanceof IFileEditorInput) { - IFileEditorInput fileInput = (IFileEditorInput) input; + if(input instanceof IFileEditorInput fileInput) { pomFile = fileInput.getFile(); pomFile.refreshLocal(1, null); } @@ -802,10 +801,9 @@ public void showInSourceEditor(EObject o) { public IDOMElement getElement(EObject o) { for(Adapter adapter : o.eAdapters()) { - if(adapter instanceof EMF2DOMSSEAdapter) { - EMF2DOMSSEAdapter a = (EMF2DOMSSEAdapter) adapter; - if(a.getNode() instanceof IDOMElement) { - return (IDOMElement) a.getNode(); + if(adapter instanceof EMF2DOMSSEAdapter a) { + if(a.getNode() instanceof IDOMElement element) { + return element; } break; } @@ -1059,8 +1057,7 @@ protected IStatus run(IProgressMonitor monitor) { @Override public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) { IEditorInput input = getEditorInput(); - if(input instanceof IFileEditorInput) { - IFileEditorInput fileinput = (IFileEditorInput) input; + if(input instanceof IFileEditorInput fileinput) { for(MavenProjectChangedEvent event : events) { if(fileinput.getFile().equals(event.getSource())) { IMavenProjectFacade facade = event.getMavenProject(); diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorContributor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorContributor.java index 9475dbe987..45375defd5 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorContributor.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorContributor.java @@ -55,8 +55,7 @@ public void dispose() { @Override public void setActiveEditor(IEditorPart targetEditor) { - if(targetEditor instanceof MavenPomEditor) { - editorPart = (MavenPomEditor) targetEditor; + if(targetEditor instanceof MavenPomEditor editorPart) { setActivePage(editorPart.getActiveEditor()); } } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPage.java index 8d2b9ba8be..0f250e38d5 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPage.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPage.java @@ -335,24 +335,12 @@ private void doLoadData(boolean active) { head = NLS.bind(Messages.FormUtils_click_for_details, head.substring(0, FormUtils.MAX_MSG_LENGTH)); } } - int severity; - switch(max.getAttribute(IMarker.SEVERITY, -1)) { - case IMarker.SEVERITY_ERROR: { - severity = IMessageProvider.ERROR; - break; - } - case IMarker.SEVERITY_WARNING: { - severity = IMessageProvider.WARNING; - break; - } - case IMarker.SEVERITY_INFO: { - severity = IMessageProvider.INFORMATION; - break; - } - default: { - severity = IMessageProvider.NONE; - } - } + int severity = switch(max.getAttribute(IMarker.SEVERITY, -1)) { + case IMarker.SEVERITY_ERROR -> IMessageProvider.ERROR; + case IMarker.SEVERITY_WARNING -> IMessageProvider.WARNING; + case IMarker.SEVERITY_INFO -> IMessageProvider.INFORMATION; + default -> IMessageProvider.NONE; + }; setErrorMessageForMarkers(head, text, severity, markers); } else { setErrorMessageForMarkers(null, null, IMessageProvider.NONE, new IMarker[0]); @@ -445,7 +433,7 @@ public String getDescriptionText() { MavenProject mp = getPomEditor().getMavenProject(); if(mp != null) { return FormUtils.simpleInterpolate(mp, - control instanceof Text ? ((Text) control).getText() : ((CCombo) control).getText()); + control instanceof Text text ? text.getText() : ((CCombo) control).getText()); } return "Cannot interpolate expressions, not resolvable file."; } @@ -458,15 +446,15 @@ public String getDescriptionText() { decoration.addSelectionListener( SelectionListener.widgetSelectedAdapter(e -> decoration.showHoverText(decoration.getDescriptionText()))); ModifyListener listener = e -> { - String text = control instanceof Text ? ((Text) control).getText() : ((CCombo) control).getText(); + String text = control instanceof Text textWidget ? textWidget.getText() : ((CCombo) control).getText(); if(text.indexOf("${") != -1 && text.indexOf("}") != -1) { decoration.show(); } else { decoration.hide(); } }; - if(control instanceof Text) { - ((Text) control).addModifyListener(listener); + if(control instanceof Text text) { + text.addModifyListener(listener); } else { ((CCombo) control).addModifyListener(listener); } @@ -509,14 +497,14 @@ public void setModifyListener(final Control control) { ModifyListener ml = new ModifyListener() { String getText(Control control) { - if(control instanceof Text) { - return ((Text) control).getText(); + if(control instanceof Text text) { + return text.getText(); } - if(control instanceof Combo) { - return ((Combo) control).getText(); + if(control instanceof Combo combo) { + return combo.getText(); } - if(control instanceof CCombo) { - return ((CCombo) control).getText(); + if(control instanceof CCombo ccombo) { + return ccombo.getText(); } throw new IllegalStateException(); } @@ -534,9 +522,9 @@ public void modifyText(ModifyEvent e) { Element el1 = provider.find(document); if(el1 != null) { Node parent = el1.getParentNode(); - if(parent instanceof Element) { - removeChild((Element) parent, el1); - removeIfNoChildElement((Element) parent); + if(parent instanceof Element element) { + removeChild(element, el1); + removeIfNoChildElement(element); } } } else { diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/OverviewPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/OverviewPage.java index c9ab02e82e..2cf04215da 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/OverviewPage.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/OverviewPage.java @@ -678,9 +678,9 @@ protected IStatus run(IProgressMonitor monitor) { modulesEditor.setCreateButtonListener(SelectionListener.widgetSelectedAdapter(e -> { IEditorInput editorInput = OverviewPage.this.pomEditor.getEditorInput(); - if(editorInput instanceof FileEditorInput) { + if(editorInput instanceof FileEditorInput fileInput) { MavenModuleWizard wizard = new MavenModuleWizard(true); - wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(((FileEditorInput) editorInput).getFile())); + wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(fileInput.getFile())); WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard); int res = dialog.open(); if(res == Window.OK) { @@ -752,8 +752,8 @@ public void dragOperationChanged(DropTargetEvent event) { @Override public void drop(DropTargetEvent event) { - if(event.data instanceof Object[]) { - addSelectedModules((Object[]) event.data, true); + if(event.data instanceof Object[] array) { + addSelectedModules(array, true); } } }); @@ -1347,14 +1347,14 @@ private void addSelectedModules(Object[] result, boolean updateParentSection) { IContainer container = null; IFile pomFile = null; - if(selection instanceof IFile) { - pomFile = (IFile) selection; + if(selection instanceof IFile file) { + pomFile = file; if(!IMavenConstants.POM_FILE_NAME.equals(pomFile.getName())) { continue; } container = pomFile.getParent(); - } else if(selection instanceof IContainer && !selection.equals(getProject())) { - container = (IContainer) selection; + } else if(selection instanceof IContainer c && !selection.equals(getProject())) { + container = c; pomFile = container.getFile(new Path(IMavenConstants.POM_FILE_NAME)); } @@ -1405,8 +1405,7 @@ public ModulesLabelProvider(MavenPomEditorPage editorPage) { @Override public Image getImage(Object element) { - if(element instanceof String) { - String moduleName = (String) element; + if(element instanceof String moduleName) { IMavenProjectFacade projectFacade = editorPage.findModuleProject(moduleName); if(projectFacade != null) { return MavenEditorImages.IMG_PROJECT; diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomHyperlinkDetector.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomHyperlinkDetector.java index c330b016d6..6f3ef4fd5e 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomHyperlinkDetector.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomHyperlinkDetector.java @@ -108,8 +108,8 @@ public IHyperlink[] detectHyperlinks(final ITextViewer textViewer, final IRegion final int offset = region.getOffset(); XmlUtils.performOnCurrentElement(document, offset, (node, structured) -> { - if(textViewer instanceof ISourceViewer) { - IHyperlink[] links = openExternalMarkerDefinition((ISourceViewer) textViewer, offset); + if(textViewer instanceof ISourceViewer sourceViwer) { + IHyperlink[] links = openExternalMarkerDefinition(sourceViwer, offset); if(links.length > 0) { hyperlinks.addAll(Arrays.asList(links)); } @@ -180,8 +180,7 @@ static ManagedArtifactRegion findManagedArtifactRegion(Node current, ITextViewer NodeList childs = root.getChildNodes(); for(int i = 0; i < childs.getLength(); i++ ) { Node child = childs.item(i); - if(child instanceof Element) { - Element el = (Element) child; + if(child instanceof Element el) { if(VERSION.equals(el.getNodeName())) { return null; } @@ -307,12 +306,9 @@ static InputLocation findLocationForManagedArtifact(final ManagedArtifactRegion } static ExpressionRegion findExpressionRegion(Node current, ITextViewer viewer, int offset) { - if(current instanceof Text) { - Text node = (Text) current; + if(current instanceof Text node) { String value = node.getNodeValue(); - if(value != null) { - assert node instanceof IndexedRegion; - IndexedRegion reg = (IndexedRegion) node; + if(value != null && node instanceof IndexedRegion reg) { int index = offset - reg.getStartOffset(); String before = value.substring(0, Math.min(index + 1, value.length())); String after = value.substring(Math.min(index + 1, value.length())); @@ -424,10 +420,10 @@ static MarkerRegion[] findMarkerRegions(ISourceViewer sourceViewer, int offset) Iterator it = model.getAnnotationIterator(); while(it.hasNext()) { Annotation ann = it.next(); - if(ann instanceof MarkerAnnotation) { + if(ann instanceof MarkerAnnotation marker) { Position pos = sourceViewer.getAnnotationModel().getPosition(ann); if(pos.includes(offset)) { - toRet.add(new MarkerRegion(pos.getOffset(), pos.getLength(), (MarkerAnnotation) ann)); + toRet.add(new MarkerRegion(pos.getOffset(), pos.getLength(), marker)); } } } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomTextHover.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomTextHover.java index 5c83091315..9d2961b670 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomTextHover.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomTextHover.java @@ -52,10 +52,9 @@ public PomTextHover(ISourceViewer sourceViewer, String contentType, int stateMas @Override public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { - if(hoverRegion instanceof ExpressionRegion) { - return getLabelForRegion((ExpressionRegion) hoverRegion).toString(); - } else if(hoverRegion instanceof ManagedArtifactRegion) { - ManagedArtifactRegion region = (ManagedArtifactRegion) hoverRegion; + if(hoverRegion instanceof ExpressionRegion expression) { + return getLabelForRegion(expression).toString(); + } else if(hoverRegion instanceof ManagedArtifactRegion region) { return getLabelForRegion(region).toString(); } @@ -161,18 +160,16 @@ public IRegion getHoverRegion(final ITextViewer textViewer, final int offset) { if(regs[1] != null) { toRet.addRegion(regs[1]); } - if(textViewer instanceof ISourceViewer) { - ISourceViewer sourceViewer = (ISourceViewer) textViewer; + if(textViewer instanceof ISourceViewer sourceViewer) { IAnnotationModel model = sourceViewer.getAnnotationModel(); if(model != null) { //eg. in tests Iterator it = model.getAnnotationIterator(); while(it.hasNext()) { Annotation ann = it.next(); - if(ann instanceof MarkerAnnotation) { + if(ann instanceof MarkerAnnotation marker) { Position pos = sourceViewer.getAnnotationModel().getPosition(ann); if(pos.includes(offset)) { - toRet.addRegion( - new PomHyperlinkDetector.MarkerRegion(pos.getOffset(), pos.getLength(), (MarkerAnnotation) ann)); + toRet.addRegion(new PomHyperlinkDetector.MarkerRegion(pos.getOffset(), pos.getLength(), marker)); } } } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertiesSection.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertiesSection.java index 3c2215103e..c4e52dc628 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertiesSection.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertiesSection.java @@ -226,8 +226,7 @@ static class PropertyPairLabelProvider extends LabelProvider { @Override public String getText(Object element) { - if(element instanceof PropertyElement) { - PropertyElement pair = (PropertyElement) element; + if(element instanceof PropertyElement pair) { return NLS.bind(Messages.PropertyPairLabelProvider_0, pair.getName(), pair.getValue()); } return super.getText(element); diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/XMLEditorUtility.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/XMLEditorUtility.java index 133ed7d427..527d89cfc4 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/XMLEditorUtility.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/XMLEditorUtility.java @@ -64,11 +64,10 @@ private static ITextEditor selectEditorPage(IEditorPart part) { if(part == null) { return null; } - if(part instanceof FormEditor) { - FormEditor ed = (FormEditor) part; + if(part instanceof FormEditor ed) { ed.setActivePage(null); //null means source, always or just in the case of MavenPomEditor? - if(ed instanceof MavenPomEditor) { - return ((MavenPomEditor) ed).getSourcePage(); + if(ed instanceof MavenPomEditor pomEditor) { + return pomEditor.getSourcePage(); } } return null; diff --git a/org.eclipse.m2e.jdt.ui/.classpath b/org.eclipse.m2e.jdt.ui/.classpath index 4a00becd81..3628e33687 100644 --- a/org.eclipse.m2e.jdt.ui/.classpath +++ b/org.eclipse.m2e.jdt.ui/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.m2e.jdt.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.jdt.ui/.settings/org.eclipse.jdt.core.prefs index 9bc5dacb67..ffbf9b784f 100644 --- a/org.eclipse.m2e.jdt.ui/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.m2e.jdt.ui/.settings/org.eclipse.jdt.core.prefs @@ -18,9 +18,9 @@ org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -108,7 +108,7 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.source=17 org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,HIGH org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX diff --git a/org.eclipse.m2e.jdt.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.jdt.ui/META-INF/MANIFEST.MF index 5046a36787..f2d7c807a9 100644 --- a/org.eclipse.m2e.jdt.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.jdt.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.m2e.jdt.ui;singleton:=true -Bundle-Version: 1.18.1.qualifier +Bundle-Version: 1.19.0.qualifier Bundle-Localization: plugin Export-Package: org.eclipse.m2e.jdt.ui.internal;x-internal:=true, org.eclipse.m2e.jdt.ui.internal.actions;x-internal:=true, @@ -23,7 +23,7 @@ Require-Bundle: org.eclipse.m2e.jdt;bundle-version="[1.18.4,3.0.0)", org.eclipse.ui Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.m2e.jdt.ui.internal.MavenJdtUiPlugin -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-Vendor: %Bundle-Vendor Import-Package: org.slf4j;version="[1.6.2,2.0.0)" Automatic-Module-Name: org.eclipse.m2e.jdt.ui diff --git a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/DownloadSourcesActionDelegate.java b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/DownloadSourcesActionDelegate.java index 8c6bd2e0d4..de73a2a949 100644 --- a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/DownloadSourcesActionDelegate.java +++ b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/DownloadSourcesActionDelegate.java @@ -40,16 +40,13 @@ public class DownloadSourcesActionDelegate implements IEditorActionDelegate { public void setActiveEditor(IAction action, IEditorPart part) { - if(part != null && part.getEditorInput() instanceof IClassFileEditorInput) { + if(part != null && part.getEditorInput() instanceof IClassFileEditorInput input) { try { IClasspathManager buildpathManager = MavenJdtPlugin.getDefault().getBuildpathManager(); - IClassFileEditorInput input = (IClassFileEditorInput) part.getEditorInput(); IJavaElement element = input.getClassFile(); while(element.getParent() != null) { element = element.getParent(); - if(element instanceof IPackageFragmentRoot) { - IPackageFragmentRoot root = (IPackageFragmentRoot) element; - + if(element instanceof IPackageFragmentRoot root) { if(root.getSourceAttachmentPath() != null) { // do nothing if sources attached already break; diff --git a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/JavaUiElementsAdapterFactory.java b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/JavaUiElementsAdapterFactory.java index 1f76a39445..01dd9421e2 100644 --- a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/JavaUiElementsAdapterFactory.java +++ b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/JavaUiElementsAdapterFactory.java @@ -51,8 +51,8 @@ public T getAdapter(Object adaptableObject, Class adapterType) { } } else if(adapterType == IMavenProjectFacade.class) { - if(adaptableObject instanceof RequiredProjectWrapper) { - ClassPathContainer container = ((RequiredProjectWrapper) adaptableObject).getParentClassPathContainer(); + if(adaptableObject instanceof RequiredProjectWrapper wrapper) { + ClassPathContainer container = wrapper.getParentClassPathContainer(); IProject project = container.getJavaProject().getProject(); IMavenProjectFacade projectFacade = getProjectFacade(project); if(projectFacade != null) { diff --git a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/actions/DownloadSourcesAction.java b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/actions/DownloadSourcesAction.java index 072da325b5..1c04d5d080 100644 --- a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/actions/DownloadSourcesAction.java +++ b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/actions/DownloadSourcesAction.java @@ -62,14 +62,11 @@ public void run(IAction action) { if(selection != null) { IClasspathManager buildpathManager = MavenJdtPlugin.getDefault().getBuildpathManager(); for(Object element : selection) { - if(element instanceof IProject) { - IProject project = (IProject) element; + if(element instanceof IProject project) { buildpathManager.scheduleDownload(project, ID_SOURCES.equals(id), ID_JAVADOC.equals(id)); - } else if(element instanceof IPackageFragmentRoot) { - IPackageFragmentRoot fragment = (IPackageFragmentRoot) element; + } else if(element instanceof IPackageFragmentRoot fragment) { buildpathManager.scheduleDownload(fragment, ID_SOURCES.equals(id), ID_JAVADOC.equals(id)); - } else if(element instanceof IWorkingSet) { - IWorkingSet workingSet = (IWorkingSet) element; + } else if(element instanceof IWorkingSet workingSet) { for(IAdaptable adaptable : workingSet.getElements()) { IProject project = adaptable.getAdapter(IProject.class); buildpathManager.scheduleDownload(project, ID_SOURCES.equals(id), ID_JAVADOC.equals(id)); @@ -80,8 +77,8 @@ public void run(IAction action) { } public void selectionChanged(IAction action, ISelection selection) { - if(selection instanceof IStructuredSelection) { - this.selection = (IStructuredSelection) selection; + if(selection instanceof IStructuredSelection structuredSelection) { + this.selection = structuredSelection; } else { this.selection = null; } diff --git a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/actions/OpenJavaDocAction.java b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/actions/OpenJavaDocAction.java index 3923827382..9472f5a250 100644 --- a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/actions/OpenJavaDocAction.java +++ b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/actions/OpenJavaDocAction.java @@ -60,8 +60,8 @@ public class OpenJavaDocAction extends ActionDelegate { private IStructuredSelection selection; public void selectionChanged(IAction action, ISelection selection) { - if(selection instanceof IStructuredSelection) { - this.selection = (IStructuredSelection) selection; + if(selection instanceof IStructuredSelection structuredSelection) { + this.selection = structuredSelection; } else { this.selection = null; } diff --git a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/filter/MavenModuleFilter.java b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/filter/MavenModuleFilter.java index 5b83b5a316..2ee9aecf10 100644 --- a/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/filter/MavenModuleFilter.java +++ b/org.eclipse.m2e.jdt.ui/src/org/eclipse/m2e/jdt/ui/internal/filter/MavenModuleFilter.java @@ -40,8 +40,7 @@ public class MavenModuleFilter extends ViewerFilter { @SuppressWarnings("restriction") public boolean select(Viewer viewer, Object parentElement, Object element) { - if(element instanceof IFolder) { - IFolder folder = (IFolder) element; + if(element instanceof IFolder folder) { IProject project = folder.getProject(); try { if(project.hasNature(org.eclipse.m2e.core.internal.IMavenConstants.NATURE_ID)) { diff --git a/org.eclipse.m2e.jdt/.classpath b/org.eclipse.m2e.jdt/.classpath index 4a00becd81..3628e33687 100644 --- a/org.eclipse.m2e.jdt/.classpath +++ b/org.eclipse.m2e.jdt/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.core.prefs index 2bdb7b46a6..11358cf629 100644 --- a/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.core.prefs @@ -28,9 +28,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul org.eclipse.jdt.core.compiler.annotation.nullable.secondary= org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -145,7 +145,7 @@ org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.source=17 org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,HIGH org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX diff --git a/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF b/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF index f6db5551af..65786bb02d 100644 --- a/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF @@ -17,7 +17,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.m2e.core;bundle-version="2.0.0" Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.m2e.jdt.MavenJdtPlugin -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-Vendor: %Bundle-Vendor Import-Package: org.slf4j;version="[1.6.2,2.0.0)" Automatic-Module-Name: org.eclipse.m2e.jdt diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java index 878c29fdb4..4079a6f027 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java @@ -82,8 +82,8 @@ protected void addFolders(Set runtimeClasspath, IProject int classpathProperty) { for(IPath folder : folders) { IResource member = project.findMember(folder); // only returns existing members - if(member instanceof IFolder) { // must exist and be a folder - runtimeClasspath.add(ModuleSupport.createRuntimeClasspathEntry((IFolder) member, classpathProperty, project)); + if(member instanceof IFolder folderMember) { // must exist and be a folder + runtimeClasspath.add(ModuleSupport.createRuntimeClasspathEntry(folderMember, classpathProperty, project)); } } } diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java index f93d57fe6a..67a82786cc 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java @@ -223,8 +223,8 @@ protected void invokeJavaProjectConfigurators(IClasspathDescriptor classpath, Pr return; } for(AbstractProjectConfigurator configurator : lifecycleMapping.getProjectConfigurators(facade, monitor)) { - if(configurator instanceof IJavaProjectConfigurator) { - ((IJavaProjectConfigurator) configurator).configureRawClasspath(request, classpath, monitor); + if(configurator instanceof IJavaProjectConfigurator javaConfigurator) { + javaConfigurator.configureRawClasspath(request, classpath, monitor); } } } @@ -723,23 +723,18 @@ private boolean isEnablePreviewFeatures(MavenProject mavenProject, MojoExecution } private String sanitizeJavaVersion(String version) { - switch(version) { - case "5": - case "6": - case "7": - case "8": - version = "1." + version; - break; - default: + return switch(version) { + case "5", "6", "7", "8" -> "1." + version; + default -> { if(version.startsWith("1.")) { String subVersion = version.substring(2); if(Integer.parseInt(subVersion) > 8) { - version = subVersion; + yield subVersion; } } - break; - } - return version; + yield version; + } + }; } protected String getDefaultTargetLevel(String source) { diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java index 6a3ae4caad..3a0a7aee4b 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java @@ -260,10 +260,7 @@ private IClasspathEntry[] getClasspath(IMavenProjectFacade projectFacade, final private IClasspathManagerDelegate getDelegate(IMavenProjectFacade projectFacade, IProgressMonitor monitor) { ILifecycleMapping lifecycleMapping = LifecycleMappingFactory.getLifecycleMapping(projectFacade); - if(lifecycleMapping instanceof IClasspathManagerDelegate) { - return (IClasspathManagerDelegate) lifecycleMapping; - } - return defaultDelegate; + return lifecycleMapping instanceof IClasspathManagerDelegate classpathManager ? classpathManager : defaultDelegate; } private void configureAttachedSourcesAndJavadoc(IMavenProjectFacade facade, Properties sourceAttachment, @@ -916,8 +913,7 @@ public ModuleInfoDetector(Collection affectedProjects) { @Override public boolean visit(IResourceDelta delta) { - if(delta.getResource() instanceof IFile) { - IFile file = (IFile) delta.getResource(); + if(delta.getResource() instanceof IFile file) { if(ModuleSupport.MODULE_INFO_JAVA.equals(file.getName())) { affectedProjects.add(file.getProject()); } diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java index 8b7fca48ec..db821ade5b 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java @@ -104,48 +104,35 @@ public IClasspathEntry toClasspathEntry() { } IAccessRule[] accessRulesArray = accessRules.toArray(new IAccessRule[accessRules.size()]); - IClasspathEntry entry; - switch(entryKind) { - case IClasspathEntry.CPE_CONTAINER: - entry = JavaCore.newContainerEntry(path, // - accessRulesArray, // - attributesArray, // - exported); - break; - case IClasspathEntry.CPE_LIBRARY: - entry = JavaCore.newLibraryEntry(path, // - sourceAttachmentPath, // - sourceAttachmentRootPath, // - accessRulesArray, // - attributesArray, // - exported); - break; - case IClasspathEntry.CPE_SOURCE: - entry = JavaCore.newSourceEntry(path, // - getInclusionPatterns(), // - getExclusionPatterns(), // - outputLocation, // - attributesArray); - break; - case IClasspathEntry.CPE_PROJECT: - entry = JavaCore.newProjectEntry(path, // - accessRulesArray, // - combineAccessRules, // - attributesArray, // - exported); - break; - case IClasspathEntry.CPE_VARIABLE: - entry = JavaCore.newVariableEntry(path, // - sourceAttachmentPath, // - sourceAttachmentRootPath, // - accessRulesArray, // - attributesArray, // - exported); - break; - default: - throw new IllegalArgumentException("Unsupported IClasspathEntry kind=" + entryKind); //$NON-NLS-1$ - } - return entry; + return switch(entryKind) { + case IClasspathEntry.CPE_CONTAINER -> JavaCore.newContainerEntry(path, // + accessRulesArray, // + attributesArray, // + exported); + case IClasspathEntry.CPE_LIBRARY -> JavaCore.newLibraryEntry(path, // + sourceAttachmentPath, // + sourceAttachmentRootPath, // + accessRulesArray, // + attributesArray, // + exported); + case IClasspathEntry.CPE_SOURCE -> JavaCore.newSourceEntry(path, // + getInclusionPatterns(), // + getExclusionPatterns(), // + outputLocation, // + attributesArray); + case IClasspathEntry.CPE_PROJECT -> JavaCore.newProjectEntry(path, // + accessRulesArray, // + combineAccessRules, // + attributesArray, // + exported); + case IClasspathEntry.CPE_VARIABLE -> JavaCore.newVariableEntry(path, // + sourceAttachmentPath, // + sourceAttachmentRootPath, // + accessRulesArray, // + attributesArray, // + exported); + default -> throw new IllegalArgumentException("Unsupported IClasspathEntry kind=" + entryKind); //$NON-NLS-1$ + }; } @Override diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DefaultClasspathManagerDelegate.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DefaultClasspathManagerDelegate.java index b0137fb58f..7e8b95f2f9 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DefaultClasspathManagerDelegate.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DefaultClasspathManagerDelegate.java @@ -78,8 +78,8 @@ private List getJavaProjectConfigurators(IMavenProject if(lifecycleMapping != null) { for(AbstractProjectConfigurator configurator : lifecycleMapping.getProjectConfigurators(projectFacade, monitor)) { - if(configurator instanceof IJavaProjectConfigurator) { - configurators.add((IJavaProjectConfigurator) configurator); + if(configurator instanceof IJavaProjectConfigurator javaConfigurator) { + configurators.add(javaConfigurator); } } } diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java index 6b3dc3e0bb..011c36a84c 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java @@ -93,11 +93,8 @@ public boolean equals(Object o) { if(this == o) { return true; } - if(!(o instanceof DownloadRequest)) { - return false; - } - DownloadRequest other = (DownloadRequest) o; - return project.equals(other.project) && Objects.equals(fragment, other.fragment) + return o instanceof DownloadRequest other && // + project.equals(other.project) && Objects.equals(fragment, other.fragment) && Objects.equals(artifact, other.artifact) && downloadSources == other.downloadSources && downloadJavaDoc == other.downloadJavaDoc; } diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaElementsAdapterFactory.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaElementsAdapterFactory.java index d90eecb585..25994070f4 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaElementsAdapterFactory.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaElementsAdapterFactory.java @@ -54,8 +54,7 @@ public Class[] getAdapterList() { @Override public T getAdapter(Object adaptableObject, Class adapterType) { if(adapterType == ArtifactKey.class) { - if(adaptableObject instanceof IPackageFragmentRoot) { - IPackageFragmentRoot fragment = (IPackageFragmentRoot) adaptableObject; + if(adaptableObject instanceof IPackageFragmentRoot fragment) { IProject project = fragment.getJavaProject().getProject(); if(project.isAccessible() && fragment.isArchive()) { try { @@ -66,22 +65,22 @@ public T getAdapter(Object adaptableObject, Class adapterType) { } } - } else if(adaptableObject instanceof IJavaProject) { - return adapterType.cast(((IJavaProject) adaptableObject).getProject().getAdapter(ArtifactKey.class)); + } else if(adaptableObject instanceof IJavaProject javaProject) { + return adapterType.cast(javaProject.getProject().getAdapter(ArtifactKey.class)); } } else if(adapterType == IPath.class) { - if(adaptableObject instanceof IJavaElement) { - IResource resource = ((IJavaElement) adaptableObject).getResource(); + if(adaptableObject instanceof IJavaElement javaElement) { + IResource resource = javaElement.getResource(); if(resource != null) { return adapterType.cast(resource.getLocation()); } } } else if(adapterType == IMavenProjectFacade.class) { - if(adaptableObject instanceof IJavaElement) { - IProject project = ((IJavaElement) adaptableObject).getJavaProject().getProject(); + if(adaptableObject instanceof IJavaElement javaElement) { + IProject project = javaElement.getJavaProject().getProject(); IMavenProjectFacade projectFacade = getProjectFacade(project); if(projectFacade != null) { return adapterType.cast(projectFacade); diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java index d6896c6104..01639b4e2a 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConversionParticipant.java @@ -402,8 +402,7 @@ public boolean visit(IResource resource) throws CoreException { if(resource.isHidden() || isIgnored(resourceName)) { return false; } - if(resource instanceof IFile) { - IFile file = (IFile) resource; + if(resource instanceof IFile file) { if(!"java".equals(file.getFileExtension())) { throw new NonJavaResourceFoundException(); } diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerSaveHelper.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerSaveHelper.java index 13309a977e..4aa4fd418c 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerSaveHelper.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerSaveHelper.java @@ -46,16 +46,16 @@ public IClasspathContainer readContainer(InputStream input) throws IOException, @Override protected Object resolveObject(Object o) throws IOException { - if(o instanceof ProjectEntryReplace) { - return ((ProjectEntryReplace) o).getEntry(); - } else if(o instanceof LibraryEntryReplace) { - return ((LibraryEntryReplace) o).getEntry(); - } else if(o instanceof ClasspathAttributeReplace) { - return ((ClasspathAttributeReplace) o).getAttribute(); - } else if(o instanceof AccessRuleReplace) { - return ((AccessRuleReplace) o).getAccessRule(); - } else if(o instanceof PathReplace) { - return ((PathReplace) o).getPath(); + if(o instanceof ProjectEntryReplace project) { + return project.getEntry(); + } else if(o instanceof LibraryEntryReplace library) { + return library.getEntry(); + } else if(o instanceof ClasspathAttributeReplace classpathAttribute) { + return classpathAttribute.getAttribute(); + } else if(o instanceof AccessRuleReplace accessRule) { + return accessRule.getAccessRule(); + } else if(o instanceof PathReplace path) { + return path.getPath(); } return super.resolveObject(o); } @@ -71,19 +71,18 @@ public void writeContainer(IClasspathContainer container, OutputStream output) t @Override protected Object replaceObject(Object o) throws IOException { - if(o instanceof IClasspathEntry) { - IClasspathEntry e = (IClasspathEntry) o; + if(o instanceof IClasspathEntry e) { if(e.getEntryKind() == IClasspathEntry.CPE_PROJECT) { return new ProjectEntryReplace(e); } else if(e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { return new LibraryEntryReplace(e); } - } else if(o instanceof IClasspathAttribute) { - return new ClasspathAttributeReplace((IClasspathAttribute) o); - } else if(o instanceof IAccessRule) { - return new AccessRuleReplace((IAccessRule) o); - } else if(o instanceof IPath) { - return new PathReplace((IPath) o); + } else if(o instanceof IClasspathAttribute classpthAttribute) { + return new ClasspathAttributeReplace(classpthAttribute); + } else if(o instanceof IAccessRule accessRule) { + return new AccessRuleReplace(accessRule); + } else if(o instanceof IPath path) { + return new PathReplace(path); } return super.replaceObject(o); } diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenLaunchConfigurationListener.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenLaunchConfigurationListener.java index 6f71017405..7c744617a0 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenLaunchConfigurationListener.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenLaunchConfigurationListener.java @@ -89,9 +89,8 @@ private void setModuleNameForLaunchersFromTestFolder(IJavaProject javaProject, I String currentModuleName = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MODULE_NAME, (String) null); if(modName != null && modName.length() > 0 && !modName.equals(currentModuleName)) { - if(config instanceof ILaunchConfigurationWorkingCopy) { - ((ILaunchConfigurationWorkingCopy) config).setAttribute(IJavaLaunchConfigurationConstants.ATTR_MODULE_NAME, - modName); + if(config instanceof ILaunchConfigurationWorkingCopy wc) { + wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MODULE_NAME, modName); } else { ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MODULE_NAME, modName); diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java index 586f1eb46d..386d4f19d0 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java @@ -391,8 +391,8 @@ public static boolean isSupportedType(String id) { } public static void enable(ILaunchConfiguration config) throws CoreException { - if(config instanceof ILaunchConfigurationWorkingCopy) { - enable((ILaunchConfigurationWorkingCopy) config); + if(config instanceof ILaunchConfigurationWorkingCopy wc) { + enable(wc); } else { ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); enable(wc); diff --git a/org.eclipse.m2e.launching/.classpath b/org.eclipse.m2e.launching/.classpath index 4a00becd81..3628e33687 100644 --- a/org.eclipse.m2e.launching/.classpath +++ b/org.eclipse.m2e.launching/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.m2e.launching/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.launching/.settings/org.eclipse.jdt.core.prefs index 9bc5dacb67..ffbf9b784f 100644 --- a/org.eclipse.m2e.launching/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.m2e.launching/.settings/org.eclipse.jdt.core.prefs @@ -18,9 +18,9 @@ org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -108,7 +108,7 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.source=17 org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,HIGH org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX diff --git a/org.eclipse.m2e.launching/META-INF/MANIFEST.MF b/org.eclipse.m2e.launching/META-INF/MANIFEST.MF index 5cc7140ede..09eb299fb3 100644 --- a/org.eclipse.m2e.launching/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.launching/META-INF/MANIFEST.MF @@ -16,14 +16,14 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.jdt.launching, org.eclipse.jdt.debug.ui, org.eclipse.m2e.maven.runtime;bundle-version="1.16.0", - org.eclipse.m2e.core;bundle-version="1.16.0", - org.eclipse.m2e.core.ui;bundle-version="1.16.0", + org.eclipse.m2e.core;bundle-version="2.0.0", + org.eclipse.m2e.core.ui;bundle-version="2.0.0", org.eclipse.jdt.debug, org.eclipse.core.resources, org.eclipse.debug.core, org.eclipse.m2e.workspace.cli;bundle-version="0.1.0" Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-Vendor: %Bundle-Vendor Export-Package: org.eclipse.m2e.actions;x-internal:=true, org.eclipse.m2e.internal.launch;x-internal:=true, diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/actions/ExecutePomAction.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/actions/ExecutePomAction.java index 74d5c8d166..16e116fc8f 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/actions/ExecutePomAction.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/actions/ExecutePomAction.java @@ -93,21 +93,20 @@ public void setInitializationData(IConfigurationElement config, String propertyN public void launch(IEditorPart editor, String mode) { IEditorInput editorInput = editor.getEditorInput(); - if(editorInput instanceof IFileEditorInput) { - launch(((IFileEditorInput) editorInput).getFile().getParent(), mode); + if(editorInput instanceof IFileEditorInput fileInput) { + launch(fileInput.getFile().getParent(), mode); } } public void launch(ISelection selection, String mode) { - if(selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection) selection; + if(selection instanceof IStructuredSelection structuredSelection) { Object object = structuredSelection.getFirstElement(); IContainer basedir = null; - if(object instanceof IProject || object instanceof IFolder) { - basedir = (IContainer) object; - } else if(object instanceof IFile) { - basedir = ((IFile) object).getParent(); + if(object instanceof IContainer container) { + basedir = container; + } else if(object instanceof IFile file) { + basedir = file.getParent(); } else if(object instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) object; Object adapter = adaptable.getAdapter(IProject.class); @@ -314,8 +313,7 @@ public Image getImage(Object element) { } public String getText(Object element) { - if(element instanceof ILaunchConfiguration) { - ILaunchConfiguration configuration = (ILaunchConfiguration) element; + if(element instanceof ILaunchConfiguration configuration) { try { return labelProvider.getText(element) + " : " + configuration.getAttribute(MavenLaunchConstants.ATTR_GOALS, ""); diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchExtensionsSupport.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchExtensionsSupport.java index 1d64ee3bc4..19484380e4 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchExtensionsSupport.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchExtensionsSupport.java @@ -47,8 +47,7 @@ private MavenLaunchExtensionsSupport(List participants) } public void configureSourceLookup(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) { - if(launch.getSourceLocator() instanceof MavenSourceLocator) { - final MavenSourceLocator sourceLocator = (MavenSourceLocator) launch.getSourceLocator(); + if(launch.getSourceLocator() instanceof MavenSourceLocator sourceLocator) { for(IMavenLaunchParticipant participant : participants) { List sourceLookupParticipants = participant.getSourceLookupParticipants(configuration, launch, monitor); diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchExtensionsTab.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchExtensionsTab.java index 5e17e733e2..3420330cd5 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchExtensionsTab.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchExtensionsTab.java @@ -67,8 +67,7 @@ public void createControl(Composite parent) { checkboxTableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION); checkboxTableViewer.addCheckStateListener(event -> { - if(event.getElement() instanceof MavenLaunchParticipantInfo) { - MavenLaunchParticipantInfo participant = (MavenLaunchParticipantInfo) event.getElement(); + if(event.getElement() instanceof MavenLaunchParticipantInfo participant) { if(event.getChecked()) { disabledParticipants.remove(participant.getId()); } else { diff --git a/org.eclipse.m2e.sourcelookup.ui/.classpath b/org.eclipse.m2e.sourcelookup.ui/.classpath index 4a00becd81..3628e33687 100644 --- a/org.eclipse.m2e.sourcelookup.ui/.classpath +++ b/org.eclipse.m2e.sourcelookup.ui/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.m2e.sourcelookup.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.sourcelookup.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..62ef3488cc --- /dev/null +++ b/org.eclipse.m2e.sourcelookup.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/org.eclipse.m2e.sourcelookup.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.sourcelookup.ui/META-INF/MANIFEST.MF index d431a569ba..de3d97d03a 100644 --- a/org.eclipse.m2e.sourcelookup.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.sourcelookup.ui/META-INF/MANIFEST.MF @@ -21,6 +21,6 @@ Require-Bundle: org.eclipse.ui, org.eclipse.jdt.core;bundle-version="3.9.0", org.eclipse.core.resources, org.eclipse.debug.core -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-ActivationPolicy: lazy Automatic-Module-Name: org.eclipse.m2e.sourcelookup.ui diff --git a/org.eclipse.m2e.sourcelookup.ui/src/org/eclipse/m2e/sourcelookup/ui/internal/ImportBinaryProjectHandler.java b/org.eclipse.m2e.sourcelookup.ui/src/org/eclipse/m2e/sourcelookup/ui/internal/ImportBinaryProjectHandler.java index 2b269f531b..2b3139a333 100644 --- a/org.eclipse.m2e.sourcelookup.ui/src/org/eclipse/m2e/sourcelookup/ui/internal/ImportBinaryProjectHandler.java +++ b/org.eclipse.m2e.sourcelookup.ui/src/org/eclipse/m2e/sourcelookup/ui/internal/ImportBinaryProjectHandler.java @@ -37,9 +37,9 @@ public class ImportBinaryProjectHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); - if (selection instanceof IStructuredSelection && !selection.isEmpty()) { + if (selection instanceof IStructuredSelection structuredSelection && !selection.isEmpty()) { try { - importBinaryProjects(((IStructuredSelection) selection).getFirstElement()); + importBinaryProjects(structuredSelection.getFirstElement()); } catch (DebugException e) { throw new ExecutionException("Could not import binary project", e); } diff --git a/org.eclipse.m2e.sourcelookup.ui/src/org/eclipse/m2e/sourcelookup/ui/internal/SourceLookupInfoDialog.java b/org.eclipse.m2e.sourcelookup.ui/src/org/eclipse/m2e/sourcelookup/ui/internal/SourceLookupInfoDialog.java index 1cd707a9ab..726fc5527c 100644 --- a/org.eclipse.m2e.sourcelookup.ui/src/org/eclipse/m2e/sourcelookup/ui/internal/SourceLookupInfoDialog.java +++ b/org.eclipse.m2e.sourcelookup.ui/src/org/eclipse/m2e/sourcelookup/ui/internal/SourceLookupInfoDialog.java @@ -189,9 +189,8 @@ private String toString(ISourceContainer container) { StringBuilder sb = new StringBuilder(); sb.append(container.getClass().getSimpleName()).append(" ").append(container.getName()); - if (container instanceof PackageFragmentRootSourceContainer) { - sb.append(" ").append( - ((PackageFragmentRootSourceContainer) container).getPackageFragmentRoot().getJavaProject().getProject()); + if (container instanceof PackageFragmentRootSourceContainer fragmentRoot) { + sb.append(" ").append(fragmentRoot.getPackageFragmentRoot().getJavaProject().getProject()); } return sb.toString(); diff --git a/org.eclipse.m2e.sourcelookup/.classpath b/org.eclipse.m2e.sourcelookup/.classpath index 4a00becd81..3628e33687 100644 --- a/org.eclipse.m2e.sourcelookup/.classpath +++ b/org.eclipse.m2e.sourcelookup/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.m2e.sourcelookup/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.sourcelookup/.settings/org.eclipse.jdt.core.prefs index c9545f06a4..62ef3488cc 100644 --- a/org.eclipse.m2e.sourcelookup/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.m2e.sourcelookup/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,9 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.source=17 diff --git a/org.eclipse.m2e.sourcelookup/META-INF/MANIFEST.MF b/org.eclipse.m2e.sourcelookup/META-INF/MANIFEST.MF index 60e3d1ad18..21363a48fc 100644 --- a/org.eclipse.m2e.sourcelookup/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.sourcelookup/META-INF/MANIFEST.MF @@ -1,11 +1,11 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.m2e.sourcelookup;singleton:=true -Bundle-Version: 1.18.0.qualifier +Bundle-Version: 1.19.0.qualifier Bundle-Vendor: Eclipse.org - m2e Bundle-Name: M2E Source Lookup Core -Require-Bundle: org.eclipse.m2e.launching;bundle-version="1.16.0", - org.eclipse.m2e.core;bundle-version="1.16.0", +Require-Bundle: org.eclipse.m2e.launching;bundle-version="2.0.0", + org.eclipse.m2e.core;bundle-version="2.0.0", org.eclipse.m2e.maven.runtime;bundle-version="1.16.0", org.eclipse.jdt.core;bundle-version="3.7.0", org.eclipse.jdt.debug;bundle-version="3.8.0", @@ -19,7 +19,7 @@ Require-Bundle: org.eclipse.m2e.launching;bundle-version="1.16.0", org.eclipse.core.variables;bundle-version="3.2.0", org.apache.commons.codec;bundle-version="1.14.0" Import-Package: org.slf4j;version="[1.6.2,2.0.0)" -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-ActivationPolicy: lazy Eclipse-BundleShape: dir Export-Package: org.eclipse.m2e.sourcelookup.internal.launch;x-friends:="org.eclipse.m2e.sourcelookup.ui,org.eclipse.m2e.binaryproject" diff --git a/target-platform/target-platform.target b/target-platform/target-platform.target index 0a44013a4d..f7be31c6be 100644 --- a/target-platform/target-platform.target +++ b/target-platform/target-platform.target @@ -1,7 +1,7 @@ - +