Skip to content

Commit

Permalink
Move org.eclipse.m2e.core.ui to Java 17
Browse files Browse the repository at this point in the history
+ use some named instanceof
+ use some switch expressions
+ Replace some content providers with ArrayContentProvider
  • Loading branch information
mickaelistria committed Jun 2, 2022
1 parent dd9ce55 commit 28814a0
Show file tree
Hide file tree
Showing 49 changed files with 313 additions and 457 deletions.
2 changes: 1 addition & 1 deletion m2e-core-tests
Submodule m2e-core-tests updated 28 files
+0 −8 .gitignore
+0 −17 .project
+0 −15 org.eclipse.m2e.editor.tests/.classpath
+5 −0 org.eclipse.m2e.editor.tests/.gitignore
+0 −28 org.eclipse.m2e.editor.tests/.project
+1 −1 org.eclipse.m2e.editor.tests/build.properties
+43 −0 org.eclipse.m2e.editor.tests/m2e.editor.tests.launch
+11 −0 org.eclipse.m2e.editor.tests/plugin_customization.ini
+54 −0 org.eclipse.m2e.editor.tests/pom.xml
+1 −0 org.eclipse.m2e.editor.tests/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialogTest.java
+0 −15 org.eclipse.m2e.tests/.classpath
+5 −0 org.eclipse.m2e.tests/.gitignore
+0 −28 org.eclipse.m2e.tests/.project
+0 −1 org.eclipse.m2e.tests/META-INF/MANIFEST.MF
+1 −1 org.eclipse.m2e.tests/build.properties
+11 −0 org.eclipse.m2e.tests/plugin_customization.ini
+44 −0 org.eclipse.m2e.tests/pom.xml
+1 −1 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/embedder/MavenImplTest.java
+11 −9 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/embedder/MavenRuntimeManagerTest.java
+56 −16 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/internal/embedder/EclipseClassRealmManagerDelegateTest.java
+0 −1 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/internal/refactoring/ExcludeArtifactRefactoringTest.java
+7 −44 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/launch/MavenLaunchDelegateTest.java
+14 −11 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/launch/MavenRuntimeClasspathProviderTest.java
+5 −5 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/lifecycle/LifecycleMappingTest.java
+258 −0 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/mocks/MockLaunchConfiguration.java
+156 −0 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/mocks/MockLaunchConfigurationType.java
+2 −10 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/profiles/AbstractMavenProfileTest.java
+1 −1 org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/project/MavenProjectFacadeTest.java
2 changes: 1 addition & 1 deletion org.eclipse.m2e.core.ui/.classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
Expand Down
8 changes: 4 additions & 4 deletions org.eclipse.m2e.core.ui/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IProject> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public static <T> T getType(Object element, Class<T> 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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -383,20 +380,18 @@ public static IFile getPomFileFromPomEditorOrViewSelection(ISelection selection)
*/
public static IProject[] getProjects(ISelection selection, boolean includeAll) {
ArrayList<IProject> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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$
}

}
Loading

0 comments on commit 28814a0

Please sign in to comment.