From 05d97888a4f8ee5ddc743ac035124d9f421275c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Thu, 26 Dec 2024 20:39:40 +0200 Subject: [PATCH] Remove pre Java 1.5 checks form o.e.jdt.ui/core extensions and friends ECJ mandates Java 8 level thus this code is always noop. --- .../manipulation/OrganizeImportsOperation.java | 2 +- .../UnresolvedElementsBaseSubProcessor.java | 10 ++-------- .../core/manipulation/dom/ASTResolving.java | 10 +--------- .../corext/template/java/JavaContextCore.java | 12 +++++------- .../jdt/ui/tests/quickfix/UtilitiesTest.java | 4 ++-- .../codemanipulation/AddImportsOperation.java | 14 ++++++-------- .../internal/corext/fix/NullAnnotationsFix.java | 7 +------ .../fix/NullAnnotationsRewriteOperations.java | 12 ------------ 8 files changed, 18 insertions(+), 53 deletions(-) diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/OrganizeImportsOperation.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/OrganizeImportsOperation.java index 4b6d8aaee35..013664edccb 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/OrganizeImportsOperation.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/OrganizeImportsOperation.java @@ -203,7 +203,7 @@ private static class UnresolvedTypeData { public UnresolvedTypeData(SimpleName ref) { this.ref= ref; - this.typeKinds= ASTResolving.getPossibleTypeKinds(ref, true); + this.typeKinds= ASTResolving.getPossibleTypeKinds(ref); this.foundInfos= new ArrayList<>(3); } diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsBaseSubProcessor.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsBaseSubProcessor.java index 0986013f783..76b5e055382 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsBaseSubProcessor.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsBaseSubProcessor.java @@ -706,12 +706,6 @@ private boolean hasFieldWithName(ITypeBinding typeBinding, String name) { return false; } - private int evauateTypeKind(ASTNode node, IJavaProject project) { - int kind= ASTResolving.getPossibleTypeKinds(node, JavaModelUtil.is50OrHigher(project)); - return kind; - } - - public void collectTypeProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); @@ -725,7 +719,7 @@ public void collectTypeProposals(IInvocationContext context, IProblemLocation pr } IJavaProject javaProject= cu.getJavaProject(); - int kind= evauateTypeKind(selectedNode, javaProject); + int kind= ASTResolving.getPossibleTypeKinds(selectedNode); if (kind == TypeKinds.REF_TYPES) { SimpleName s= addEnhancedForWithoutTypeProposals(cu, selectedNode, proposals); @@ -830,7 +824,7 @@ public void collectTypeProposals(IInvocationContext context, IProblemLocation pr } if (selectedNode != node) { - kind= evauateTypeKind(node, javaProject); + kind= ASTResolving.getPossibleTypeKinds(node); } if ((kind & (TypeKinds.CLASSES | TypeKinds.INTERFACES)) != 0) { kind &= ~TypeKinds.ANNOTATIONS; // only propose annotations when there are no other suggestions diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java index 02f32390e1d..ea7bad05e9d 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java @@ -1127,15 +1127,7 @@ public static CompilationUnit createQuickFixAST(ICompilationUnit compilationUnit return (CompilationUnit) astParser.createAST(monitor); } - public static int getPossibleTypeKinds(ASTNode node, boolean is50OrHigher) { - int kinds= internalGetPossibleTypeKinds(node); - if (!is50OrHigher) { - kinds &= (TypeKinds.INTERFACES | TypeKinds.CLASSES); - } - return kinds; - } - - private static int internalGetPossibleTypeKinds(ASTNode node) { + public static int getPossibleTypeKinds(ASTNode node) { int kind= TypeKinds.ALL_TYPES; int mask= TypeKinds.ALL_TYPES | TypeKinds.VOIDTYPE; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/JavaContextCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/JavaContextCore.java index 31a4e755c2f..fe9eab997c0 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/JavaContextCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/JavaContextCore.java @@ -626,11 +626,9 @@ private CompilationUnit getASTRoot(ICompilationUnit compilationUnit) { * Finds a type by the simple name. From AddImportsOperation */ private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor, ICompilationUnit cu) throws JavaModelException { - boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.getJavaProject()); - int typeKinds= TypeKinds.ALL_TYPES; if (nameNode != null) { - typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher); + typeKinds= ASTResolving.getPossibleTypeKinds(nameNode); } ArrayList typeInfos= new ArrayList<>(); @@ -640,7 +638,7 @@ private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope sea ArrayList typeRefsFound= new ArrayList<>(typeInfos.size()); for (TypeNameMatch curr : typeInfos) { if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package - if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr, cu)) { + if (isOfKind(curr, typeKinds) && isVisible(curr, cu)) { typeRefsFound.add(curr); } } @@ -665,13 +663,13 @@ private int getSearchForConstant(int typeKinds) { } } - private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) { + private boolean isOfKind(TypeNameMatch curr, int typeKinds) { int flags= curr.getModifiers(); if (Flags.isAnnotation(flags)) { - return is50OrHigher && ((typeKinds & TypeKinds.ANNOTATIONS) != 0); + return (typeKinds & TypeKinds.ANNOTATIONS) != 0; } if (Flags.isEnum(flags)) { - return is50OrHigher && ((typeKinds & TypeKinds.ENUMS) != 0); + return (typeKinds & TypeKinds.ENUMS) != 0; } if (Flags.isInterface(flags)) { return (typeKinds & TypeKinds.INTERFACES) != 0; diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UtilitiesTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UtilitiesTest.java index 54a475dda54..e02a985a2e3 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UtilitiesTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UtilitiesTest.java @@ -209,7 +209,7 @@ public void testGetPossibleTypeKinds() throws Exception { FieldDeclaration[] fields= ((TypeDeclaration) astRoot.types().get(0)).getFields(); for (int i= 0; i < fields.length; i++) { ASTNode node= NodeFinder.perform(astRoot, buf.indexOf("X", fields[i].getStartPosition()), 1); - int kinds= ASTResolving.getPossibleTypeKinds(node, true); + int kinds= ASTResolving.getPossibleTypeKinds(node); if (kinds != expected[i]) { assertEquals("Guessing failed for " + fields[i].toString(), expected[i], kinds); } @@ -237,7 +237,7 @@ public void testGetPossibleTypeKindsForTypes() throws Exception { for (int i = 0; i < astRoot.types().size(); i++) { TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(i); ASTNode node= NodeFinder.perform(astRoot, buf.indexOf("X", typeDecl.getStartPosition()), 1); - int kinds= ASTResolving.getPossibleTypeKinds(node, true); + int kinds= ASTResolving.getPossibleTypeKinds(node); assertEquals("Guessing failed for " + node.toString(), expected[i], kinds); } } diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddImportsOperation.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddImportsOperation.java index d06b50c32e2..8e40eb7c395 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddImportsOperation.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddImportsOperation.java @@ -272,7 +272,7 @@ private TextEdit evaluateEdits(CompilationUnit root, ImportRewrite importRewrite return null; } return new ReplaceEdit(qualifierStart, simpleNameStart - qualifierStart, ""); //$NON-NLS-1$ - } else if (JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject()) && (binding instanceof IVariableBinding || binding instanceof IMethodBinding)) { + } else if (binding instanceof IVariableBinding || binding instanceof IMethodBinding) { boolean isField= binding instanceof IVariableBinding; ITypeBinding declaringClass= isField ? ((IVariableBinding) binding).getDeclaringClass() : ((IMethodBinding) binding).getDeclaringClass(); if (declaringClass == null) { @@ -447,11 +447,9 @@ private int getSearchForConstant(int typeKinds) { * Finds a type by the simple name. */ private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor) throws JavaModelException { - boolean is50OrHigher= JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject()); - int typeKinds= TypeKinds.ALL_TYPES; if (nameNode != null) { - typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher); + typeKinds= ASTResolving.getPossibleTypeKinds(nameNode); } ArrayList typeInfos= new ArrayList<>(); @@ -463,7 +461,7 @@ private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope sea for (int i= 0, len= typeInfos.size(); i < len; i++) { TypeNameMatch curr= typeInfos.get(i); if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package - if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) { + if (isOfKind(curr, typeKinds) && isVisible(curr)) { typeRefsFound.add(curr); } } @@ -471,13 +469,13 @@ private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope sea return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]); } - private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) { + private boolean isOfKind(TypeNameMatch curr, int typeKinds) { int flags= curr.getModifiers(); if (Flags.isAnnotation(flags)) { - return is50OrHigher && (typeKinds & TypeKinds.ANNOTATIONS) != 0; + return (typeKinds & TypeKinds.ANNOTATIONS) != 0; } if (Flags.isEnum(flags)) { - return is50OrHigher && (typeKinds & TypeKinds.ENUMS) != 0; + return (typeKinds & TypeKinds.ENUMS) != 0; } if (Flags.isInterface(flags)) { return (typeKinds & TypeKinds.INTERFACES) != 0; diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsFix.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsFix.java index 0d8be70f602..94bc3b79280 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsFix.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsFix.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2018 GK Software AG and others. + * Copyright (c) 2011, 2024 GK Software AG and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -40,7 +40,6 @@ import org.eclipse.jdt.internal.corext.fix.NullAnnotationsRewriteOperations.RemoveRedundantAnnotationRewriteOperation; import org.eclipse.jdt.internal.corext.fix.NullAnnotationsRewriteOperations.SignatureAnnotationRewriteOperation; import org.eclipse.jdt.internal.corext.fix.TypeAnnotationRewriteOperations.MoveTypeAnnotationRewriteOperation; -import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.ui.cleanup.ICleanUpFix; @@ -166,10 +165,6 @@ public static NullAnnotationsFix createAddMissingDefaultNullnessAnnotationsFix(C // Entry for NullAnnotationsCleanup: public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] locations, int problemID) { - ICompilationUnit cu= (ICompilationUnit) compilationUnit.getJavaElement(); - if (!JavaModelUtil.is50OrHigher(cu.getJavaProject())) - return null; - List operations= new ArrayList<>(); if (locations == null) { org.eclipse.jdt.core.compiler.IProblem[] problems= compilationUnit.getProblems(); diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsRewriteOperations.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsRewriteOperations.java index da901a50437..2e78973e4de 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsRewriteOperations.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsRewriteOperations.java @@ -515,12 +515,6 @@ public void swapAnnotations() { fAnnotationToRemove= tmp; } - public boolean is50OrHigher() { - CompilationUnit compilationUnit= fUnit; - ICompilationUnit cu= (ICompilationUnit) compilationUnit.getJavaElement(); - return JavaModelUtil.is50OrHigher(cu.getJavaProject()); - } - public ASTNode getCoveringNode() { return fProblem.getCoveringNode(fUnit); } @@ -543,9 +537,6 @@ public SignatureAnnotationRewriteOperation createAddAnnotationOperation(Set