Skip to content

Commit

Permalink
Remove pre Java 1.5 checks form o.e.jdt.ui/core extensions and friends
Browse files Browse the repository at this point in the history
ECJ mandates Java 8 level thus this code is always noop.
  • Loading branch information
akurtakov committed Dec 26, 2024
1 parent 6669c21 commit 05d9788
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> proposals) throws CoreException {
ICompilationUnit cu= context.getCompilationUnit();

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeNameMatch> typeInfos= new ArrayList<>();
Expand All @@ -640,7 +638,7 @@ private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope sea
ArrayList<TypeNameMatch> 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);
}
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<TypeNameMatch> typeInfos= new ArrayList<>();
Expand All @@ -463,21 +461,21 @@ 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);
}
}
}
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<CompilationUnitRewriteOperationWithSourceRange> operations= new ArrayList<>();
if (locations == null) {
org.eclipse.jdt.core.compiler.IProblem[] problems= compilationUnit.getProblems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -543,9 +537,6 @@ public SignatureAnnotationRewriteOperation createAddAnnotationOperation(Set<Stri
}

private SignatureAnnotationRewriteOperation createAddAnnotationOperation(boolean changeTargetMethod, boolean thisUnitOnly) {
if (!is50OrHigher())
return null;

ASTNode selectedNode= getCoveringNode();
if (selectedNode == null)
return null;
Expand Down Expand Up @@ -681,9 +672,6 @@ private SignatureAnnotationRewriteOperation createAddAnnotationOperation(boolean
}

private SignatureAnnotationRewriteOperation createAddAnnotationToOverriddenOperation() {
if (!is50OrHigher())
return null;

ASTNode selectedNode= getCoveringNode();
if (selectedNode == null)
return null;
Expand Down

0 comments on commit 05d9788

Please sign in to comment.