From 5248d966bb41429662067c3eb76127e3be6b4445 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 6 Aug 2024 17:08:44 -0400 Subject: [PATCH 1/3] Fix "fix return type" quickfix for type param return type (#1559) The old method would propose the erasure of the type param if the compliance was set pre 1.5. Instead, now two quickfixes are always proposed: 1. Replace the return type with the erasure 2. Introduce a new type param with the same bounds, importing the bounds and adding the type variable for any raw types Fixes #1558 Signed-off-by: David Thompson --- .../TypeMismatchBaseSubProcessor.java | 19 +- .../TypeChangeCorrectionProposalCore.java | 86 ++++ .../quickfix/TypeMismatchQuickFixTests.java | 378 +++++++++++++++++- 3 files changed, 473 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/TypeMismatchBaseSubProcessor.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/TypeMismatchBaseSubProcessor.java index 05b5ddc292c..ac5341681e3 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/TypeMismatchBaseSubProcessor.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/TypeMismatchBaseSubProcessor.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.stream.Stream; import org.eclipse.core.runtime.CoreException; @@ -381,12 +382,20 @@ public void collectIncompatibleReturnTypeProposals(IInvocationContext context, I ICompilationUnit cu= context.getCompilationUnit(); IMethodBinding methodDecl= methodDeclBinding.getMethodDeclaration(); ITypeBinding overriddenReturnType= overridden.getReturnType(); - if (! JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) { - overriddenReturnType= overriddenReturnType.getErasure(); + // propose erasure + if (decl.typeParameters().isEmpty() || overriddenReturnType.getTypeBounds().length == 0 || Stream.of(overriddenReturnType.getTypeBounds()).allMatch(bound -> bound.getTypeArguments().length == 0)) { + T p1= createChangeIncompatibleReturnTypeProposal(cu, methodDecl, astRoot, overriddenReturnType.getErasure(), false, IProposalRelevance.CHANGE_RETURN_TYPE); + if (p1 != null) + proposals.add(p1); + } + + // propose using (and potentially introducing) the type variable + if (overriddenReturnType.isTypeVariable()) { + T p2 = createChangeIncompatibleReturnTypeProposal(cu, methodDecl, astRoot, overriddenReturnType, false, IProposalRelevance.CHANGE_RETURN_TYPE); + if (p2 != null) { + proposals.add(p2); + } } - T p1= createChangeIncompatibleReturnTypeProposal(cu, methodDecl, astRoot, overriddenReturnType, false, IProposalRelevance.CHANGE_RETURN_TYPE); - if (p1 != null) - proposals.add(p1); ICompilationUnit targetCu= cu; diff --git a/org.eclipse.jdt.core.manipulation/proposals/org/eclipse/jdt/internal/ui/text/correction/proposals/TypeChangeCorrectionProposalCore.java b/org.eclipse.jdt.core.manipulation/proposals/org/eclipse/jdt/internal/ui/text/correction/proposals/TypeChangeCorrectionProposalCore.java index 46e0908536c..37deece4e4e 100644 --- a/org.eclipse.jdt.core.manipulation/proposals/org/eclipse/jdt/internal/ui/text/correction/proposals/TypeChangeCorrectionProposalCore.java +++ b/org.eclipse.jdt.core.manipulation/proposals/org/eclipse/jdt/internal/ui/text/correction/proposals/TypeChangeCorrectionProposalCore.java @@ -17,12 +17,15 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; @@ -54,13 +57,17 @@ import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.ParameterizedType; import org.eclipse.jdt.core.dom.PrimitiveType; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.TagElement; import org.eclipse.jdt.core.dom.TextElement; import org.eclipse.jdt.core.dom.Type; +import org.eclipse.jdt.core.dom.TypeParameter; import org.eclipse.jdt.core.dom.VariableDeclarationExpression; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.VariableDeclarationStatement; +import org.eclipse.jdt.core.dom.WildcardType; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; @@ -273,9 +280,49 @@ protected ASTRewrite getRewrite() throws CoreException { if (declNode instanceof MethodDeclaration) { MethodDeclaration methodDecl= (MethodDeclaration) declNode; Type origReturnType= methodDecl.getReturnType2(); + + if (fNewType.isTypeVariable()) { + IMethodBinding realMethodBinding= fNewType.getDeclaringMethod(); + ITypeBinding[] typeParameters= realMethodBinding.getTypeParameters(); + + if (!methodDecl.typeParameters().isEmpty()) { + Map typeParamNameMap= new HashMap<>(); + for (int i = 0; i < methodDecl.typeParameters().size(); i++) { + typeParamNameMap.put(typeParameters[i].getName(), ((List) methodDecl.typeParameters()).get(i).getName().toString()); + } + String existingTypeVarIdent= typeParamNameMap.get(fNewType.getName()); + type= ast.newSimpleType(ast.newSimpleName(existingTypeVarIdent)); + } else { + // add type parameters as they appear in the parent method + // notably, if you add the type variables, you must add ALL of them. + // eg. if you have T myMethod(Class clazz) + // you cannot override it with T myMethod(Class clazz) + ListRewrite typeParameterRewrite= rewrite.getListRewrite(methodDecl, MethodDeclaration.TYPE_PARAMETERS_PROPERTY); + for (ITypeBinding parameter : typeParameters) { + TypeParameter newTypeParameter= ast.newTypeParameter(); + SimpleName newTypeParameterName= ast.newSimpleName(parameter.getName()); + newTypeParameter.setName(newTypeParameterName); + Stream.of(parameter.getTypeBounds()) // + .forEach(bound -> { + newTypeParameter.typeBounds().add(getTypeNodeFromBinding(bound, ast, imports, context)); + }); + typeParameterRewrite.insertLast(newTypeParameter, null); + } + + // Update the parameter types to match that of the resolved method. + // Some of the existing parameter types may be raw instead of containing the expected type parameters. + // Without inserting the type parameters in these cases, the signature will no longer match the overridden type. + for (int i = 0 ; i < methodDecl.parameters().size(); i++) { + SingleVariableDeclaration svd= (SingleVariableDeclaration)methodDecl.parameters().get(i); + rewrite.set(svd, SingleVariableDeclaration.TYPE_PROPERTY, getTypeNodeFromBinding(realMethodBinding.getParameterTypes()[i], ast, imports, context), null); + } + } + } + rewrite.set(methodDecl, MethodDeclaration.RETURN_TYPE2_PROPERTY, type, null); DimensionRewrite.removeAllChildren(methodDecl, MethodDeclaration.EXTRA_DIMENSIONS2_PROPERTY, rewrite, null); TypeAnnotationRewrite.removePureTypeAnnotations(methodDecl, MethodDeclaration.MODIFIERS2_PROPERTY, rewrite, null); + // add javadoc tag Javadoc javadoc= methodDecl.getJavadoc(); if (javadoc != null && origReturnType != null && origReturnType.isPrimitiveType() @@ -526,4 +573,43 @@ private void handledInferredParametrizedType(ASTNode node, ASTNode declaringNode } } + private Type getTypeNodeFromBinding(ITypeBinding typeBinding, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) { + + if (typeBinding.isWildcardType()) { + WildcardType wildcardType = ast.newWildcardType(); + ITypeBinding bound = typeBinding.getBound(); + if (bound != null) { + Type boundNode = getTypeNodeFromBinding(bound, ast, importRewrite, context); + wildcardType.setBound(boundNode); + wildcardType.setUpperBound(typeBinding.isUpperbound()); + } + return wildcardType; + } + + if (typeBinding.isArray()) { + Type elementTypeNode = getTypeNodeFromBinding(typeBinding.getElementType(), ast, importRewrite, context); + return ast.newArrayType(elementTypeNode, typeBinding.getDimensions()); + } + + if (typeBinding.isTypeVariable()) { + return ast.newSimpleType(ast.newSimpleName(typeBinding.getName())); + } + + // import the simple/parameterized type if needed + importRewrite.addImport(typeBinding, ast, context, fTypeLocation); + + // create the simple/parameterized + SimpleName simpleName = ast.newSimpleName(typeBinding.getErasure().getName()); + SimpleType simpleType = ast.newSimpleType(simpleName); + if (typeBinding.isParameterizedType()) { + ParameterizedType parameterizedType = ast.newParameterizedType(simpleType); + for (ITypeBinding argument : typeBinding.getTypeArguments()) { + Type typeArgument = getTypeNodeFromBinding(argument, ast, importRewrite, context); + parameterizedType.typeArguments().add(typeArgument); + } + return parameterizedType; + } + return simpleType; + } + } \ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java index 9f6d4760a60..f309fd08061 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java @@ -1493,13 +1493,29 @@ public void getAnnotation(Class annotationClass) { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 1); + assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview1= getPreviewContent(proposal); String expected1= """ + package test1; + import java.lang.annotation.Annotation; + import java.lang.reflect.AccessibleObject; + public class E { + void m() { + new AccessibleObject() { + public Annotation getAnnotation(Class annotationClass) { + } + }; + } + } + """; + + String preview2= getPreviewContent((CUCorrectionProposal)proposals.get(1)); + + String expected2= """ package test1; import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; @@ -1513,7 +1529,7 @@ public T getAnnotation(Class annotationClass) { } """; - assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 }); + assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); } @Test @@ -1536,7 +1552,7 @@ public void getAnnotation(Class annotationClass) { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 1); + assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); @@ -1544,18 +1560,370 @@ public void getAnnotation(Class annotationClass) { String expected1= """ package test1; + import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; public class E { void m() { new AccessibleObject() { - public T getAnnotation(Class annotationClass) { + public Annotation getAnnotation(Class annotationClass) { } }; } } """; - assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 }); + String preview2= getPreviewContent((CUCorrectionProposal)proposals.get(1)); + + String expected2= """ + package test1; + import java.lang.annotation.Annotation; + import java.lang.reflect.AccessibleObject; + public class E { + void m() { + new AccessibleObject() { + public T getAnnotation(Class annotationClass) { + } + }; + } + } + """; + + assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); + } + + @Test + public void testMismatchingReturnTypeOnGenericMethodNestedTypeArgs() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + + String str= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract >> T myMethod(Class asdf); + } + private static class MyExtensionClass extends MyClass { + @Override + void myMethod(Class asdf) { + } + } + } + """; + ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList proposals= collectCorrections(cu, astRoot); + assertNumberOfProposals(proposals, 3); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + String expected1= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract >> T myMethod(Class asdf); + } + private static class MyExtensionClass extends MyClass { + @Override + List myMethod(Class asdf) { + } + } + } + """; + + String preview2= getPreviewContent((CUCorrectionProposal)proposals.get(1)); + + String expected2= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract >> T myMethod(Class asdf); + } + private static class MyExtensionClass extends MyClass { + @Override + >> T myMethod(Class asdf) { + } + } + } + """; + + String preview3= getPreviewContent((CUCorrectionProposal)proposals.get(2)); + + String expected3= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract >> void myMethod(Class asdf); + } + private static class MyExtensionClass extends MyClass { + @Override + void myMethod(Class asdf) { + } + } + } + """; + + assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2 , expected3}); + } + + @Test + public void testMismatchingReturnTypeOnGenericMethodNestedTypeArgs2() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + + String str= """ + package test1; + import java.util.List; + + public class E { + static interface Interfacable { + void itsMethod(); + } + private abstract static class MyClass { + abstract , ? super Comparable>>> T myMethod(Interfacable, T> asdf); + } + private static class MyExtensionClass extends MyClass { + @Override + void myMethod(Interfacable asdf) { + } + } + } + """; + ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList proposals= collectCorrections(cu, astRoot); + assertNumberOfProposals(proposals, 3); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + String expected1= """ + package test1; + import java.util.List; + + public class E { + static interface Interfacable { + void itsMethod(); + } + private abstract static class MyClass { + abstract , ? super Comparable>>> T myMethod(Interfacable, T> asdf); + } + private static class MyExtensionClass extends MyClass { + @Override + List myMethod(Interfacable asdf) { + } + } + } + """; + + String preview2= getPreviewContent((CUCorrectionProposal)proposals.get(1)); + + String expected2= """ + package test1; + import java.util.List; + + public class E { + static interface Interfacable { + void itsMethod(); + } + private abstract static class MyClass { + abstract , ? super Comparable>>> T myMethod(Interfacable, T> asdf); + } + private static class MyExtensionClass extends MyClass { + @Override + , ? super Comparable>>> T myMethod(Interfacable, T> asdf) { + } + } + } + """; + + String preview3= getPreviewContent((CUCorrectionProposal)proposals.get(2)); + + String expected3= """ + package test1; + import java.util.List; + + public class E { + static interface Interfacable { + void itsMethod(); + } + private abstract static class MyClass { + abstract , ? super Comparable>>> void myMethod(Interfacable, T> asdf); + } + private static class MyExtensionClass extends MyClass { + @Override + void myMethod(Interfacable asdf) { + } + } + } + """; + + assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2 , expected3 }); + } + + @Test + public void testMismatchingReturnTypeOnGenericMethodNestedTypeArgs3() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + + String str= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract > T myMethod(Class clazz); + } + private static class MyExtensionClass extends MyClass { + @Override + > void myMethod(Class clazz) { + + } + } + } + """; + ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList proposals= collectCorrections(cu, astRoot); + assertNumberOfProposals(proposals, 2); + assertCorrectLabels(proposals); + + String preview1= getPreviewContent((CUCorrectionProposal)proposals.get(0)); + + String expected1= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract > T myMethod(Class clazz); + } + private static class MyExtensionClass extends MyClass { + @Override + > T myMethod(Class clazz) { + + } + } + } + """; + + String preview2= getPreviewContent((CUCorrectionProposal)proposals.get(1)); + + String expected2= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract > void myMethod(Class clazz); + } + private static class MyExtensionClass extends MyClass { + @Override + > void myMethod(Class clazz) { + + } + } + } + """; + + assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); + } + + @Test + public void testMismatchingReturnTypeOnGenericMethodNestedTypeArgs4() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + + String str= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract T myMethod(Class clazz); + } + private static class MyExtensionClass extends MyClass { + @Override + void myMethod(Class clazz) { + + } + } + } + """; + ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList proposals= collectCorrections(cu, astRoot); + assertNumberOfProposals(proposals, 3); + assertCorrectLabels(proposals); + + String preview1= getPreviewContent((CUCorrectionProposal)proposals.get(0)); + + String expected1= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract T myMethod(Class clazz); + } + private static class MyExtensionClass extends MyClass { + @Override + Object myMethod(Class clazz) { + + } + } + } + """; + + String preview2= getPreviewContent((CUCorrectionProposal)proposals.get(1)); + + String expected2= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract T myMethod(Class clazz); + } + private static class MyExtensionClass extends MyClass { + @Override + M myMethod(Class clazz) { + + } + } + } + """; + + String preview3= getPreviewContent((CUCorrectionProposal)proposals.get(2)); + + String expected3= """ + package test1; + import java.util.List; + + public class E { + private abstract static class MyClass { + abstract void myMethod(Class clazz); + } + private static class MyExtensionClass extends MyClass { + @Override + void myMethod(Class clazz) { + + } + } + } + """; + + assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 }); } @Test From e2aacdfb1e41bafb4b0eb7b345b905c0acbd2a67 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Wed, 7 Aug 2024 09:04:58 +0200 Subject: [PATCH 2/3] Bump qualifier of org.eclipse.jdt.ui Pick up changes from https://github.com/eclipse-jdt/eclipse.jdt.core/pull/2770 --- org.eclipse.jdt.ui/forceQualifierUpdate.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jdt.ui/forceQualifierUpdate.txt b/org.eclipse.jdt.ui/forceQualifierUpdate.txt index a728eb93a05..565dbbd478b 100644 --- a/org.eclipse.jdt.ui/forceQualifierUpdate.txt +++ b/org.eclipse.jdt.ui/forceQualifierUpdate.txt @@ -20,4 +20,5 @@ Comparator errors in I20230906-0400 Comparator errors in I20231127-0750 https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1923 https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1979 -https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/2044 \ No newline at end of file +https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/2044 +Pick up changes from https://github.com/eclipse-jdt/eclipse.jdt.core/pull/2770 From 11901207db25ce7aea6b339595c15a95b1ef2e51 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Tue, 6 Aug 2024 20:02:24 +0200 Subject: [PATCH 3/3] Use new return-type of JC.getAllJavaSourceVersionsSupportedByCompiler() Leverage the new return-type of JavaCore.getAllJavaSourceVersionsSupportedByCompiler(), adjusted in https://github.com/eclipse-jdt/eclipse.jdt.core/pull/2770 --- .../org/eclipse/jdt/internal/corext/util/JavaModelUtil.java | 4 ++-- .../ui/preferences/ComplianceConfigurationBlock.java | 6 +++--- .../eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java index 9f5d12ffc64..866a7dea306 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java @@ -1155,7 +1155,7 @@ public static String getExecutionEnvironmentCompliance(IExecutionEnvironment exe if(JavaCore.isJavaSourceVersionSupportedByCompiler(compliance)) { return compliance; } - return JavaCore.getFirstJavaSourceVersionSupportedByCompiler(); + return JavaCore.getAllJavaSourceVersionsSupportedByCompiler().first(); } } @@ -1192,7 +1192,7 @@ public static String getExecutionEnvironmentCompliance(IExecutionEnvironment exe } else if (desc.indexOf(JavaCore.VERSION_1_8) != -1) { return JavaCore.VERSION_1_8; } - return JavaCore.getFirstJavaSourceVersionSupportedByCompiler(); + return JavaCore.getAllJavaSourceVersionsSupportedByCompiler().first(); } /** diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java index 1d0cb258e61..e084acca408 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ComplianceConfigurationBlock.java @@ -442,7 +442,7 @@ public void widgetSelected(SelectionEvent e) { fJRE50InfoText= new Link(infoComposite, SWT.WRAP); fJRE50InfoText.setFont(composite.getFont()); // set a text: not the real one, just for layouting - String versionLabel= getVersionLabel(JavaCore.getFirstJavaSourceVersionSupportedByCompiler()); + String versionLabel= getVersionLabel(JavaCore.getAllJavaSourceVersionsSupportedByCompiler().first()); fJRE50InfoText.setText(Messages.format(PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info_project, new String[] { versionLabel, versionLabel })); fJRE50InfoText.setVisible(false); fJRE50InfoText.addSelectionListener(new SelectionListener() { @@ -1170,8 +1170,8 @@ private void updateComplianceDefaultSettings(boolean rememberOld, String oldComp reportPreview= WARNING; assertAsId= ERROR; enumAsId= ERROR; - source= JavaCore.getFirstJavaSourceVersionSupportedByCompiler(); - target= JavaCore.getFirstJavaSourceVersionSupportedByCompiler(); + source= JavaCore.getAllJavaSourceVersionsSupportedByCompiler().first(); + target= JavaCore.getAllJavaSourceVersionsSupportedByCompiler().first(); } } } else { diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java index 81128cbbc8f..e7f16bdccba 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java @@ -474,8 +474,8 @@ private void initializeJvmFields () { fInstalledJVMs= getWorkspaceJREs(); Arrays.sort(fInstalledJVMs, (i0, i1) -> { if (i1 instanceof IVMInstall2 && i0 instanceof IVMInstall2) { - String cc0= JavaModelUtil.getCompilerCompliance((IVMInstall2) i0, JavaCore.getFirstJavaSourceVersionSupportedByCompiler()); - String cc1= JavaModelUtil.getCompilerCompliance((IVMInstall2) i1, JavaCore.getFirstJavaSourceVersionSupportedByCompiler()); + String cc0= JavaModelUtil.getCompilerCompliance((IVMInstall2) i0, JavaCore.getAllJavaSourceVersionsSupportedByCompiler().first()); + String cc1= JavaModelUtil.getCompilerCompliance((IVMInstall2) i1, JavaCore.getAllJavaSourceVersionsSupportedByCompiler().first()); int result= JavaCore.compareJavaVersions(cc1, cc0); if (result != 0) return result;