Skip to content

Commit af96d1e

Browse files
committed
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.
1 parent 6669c21 commit af96d1e

File tree

8 files changed

+18
-53
lines changed

8 files changed

+18
-53
lines changed

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/OrganizeImportsOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private static class UnresolvedTypeData {
203203

204204
public UnresolvedTypeData(SimpleName ref) {
205205
this.ref= ref;
206-
this.typeKinds= ASTResolving.getPossibleTypeKinds(ref, true);
206+
this.typeKinds= ASTResolving.getPossibleTypeKinds(ref);
207207
this.foundInfos= new ArrayList<>(3);
208208
}
209209

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsBaseSubProcessor.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -706,12 +706,6 @@ private boolean hasFieldWithName(ITypeBinding typeBinding, String name) {
706706
return false;
707707
}
708708

709-
private int evauateTypeKind(ASTNode node, IJavaProject project) {
710-
int kind= ASTResolving.getPossibleTypeKinds(node, JavaModelUtil.is50OrHigher(project));
711-
return kind;
712-
}
713-
714-
715709
public void collectTypeProposals(IInvocationContext context, IProblemLocation problem, Collection<T> proposals) throws CoreException {
716710
ICompilationUnit cu= context.getCompilationUnit();
717711

@@ -725,7 +719,7 @@ public void collectTypeProposals(IInvocationContext context, IProblemLocation pr
725719
}
726720

727721
IJavaProject javaProject= cu.getJavaProject();
728-
int kind= evauateTypeKind(selectedNode, javaProject);
722+
int kind= ASTResolving.getPossibleTypeKinds(selectedNode);
729723

730724
if (kind == TypeKinds.REF_TYPES) {
731725
SimpleName s= addEnhancedForWithoutTypeProposals(cu, selectedNode, proposals);
@@ -830,7 +824,7 @@ public void collectTypeProposals(IInvocationContext context, IProblemLocation pr
830824
}
831825

832826
if (selectedNode != node) {
833-
kind= evauateTypeKind(node, javaProject);
827+
kind= ASTResolving.getPossibleTypeKinds(node);
834828
}
835829
if ((kind & (TypeKinds.CLASSES | TypeKinds.INTERFACES)) != 0) {
836830
kind &= ~TypeKinds.ANNOTATIONS; // only propose annotations when there are no other suggestions

org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,15 +1127,7 @@ public static CompilationUnit createQuickFixAST(ICompilationUnit compilationUnit
11271127
return (CompilationUnit) astParser.createAST(monitor);
11281128
}
11291129

1130-
public static int getPossibleTypeKinds(ASTNode node, boolean is50OrHigher) {
1131-
int kinds= internalGetPossibleTypeKinds(node);
1132-
if (!is50OrHigher) {
1133-
kinds &= (TypeKinds.INTERFACES | TypeKinds.CLASSES);
1134-
}
1135-
return kinds;
1136-
}
1137-
1138-
private static int internalGetPossibleTypeKinds(ASTNode node) {
1130+
public static int getPossibleTypeKinds(ASTNode node) {
11391131
int kind= TypeKinds.ALL_TYPES;
11401132

11411133
int mask= TypeKinds.ALL_TYPES | TypeKinds.VOIDTYPE;

org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/JavaContextCore.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,9 @@ private CompilationUnit getASTRoot(ICompilationUnit compilationUnit) {
626626
* Finds a type by the simple name. From AddImportsOperation
627627
*/
628628
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor, ICompilationUnit cu) throws JavaModelException {
629-
boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.getJavaProject());
630-
631629
int typeKinds= TypeKinds.ALL_TYPES;
632630
if (nameNode != null) {
633-
typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
631+
typeKinds= ASTResolving.getPossibleTypeKinds(nameNode);
634632
}
635633

636634
ArrayList<TypeNameMatch> typeInfos= new ArrayList<>();
@@ -640,7 +638,7 @@ private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope sea
640638
ArrayList<TypeNameMatch> typeRefsFound= new ArrayList<>(typeInfos.size());
641639
for (TypeNameMatch curr : typeInfos) {
642640
if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
643-
if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr, cu)) {
641+
if (isOfKind(curr, typeKinds) && isVisible(curr, cu)) {
644642
typeRefsFound.add(curr);
645643
}
646644
}
@@ -665,13 +663,13 @@ private int getSearchForConstant(int typeKinds) {
665663
}
666664
}
667665

668-
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
666+
private boolean isOfKind(TypeNameMatch curr, int typeKinds) {
669667
int flags= curr.getModifiers();
670668
if (Flags.isAnnotation(flags)) {
671-
return is50OrHigher && ((typeKinds & TypeKinds.ANNOTATIONS) != 0);
669+
return (typeKinds & TypeKinds.ANNOTATIONS) != 0;
672670
}
673671
if (Flags.isEnum(flags)) {
674-
return is50OrHigher && ((typeKinds & TypeKinds.ENUMS) != 0);
672+
return (typeKinds & TypeKinds.ENUMS) != 0;
675673
}
676674
if (Flags.isInterface(flags)) {
677675
return (typeKinds & TypeKinds.INTERFACES) != 0;

org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UtilitiesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void testGetPossibleTypeKinds() throws Exception {
209209
FieldDeclaration[] fields= ((TypeDeclaration) astRoot.types().get(0)).getFields();
210210
for (int i= 0; i < fields.length; i++) {
211211
ASTNode node= NodeFinder.perform(astRoot, buf.indexOf("X", fields[i].getStartPosition()), 1);
212-
int kinds= ASTResolving.getPossibleTypeKinds(node, true);
212+
int kinds= ASTResolving.getPossibleTypeKinds(node);
213213
if (kinds != expected[i]) {
214214
assertEquals("Guessing failed for " + fields[i].toString(), expected[i], kinds);
215215
}
@@ -237,7 +237,7 @@ public void testGetPossibleTypeKindsForTypes() throws Exception {
237237
for (int i = 0; i < astRoot.types().size(); i++) {
238238
TypeDeclaration typeDecl = (TypeDeclaration) astRoot.types().get(i);
239239
ASTNode node= NodeFinder.perform(astRoot, buf.indexOf("X", typeDecl.getStartPosition()), 1);
240-
int kinds= ASTResolving.getPossibleTypeKinds(node, true);
240+
int kinds= ASTResolving.getPossibleTypeKinds(node);
241241
assertEquals("Guessing failed for " + node.toString(), expected[i], kinds);
242242
}
243243
}

org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddImportsOperation.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private TextEdit evaluateEdits(CompilationUnit root, ImportRewrite importRewrite
272272
return null;
273273
}
274274
return new ReplaceEdit(qualifierStart, simpleNameStart - qualifierStart, ""); //$NON-NLS-1$
275-
} else if (JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject()) && (binding instanceof IVariableBinding || binding instanceof IMethodBinding)) {
275+
} else if (binding instanceof IVariableBinding || binding instanceof IMethodBinding) {
276276
boolean isField= binding instanceof IVariableBinding;
277277
ITypeBinding declaringClass= isField ? ((IVariableBinding) binding).getDeclaringClass() : ((IMethodBinding) binding).getDeclaringClass();
278278
if (declaringClass == null) {
@@ -447,11 +447,9 @@ private int getSearchForConstant(int typeKinds) {
447447
* Finds a type by the simple name.
448448
*/
449449
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor) throws JavaModelException {
450-
boolean is50OrHigher= JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject());
451-
452450
int typeKinds= TypeKinds.ALL_TYPES;
453451
if (nameNode != null) {
454-
typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
452+
typeKinds= ASTResolving.getPossibleTypeKinds(nameNode);
455453
}
456454

457455
ArrayList<TypeNameMatch> typeInfos= new ArrayList<>();
@@ -463,21 +461,21 @@ private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope sea
463461
for (int i= 0, len= typeInfos.size(); i < len; i++) {
464462
TypeNameMatch curr= typeInfos.get(i);
465463
if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package
466-
if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) {
464+
if (isOfKind(curr, typeKinds) && isVisible(curr)) {
467465
typeRefsFound.add(curr);
468466
}
469467
}
470468
}
471469
return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
472470
}
473471

474-
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
472+
private boolean isOfKind(TypeNameMatch curr, int typeKinds) {
475473
int flags= curr.getModifiers();
476474
if (Flags.isAnnotation(flags)) {
477-
return is50OrHigher && (typeKinds & TypeKinds.ANNOTATIONS) != 0;
475+
return (typeKinds & TypeKinds.ANNOTATIONS) != 0;
478476
}
479477
if (Flags.isEnum(flags)) {
480-
return is50OrHigher && (typeKinds & TypeKinds.ENUMS) != 0;
478+
return (typeKinds & TypeKinds.ENUMS) != 0;
481479
}
482480
if (Flags.isInterface(flags)) {
483481
return (typeKinds & TypeKinds.INTERFACES) != 0;

org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsFix.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2018 GK Software AG and others.
2+
* Copyright (c) 2011, 2024 GK Software AG and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -40,7 +40,6 @@
4040
import org.eclipse.jdt.internal.corext.fix.NullAnnotationsRewriteOperations.RemoveRedundantAnnotationRewriteOperation;
4141
import org.eclipse.jdt.internal.corext.fix.NullAnnotationsRewriteOperations.SignatureAnnotationRewriteOperation;
4242
import org.eclipse.jdt.internal.corext.fix.TypeAnnotationRewriteOperations.MoveTypeAnnotationRewriteOperation;
43-
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
4443
import org.eclipse.jdt.internal.corext.util.Messages;
4544

4645
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
@@ -166,10 +165,6 @@ public static NullAnnotationsFix createAddMissingDefaultNullnessAnnotationsFix(C
166165

167166
// Entry for NullAnnotationsCleanup:
168167
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] locations, int problemID) {
169-
ICompilationUnit cu= (ICompilationUnit) compilationUnit.getJavaElement();
170-
if (!JavaModelUtil.is50OrHigher(cu.getJavaProject()))
171-
return null;
172-
173168
List<CompilationUnitRewriteOperationWithSourceRange> operations= new ArrayList<>();
174169
if (locations == null) {
175170
org.eclipse.jdt.core.compiler.IProblem[] problems= compilationUnit.getProblems();

org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/NullAnnotationsRewriteOperations.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,6 @@ public void swapAnnotations() {
515515
fAnnotationToRemove= tmp;
516516
}
517517

518-
public boolean is50OrHigher() {
519-
CompilationUnit compilationUnit= fUnit;
520-
ICompilationUnit cu= (ICompilationUnit) compilationUnit.getJavaElement();
521-
return JavaModelUtil.is50OrHigher(cu.getJavaProject());
522-
}
523-
524518
public ASTNode getCoveringNode() {
525519
return fProblem.getCoveringNode(fUnit);
526520
}
@@ -543,9 +537,6 @@ public SignatureAnnotationRewriteOperation createAddAnnotationOperation(Set<Stri
543537
}
544538

545539
private SignatureAnnotationRewriteOperation createAddAnnotationOperation(boolean changeTargetMethod, boolean thisUnitOnly) {
546-
if (!is50OrHigher())
547-
return null;
548-
549540
ASTNode selectedNode= getCoveringNode();
550541
if (selectedNode == null)
551542
return null;
@@ -681,9 +672,6 @@ private SignatureAnnotationRewriteOperation createAddAnnotationOperation(boolean
681672
}
682673

683674
private SignatureAnnotationRewriteOperation createAddAnnotationToOverriddenOperation() {
684-
if (!is50OrHigher())
685-
return null;
686-
687675
ASTNode selectedNode= getCoveringNode();
688676
if (selectedNode == null)
689677
return null;

0 commit comments

Comments
 (0)