Skip to content

Commit f5e22a7

Browse files
committed
Remove dead code
Java 1.8 is mandated by ECJ thus removed code is non-reachable anymore.
1 parent 739fcd5 commit f5e22a7

28 files changed

+153
-293
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -114,7 +114,7 @@ private ImportReferencesCollector(IJavaProject project, CompilationUnit astRoot,
114114
fTypeImports= resultingTypeImports;
115115
fStaticImports= resultingStaticImports;
116116
fSubRange= rangeLimit;
117-
if (project == null || !JavaModelUtil.is50OrHigher(project)) {
117+
if (project == null) {
118118
fStaticImports= null; // do not collect
119119
}
120120
fASTRoot= astRoot; // can be null

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,9 @@ public boolean process(IProgressMonitor monitor) throws JavaModelException {
360360
TypeNameMatchCollector collector= new TypeNameMatchCollector(typesFound);
361361
new SearchEngine().searchAllTypeNames(null, allTypes, scope, collector, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
362362

363-
boolean is50OrHigher= JavaModelUtil.is50OrHigher(project);
364-
365363
for (TypeNameMatch curr : typesFound) {
366364
UnresolvedTypeData data= fUnresolvedTypes.get(curr.getSimpleTypeName());
367-
if (data != null && isVisible(curr) && isOfKind(curr, data.typeKinds, is50OrHigher)) {
365+
if (data != null && isVisible(curr) && isOfKind(curr, data.typeKinds)) {
368366
if (curr.getPackageName().length() > 0) {
369367
data.addInfo(curr);
370368
}
@@ -443,13 +441,13 @@ private TypeNameMatch[] processTypeInfo(List<TypeNameMatch> typeRefsFound) {
443441
}
444442
}
445443

446-
private boolean isOfKind(TypeNameMatch curr, int typeKinds, boolean is50OrHigher) {
444+
private boolean isOfKind(TypeNameMatch curr, int typeKinds) {
447445
int flags= curr.getModifiers();
448446
if (Flags.isAnnotation(flags)) {
449-
return is50OrHigher && (typeKinds & TypeKinds.ANNOTATIONS) != 0;
447+
return (typeKinds & TypeKinds.ANNOTATIONS) != 0;
450448
}
451449
if (Flags.isEnum(flags)) {
452-
return is50OrHigher && (typeKinds & TypeKinds.ENUMS) != 0;
450+
return (typeKinds & TypeKinds.ENUMS) != 0;
453451
}
454452
if (Flags.isInterface(flags)) {
455453
return (typeKinds & TypeKinds.INTERFACES) != 0;

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/UnnecessaryArrayCreationCleanUpCore.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 Red Hat Inc. and others.
2+
* Copyright (c) 2019, 2024 Red Hat Inc. and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -26,7 +26,6 @@
2626
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
2727
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore;
2828
import org.eclipse.jdt.internal.corext.fix.UnnecessaryArrayCreationFixCore;
29-
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
3029

3130
import org.eclipse.jdt.ui.cleanup.CleanUpRequirements;
3231
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
@@ -71,7 +70,7 @@ public String getPreview() {
7170

7271
@Override
7372
protected ICleanUpFix createFix(CompilationUnit unit) throws CoreException {
74-
if (!isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_ARRAY_CREATION) || !JavaModelUtil.is50OrHigher(unit.getJavaElement().getJavaProject())) {
73+
if (!isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_ARRAY_CREATION)) {
7574
return null;
7675
}
7776

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,8 @@ public boolean addImportNotFoundProposals(IInvocationContext context, IProblemLo
301301
if (importDeclaration.isStatic() && name.isQualifiedName()) {
302302
name= ((QualifiedName) name).getQualifier();
303303
}
304-
int kind= JavaModelUtil.is50OrHigher(cu.getJavaProject()) ? TypeKinds.REF_TYPES : TypeKinds.CLASSES | TypeKinds.INTERFACES;
305304
unresolvedElements.collectRequiresModuleProposals(cu, name, IProposalRelevance.IMPORT_NOT_FOUND_ADD_REQUIRES_MODULE, proposals, false);
306-
unresolvedElements.collectNewTypeProposals(cu, name, kind, IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals);
305+
unresolvedElements.collectNewTypeProposals(cu, name, TypeKinds.REF_TYPES, IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals);
307306
} else {
308307
Name name= importDeclaration.getName();
309308
unresolvedElements.collectRequiresModuleProposals(cu, name, IProposalRelevance.IMPORT_NOT_FOUND_ADD_REQUIRES_MODULE, proposals, true);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;
6060
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
6161
import org.eclipse.jdt.internal.corext.dom.Bindings;
62-
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
6362
import org.eclipse.jdt.internal.corext.util.Messages;
6463

6564
import org.eclipse.jdt.ui.text.java.IInvocationContext;
@@ -177,7 +176,7 @@ public void collectTypeMismatchProposals(IInvocationContext context, IProblemLoc
177176
ITypeBinding castFixType= null;
178177
if (currBinding == null || castTypeBinding.isCastCompatible(currBinding) || nodeToCast instanceof CastExpression) {
179178
castFixType= castTypeBinding;
180-
} else if (JavaModelUtil.is50OrHigher(cu.getJavaProject())) {
179+
} else {
181180
ITypeBinding boxUnboxedTypeBinding= boxOrUnboxPrimitives(castTypeBinding, currBinding, ast);
182181
if (boxUnboxedTypeBinding != castTypeBinding && boxUnboxedTypeBinding.isCastCompatible(currBinding)) {
183182
castFixType= boxUnboxedTypeBinding;

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

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,6 @@ public void collectVariableProposals(IInvocationContext context, IProblemLocatio
334334

335335
// add type proposals
336336
if (typeKind != 0) {
337-
if (!JavaModelUtil.is50OrHigher(cu.getJavaProject())) {
338-
typeKind &= ~(TypeKinds.ANNOTATIONS | TypeKinds.ENUMS | TypeKinds.VARIABLES);
339-
}
340-
341337
int relevance= Character.isUpperCase(ASTNodes.getSimpleNameIdentifier(node).charAt(0)) ? IProposalRelevance.VARIABLE_TYPE_PROPOSAL_1 : IProposalRelevance.VARIABLE_TYPE_PROPOSAL_2;
342338
addSimilarTypeProposals(typeKind, cu, node, relevance + 1, proposals);
343339

@@ -1514,46 +1510,44 @@ public void collectMethodProposals(IInvocationContext context, IProblemLocation
15141510
// 1300
15151511
private void addStaticImportFavoriteProposals(IInvocationContext context, SimpleName node, boolean isMethod, Collection<T> proposals) throws JavaModelException {
15161512
IJavaProject project= context.getCompilationUnit().getJavaProject();
1517-
if (JavaModelUtil.is50OrHigher(project)) {
1518-
String pref= JavaManipulation.getPreference(JavaManipulationPlugin.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
1519-
if (pref == null || pref.isBlank()) {
1520-
return;
1521-
}
1522-
String[] favourites= pref.split(";"); //$NON-NLS-1$
1523-
if (favourites.length == 0) {
1524-
return;
1525-
}
1513+
String pref= JavaManipulation.getPreference(JavaManipulationPlugin.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
1514+
if (pref == null || pref.isBlank()) {
1515+
return;
1516+
}
1517+
String[] favourites= pref.split(";"); //$NON-NLS-1$
1518+
if (favourites.length == 0) {
1519+
return;
1520+
}
15261521

1527-
CompilationUnit root= context.getASTRoot();
1528-
AST ast= root.getAST();
1522+
CompilationUnit root= context.getASTRoot();
1523+
AST ast= root.getAST();
15291524

1530-
String name= node.getIdentifier();
1531-
for (String curr : JavaModelUtil.getStaticImportFavorites(context.getCompilationUnit(), name, isMethod, favourites)) {
1532-
ImportRewrite importRewrite= StubUtility.createImportRewrite(root, true);
1533-
ASTRewrite astRewrite= ASTRewrite.create(ast);
1525+
String name= node.getIdentifier();
1526+
for (String curr : JavaModelUtil.getStaticImportFavorites(context.getCompilationUnit(), name, isMethod, favourites)) {
1527+
ImportRewrite importRewrite= StubUtility.createImportRewrite(root, true);
1528+
ASTRewrite astRewrite= ASTRewrite.create(ast);
15341529

1535-
String label;
1536-
String qualifiedTypeName= Signature.getQualifier(Signature.getTypeErasure(curr));
1537-
String elementLabel= BasicElementLabels.getJavaElementName(JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));
1538-
1539-
String res= importRewrite.addStaticImport(qualifiedTypeName, name, isMethod, new ContextSensitiveImportRewriteContext(root, node.getStartPosition(), importRewrite));
1540-
int dot= res.lastIndexOf('.');
1541-
if (dot != -1) {
1542-
String usedTypeName= importRewrite.addImport(qualifiedTypeName);
1543-
Name newName= ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
1544-
astRewrite.replace(node, newName, null);
1545-
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_change_to_static_import_description, elementLabel);
1546-
} else {
1547-
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description, elementLabel);
1548-
}
1549-
1550-
//Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
1551-
ASTRewriteCorrectionProposalCore proposal= new ASTRewriteCorrectionProposalCore(label, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_STATIC_IMPORT);
1552-
proposal.setImportRewrite(importRewrite);
1553-
T t= rewriteProposalToT(proposal, StaticImportFavoriteProposal1);
1554-
if (t != null)
1555-
proposals.add(t);
1530+
String label;
1531+
String qualifiedTypeName= Signature.getQualifier(Signature.getTypeErasure(curr));
1532+
String elementLabel= BasicElementLabels.getJavaElementName(JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));
1533+
1534+
String res= importRewrite.addStaticImport(qualifiedTypeName, name, isMethod, new ContextSensitiveImportRewriteContext(root, node.getStartPosition(), importRewrite));
1535+
int dot= res.lastIndexOf('.');
1536+
if (dot != -1) {
1537+
String usedTypeName= importRewrite.addImport(qualifiedTypeName);
1538+
Name newName= ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
1539+
astRewrite.replace(node, newName, null);
1540+
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_change_to_static_import_description, elementLabel);
1541+
} else {
1542+
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description, elementLabel);
15561543
}
1544+
1545+
//Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
1546+
ASTRewriteCorrectionProposalCore proposal= new ASTRewriteCorrectionProposalCore(label, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_STATIC_IMPORT);
1547+
proposal.setImportRewrite(importRewrite);
1548+
T t= rewriteProposalToT(proposal, StaticImportFavoriteProposal1);
1549+
if (t != null)
1550+
proposals.add(t);
15571551
}
15581552
}
15591553

@@ -2036,7 +2030,7 @@ private void doEqualNumberOfParameters(IInvocationContext context, ASTNode invoc
20362030
ITypeBinding castFixType= null;
20372031
if (binding == null || castType.isCastCompatible(binding)) {
20382032
castFixType= castType;
2039-
} else if (JavaModelUtil.is50OrHigher(cu.getJavaProject())) {
2033+
} else {
20402034
ITypeBinding boxUnboxedTypeBinding= TypeMismatchBaseSubProcessor.boxOrUnboxPrimitives(castType, binding, nodeToCast.getAST());
20412035
if (boxUnboxedTypeBinding != castType && boxUnboxedTypeBinding.isCastCompatible(binding)) {
20422036
castFixType= boxUnboxedTypeBinding;

org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -598,28 +598,13 @@ private Statement[] createAddSimpleHashCode(ITypeBinding type, IHashCodeAccessPr
598598

599599
private Statement createAddArrayHashCode(IVariableBinding binding) {
600600
MethodInvocation invoc= fAst.newMethodInvocation();
601-
if (JavaModelUtil.is50OrHigher(fRewrite.getCu().getJavaProject())) {
602-
if (needsDeepMethod(binding.getType())) {
603-
invoc.setName(fAst.newSimpleName(METHODNAME_DEEP_HASH_CODE));
604-
} else {
605-
invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
606-
}
607-
invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
608-
invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
601+
if (needsDeepMethod(binding.getType())) {
602+
invoc.setName(fAst.newSimpleName(METHODNAME_DEEP_HASH_CODE));
609603
} else {
610604
invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
611-
final IJavaElement element= fType.getJavaElement();
612-
if (element != null && !"".equals(element.getElementName())) //$NON-NLS-1$
613-
invoc.setExpression(fAst.newSimpleName(element.getElementName()));
614-
invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
615-
ITypeBinding type= binding.getType().getElementType();
616-
if (!Bindings.isVoidType(type)) {
617-
if (!type.isPrimitive() || binding.getType().getDimensions() >= 2)
618-
type= fAst.resolveWellKnownType(JAVA_LANG_OBJECT);
619-
if (!fCustomHashCodeTypes.contains(type))
620-
fCustomHashCodeTypes.add(type);
621-
}
622605
}
606+
invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
607+
invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
623608
return prepareAssignment(invoc);
624609
}
625610

@@ -923,8 +908,7 @@ private MethodDeclaration createEqualsMethod() throws CoreException {
923908
if (type.isPrimitive() || type.isEnum())
924909
body.statements().add(createSimpleComparison(field));
925910
else if (type.isArray()) {
926-
IJavaProject project= fUnit.getJavaElement().getJavaProject();
927-
if (needsDeepMethod(type) && JavaModelUtil.is50OrHigher(project)) {
911+
if (needsDeepMethod(type)) {
928912
body.statements().add(createMultiArrayComparison(field.getName()));
929913
} else {
930914
body.statements().add(createArrayComparison(field.getName()));

org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018, 2023 IBM Corporation and others.
2+
* Copyright (c) 2018, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -125,12 +125,7 @@ public static MethodDeclaration createImplementationStub(ICompilationUnit unit,
125125
ITypeBinding bindingReturnType= binding.getReturnType();
126126
bindingReturnType = StubUtility2Core.replaceWildcardsAndCaptures(bindingReturnType);
127127

128-
if (JavaModelUtil.is50OrHigher(javaProject)) {
129-
StubUtility2Core.createTypeParameters(imports, context, ast, binding, decl);
130-
131-
} else {
132-
bindingReturnType= bindingReturnType.getErasure();
133-
}
128+
StubUtility2Core.createTypeParameters(imports, context, ast, binding, decl);
134129

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

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

470-
if (JavaModelUtil.is50OrHigher(javaProject)) {
471-
StubUtility2Core.createTypeParameters(imports, context, ast, binding, decl);
472-
473-
} else {
474-
bindingReturnType= bindingReturnType.getErasure();
475-
}
465+
StubUtility2Core.createTypeParameters(imports, context, ast, binding, decl);
476466

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

@@ -597,7 +587,6 @@ public static List<SingleVariableDeclaration> createParameters(IJavaProject proj
597587
}
598588
public static List<SingleVariableDeclaration> createParameters(IJavaProject project, ImportRewrite imports, ImportRewriteContext context, AST ast,
599589
IMethodBinding binding, String[] paramNames, MethodDeclaration decl, EnumSet<TypeLocation> nullnessDefault) {
600-
boolean is50OrHigher= JavaModelUtil.is50OrHigher(project);
601590
List<SingleVariableDeclaration> parameters= decl.parameters();
602591
ITypeBinding[] params= binding.getParameterTypes();
603592
if (paramNames == null || paramNames.length < params.length) {
@@ -607,10 +596,7 @@ public static List<SingleVariableDeclaration> createParameters(IJavaProject proj
607596
SingleVariableDeclaration var= ast.newSingleVariableDeclaration();
608597
ITypeBinding type= params[i];
609598
type=replaceWildcardsAndCaptures(type);
610-
if (!is50OrHigher) {
611-
type= type.getErasure();
612-
var.setType(imports.addImport(type, ast, context, TypeLocation.PARAMETER));
613-
} else if (binding.isVarargs() && type.isArray() && i == params.length - 1) {
599+
if (binding.isVarargs() && type.isArray() && i == params.length - 1) {
614600
var.setVarargs(true);
615601
/*
616602
* Varargs annotations are special.
@@ -1108,9 +1094,6 @@ public static ASTNode getNodeToInsertBefore(ListRewrite listRewrite, IJavaElemen
11081094
*/
11091095
public static void addOverrideAnnotation(CodeGenerationSettings settings, IJavaProject project, ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration methodDecl,
11101096
boolean isDeclaringTypeInterface, TextEditGroup group) {
1111-
if (!JavaModelUtil.is50OrHigher(project)) {
1112-
return;
1113-
}
11141097
if (isDeclaringTypeInterface) {
11151098
String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
11161099
if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))

org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/ConvertForLoopOperation.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import org.eclipse.jdt.internal.corext.dom.JdtASTMatcher;
6767
import org.eclipse.jdt.internal.corext.dom.ModifierRewrite;
6868
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
69-
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
7069

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

113-
if (!JavaModelUtil.is50OrHigher(javaElement.getJavaProject()))
114-
return ERROR_STATUS;
115-
116112
if (!validateInitializers(statement))
117113
return ERROR_STATUS;
118114

0 commit comments

Comments
 (0)