Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
Java 1.8 is mandated by ECJ thus removed code is non-reachable anymore.
  • Loading branch information
akurtakov committed Dec 29, 2024
1 parent 739fcd5 commit f5e22a7
Show file tree
Hide file tree
Showing 28 changed files with 153 additions and 293 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation 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 @@ -114,7 +114,7 @@ private ImportReferencesCollector(IJavaProject project, CompilationUnit astRoot,
fTypeImports= resultingTypeImports;
fStaticImports= resultingStaticImports;
fSubRange= rangeLimit;
if (project == null || !JavaModelUtil.is50OrHigher(project)) {
if (project == null) {
fStaticImports= null; // do not collect
}
fASTRoot= astRoot; // can be null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,9 @@ public boolean process(IProgressMonitor monitor) throws JavaModelException {
TypeNameMatchCollector collector= new TypeNameMatchCollector(typesFound);
new SearchEngine().searchAllTypeNames(null, allTypes, scope, collector, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);

boolean is50OrHigher= JavaModelUtil.is50OrHigher(project);

for (TypeNameMatch curr : typesFound) {
UnresolvedTypeData data= fUnresolvedTypes.get(curr.getSimpleTypeName());
if (data != null && isVisible(curr) && isOfKind(curr, data.typeKinds, is50OrHigher)) {
if (data != null && isVisible(curr) && isOfKind(curr, data.typeKinds)) {
if (curr.getPackageName().length() > 0) {
data.addInfo(curr);
}
Expand Down Expand Up @@ -443,13 +441,13 @@ private TypeNameMatch[] processTypeInfo(List<TypeNameMatch> typeRefsFound) {
}
}

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) 2019 Red Hat Inc. and others.
* Copyright (c) 2019, 2024 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -26,7 +26,6 @@
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore;
import org.eclipse.jdt.internal.corext.fix.UnnecessaryArrayCreationFixCore;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;

import org.eclipse.jdt.ui.cleanup.CleanUpRequirements;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
Expand Down Expand Up @@ -71,7 +70,7 @@ public String getPreview() {

@Override
protected ICleanUpFix createFix(CompilationUnit unit) throws CoreException {
if (!isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_ARRAY_CREATION) || !JavaModelUtil.is50OrHigher(unit.getJavaElement().getJavaProject())) {
if (!isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_ARRAY_CREATION)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,8 @@ public boolean addImportNotFoundProposals(IInvocationContext context, IProblemLo
if (importDeclaration.isStatic() && name.isQualifiedName()) {
name= ((QualifiedName) name).getQualifier();
}
int kind= JavaModelUtil.is50OrHigher(cu.getJavaProject()) ? TypeKinds.REF_TYPES : TypeKinds.CLASSES | TypeKinds.INTERFACES;
unresolvedElements.collectRequiresModuleProposals(cu, name, IProposalRelevance.IMPORT_NOT_FOUND_ADD_REQUIRES_MODULE, proposals, false);
unresolvedElements.collectNewTypeProposals(cu, name, kind, IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals);
unresolvedElements.collectNewTypeProposals(cu, name, TypeKinds.REF_TYPES, IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals);
} else {
Name name= importDeclaration.getName();
unresolvedElements.collectRequiresModuleProposals(cu, name, IProposalRelevance.IMPORT_NOT_FOUND_ADD_REQUIRES_MODULE, proposals, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.corext.util.Messages;

import org.eclipse.jdt.ui.text.java.IInvocationContext;
Expand Down Expand Up @@ -177,7 +176,7 @@ public void collectTypeMismatchProposals(IInvocationContext context, IProblemLoc
ITypeBinding castFixType= null;
if (currBinding == null || castTypeBinding.isCastCompatible(currBinding) || nodeToCast instanceof CastExpression) {
castFixType= castTypeBinding;
} else if (JavaModelUtil.is50OrHigher(cu.getJavaProject())) {
} else {
ITypeBinding boxUnboxedTypeBinding= boxOrUnboxPrimitives(castTypeBinding, currBinding, ast);
if (boxUnboxedTypeBinding != castTypeBinding && boxUnboxedTypeBinding.isCastCompatible(currBinding)) {
castFixType= boxUnboxedTypeBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,6 @@ public void collectVariableProposals(IInvocationContext context, IProblemLocatio

// add type proposals
if (typeKind != 0) {
if (!JavaModelUtil.is50OrHigher(cu.getJavaProject())) {
typeKind &= ~(TypeKinds.ANNOTATIONS | TypeKinds.ENUMS | TypeKinds.VARIABLES);
}

int relevance= Character.isUpperCase(ASTNodes.getSimpleNameIdentifier(node).charAt(0)) ? IProposalRelevance.VARIABLE_TYPE_PROPOSAL_1 : IProposalRelevance.VARIABLE_TYPE_PROPOSAL_2;
addSimilarTypeProposals(typeKind, cu, node, relevance + 1, proposals);

Expand Down Expand Up @@ -1514,46 +1510,44 @@ public void collectMethodProposals(IInvocationContext context, IProblemLocation
// 1300
private void addStaticImportFavoriteProposals(IInvocationContext context, SimpleName node, boolean isMethod, Collection<T> proposals) throws JavaModelException {
IJavaProject project= context.getCompilationUnit().getJavaProject();
if (JavaModelUtil.is50OrHigher(project)) {
String pref= JavaManipulation.getPreference(JavaManipulationPlugin.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
if (pref == null || pref.isBlank()) {
return;
}
String[] favourites= pref.split(";"); //$NON-NLS-1$
if (favourites.length == 0) {
return;
}
String pref= JavaManipulation.getPreference(JavaManipulationPlugin.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
if (pref == null || pref.isBlank()) {
return;
}
String[] favourites= pref.split(";"); //$NON-NLS-1$
if (favourites.length == 0) {
return;
}

CompilationUnit root= context.getASTRoot();
AST ast= root.getAST();
CompilationUnit root= context.getASTRoot();
AST ast= root.getAST();

String name= node.getIdentifier();
for (String curr : JavaModelUtil.getStaticImportFavorites(context.getCompilationUnit(), name, isMethod, favourites)) {
ImportRewrite importRewrite= StubUtility.createImportRewrite(root, true);
ASTRewrite astRewrite= ASTRewrite.create(ast);
String name= node.getIdentifier();
for (String curr : JavaModelUtil.getStaticImportFavorites(context.getCompilationUnit(), name, isMethod, favourites)) {
ImportRewrite importRewrite= StubUtility.createImportRewrite(root, true);
ASTRewrite astRewrite= ASTRewrite.create(ast);

String label;
String qualifiedTypeName= Signature.getQualifier(Signature.getTypeErasure(curr));
String elementLabel= BasicElementLabels.getJavaElementName(JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));

String res= importRewrite.addStaticImport(qualifiedTypeName, name, isMethod, new ContextSensitiveImportRewriteContext(root, node.getStartPosition(), importRewrite));
int dot= res.lastIndexOf('.');
if (dot != -1) {
String usedTypeName= importRewrite.addImport(qualifiedTypeName);
Name newName= ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
astRewrite.replace(node, newName, null);
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_change_to_static_import_description, elementLabel);
} else {
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description, elementLabel);
}

//Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
ASTRewriteCorrectionProposalCore proposal= new ASTRewriteCorrectionProposalCore(label, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_STATIC_IMPORT);
proposal.setImportRewrite(importRewrite);
T t= rewriteProposalToT(proposal, StaticImportFavoriteProposal1);
if (t != null)
proposals.add(t);
String label;
String qualifiedTypeName= Signature.getQualifier(Signature.getTypeErasure(curr));
String elementLabel= BasicElementLabels.getJavaElementName(JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));

String res= importRewrite.addStaticImport(qualifiedTypeName, name, isMethod, new ContextSensitiveImportRewriteContext(root, node.getStartPosition(), importRewrite));
int dot= res.lastIndexOf('.');
if (dot != -1) {
String usedTypeName= importRewrite.addImport(qualifiedTypeName);
Name newName= ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
astRewrite.replace(node, newName, null);
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_change_to_static_import_description, elementLabel);
} else {
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description, elementLabel);
}

//Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
ASTRewriteCorrectionProposalCore proposal= new ASTRewriteCorrectionProposalCore(label, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_STATIC_IMPORT);
proposal.setImportRewrite(importRewrite);
T t= rewriteProposalToT(proposal, StaticImportFavoriteProposal1);
if (t != null)
proposals.add(t);
}
}

Expand Down Expand Up @@ -2036,7 +2030,7 @@ private void doEqualNumberOfParameters(IInvocationContext context, ASTNode invoc
ITypeBinding castFixType= null;
if (binding == null || castType.isCastCompatible(binding)) {
castFixType= castType;
} else if (JavaModelUtil.is50OrHigher(cu.getJavaProject())) {
} else {
ITypeBinding boxUnboxedTypeBinding= TypeMismatchBaseSubProcessor.boxOrUnboxPrimitives(castType, binding, nodeToCast.getAST());
if (boxUnboxedTypeBinding != castType && boxUnboxedTypeBinding.isCastCompatible(binding)) {
castFixType= boxUnboxedTypeBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,28 +598,13 @@ private Statement[] createAddSimpleHashCode(ITypeBinding type, IHashCodeAccessPr

private Statement createAddArrayHashCode(IVariableBinding binding) {
MethodInvocation invoc= fAst.newMethodInvocation();
if (JavaModelUtil.is50OrHigher(fRewrite.getCu().getJavaProject())) {
if (needsDeepMethod(binding.getType())) {
invoc.setName(fAst.newSimpleName(METHODNAME_DEEP_HASH_CODE));
} else {
invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
}
invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
if (needsDeepMethod(binding.getType())) {
invoc.setName(fAst.newSimpleName(METHODNAME_DEEP_HASH_CODE));
} else {
invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
final IJavaElement element= fType.getJavaElement();
if (element != null && !"".equals(element.getElementName())) //$NON-NLS-1$
invoc.setExpression(fAst.newSimpleName(element.getElementName()));
invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
ITypeBinding type= binding.getType().getElementType();
if (!Bindings.isVoidType(type)) {
if (!type.isPrimitive() || binding.getType().getDimensions() >= 2)
type= fAst.resolveWellKnownType(JAVA_LANG_OBJECT);
if (!fCustomHashCodeTypes.contains(type))
fCustomHashCodeTypes.add(type);
}
}
invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
return prepareAssignment(invoc);
}

Expand Down Expand Up @@ -923,8 +908,7 @@ private MethodDeclaration createEqualsMethod() throws CoreException {
if (type.isPrimitive() || type.isEnum())
body.statements().add(createSimpleComparison(field));
else if (type.isArray()) {
IJavaProject project= fUnit.getJavaElement().getJavaProject();
if (needsDeepMethod(type) && JavaModelUtil.is50OrHigher(project)) {
if (needsDeepMethod(type)) {
body.statements().add(createMultiArrayComparison(field.getName()));
} else {
body.statements().add(createArrayComparison(field.getName()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2023 IBM Corporation and others.
* Copyright (c) 2018, 2024 IBM Corporation 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 @@ -125,12 +125,7 @@ public static MethodDeclaration createImplementationStub(ICompilationUnit unit,
ITypeBinding bindingReturnType= binding.getReturnType();
bindingReturnType = StubUtility2Core.replaceWildcardsAndCaptures(bindingReturnType);

if (JavaModelUtil.is50OrHigher(javaProject)) {
StubUtility2Core.createTypeParameters(imports, context, ast, binding, decl);

} else {
bindingReturnType= bindingReturnType.getErasure();
}
StubUtility2Core.createTypeParameters(imports, context, ast, binding, decl);

decl.setReturnType2(imports.addImport(bindingReturnType, ast, context, TypeLocation.RETURN_TYPE));

Expand Down Expand Up @@ -467,12 +462,7 @@ public static MethodDeclaration createImplementationStubCore(ICompilationUnit un
ITypeBinding bindingReturnType= binding.getReturnType();
bindingReturnType= StubUtility2Core.replaceWildcardsAndCaptures(bindingReturnType);

if (JavaModelUtil.is50OrHigher(javaProject)) {
StubUtility2Core.createTypeParameters(imports, context, ast, binding, decl);

} else {
bindingReturnType= bindingReturnType.getErasure();
}
StubUtility2Core.createTypeParameters(imports, context, ast, binding, decl);

decl.setReturnType2(imports.addImport(bindingReturnType, ast, context, TypeLocation.RETURN_TYPE));

Expand Down Expand Up @@ -597,7 +587,6 @@ public static List<SingleVariableDeclaration> createParameters(IJavaProject proj
}
public static List<SingleVariableDeclaration> createParameters(IJavaProject project, ImportRewrite imports, ImportRewriteContext context, AST ast,
IMethodBinding binding, String[] paramNames, MethodDeclaration decl, EnumSet<TypeLocation> nullnessDefault) {
boolean is50OrHigher= JavaModelUtil.is50OrHigher(project);
List<SingleVariableDeclaration> parameters= decl.parameters();
ITypeBinding[] params= binding.getParameterTypes();
if (paramNames == null || paramNames.length < params.length) {
Expand All @@ -607,10 +596,7 @@ public static List<SingleVariableDeclaration> createParameters(IJavaProject proj
SingleVariableDeclaration var= ast.newSingleVariableDeclaration();
ITypeBinding type= params[i];
type=replaceWildcardsAndCaptures(type);
if (!is50OrHigher) {
type= type.getErasure();
var.setType(imports.addImport(type, ast, context, TypeLocation.PARAMETER));
} else if (binding.isVarargs() && type.isArray() && i == params.length - 1) {
if (binding.isVarargs() && type.isArray() && i == params.length - 1) {
var.setVarargs(true);
/*
* Varargs annotations are special.
Expand Down Expand Up @@ -1108,9 +1094,6 @@ public static ASTNode getNodeToInsertBefore(ListRewrite listRewrite, IJavaElemen
*/
public static void addOverrideAnnotation(CodeGenerationSettings settings, IJavaProject project, ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration methodDecl,
boolean isDeclaringTypeInterface, TextEditGroup group) {
if (!JavaModelUtil.is50OrHigher(project)) {
return;
}
if (isDeclaringTypeInterface) {
String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.eclipse.jdt.internal.corext.dom.JdtASTMatcher;
import org.eclipse.jdt.internal.corext.dom.ModifierRewrite;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;

public class ConvertForLoopOperation extends ConvertLoopOperation {
private static final String LENGTH_QUERY= "length"; //$NON-NLS-1$
Expand Down Expand Up @@ -110,9 +109,6 @@ public IStatus satisfiesPreconditions() {
if (javaElement == null)
return ERROR_STATUS;

if (!JavaModelUtil.is50OrHigher(javaElement.getJavaProject()))
return ERROR_STATUS;

if (!validateInitializers(statement))
return ERROR_STATUS;

Expand Down
Loading

0 comments on commit f5e22a7

Please sign in to comment.