Skip to content

Commit 9c3b475

Browse files
committed
Remove Java 7 checks
ECJ support 1.8 as lowest version and JDT UI converts projects to that as a min level thus this code is non reachable.
1 parent b9233aa commit 9c3b475

File tree

15 files changed

+157
-273
lines changed

15 files changed

+157
-273
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2020, 2024 Fabrice TIERCELIN and others.
2+
* Copyright (c) 2020, 2025 Fabrice TIERCELIN and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -57,7 +57,6 @@
5757
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
5858
import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore;
5959
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
60-
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
6160

6261
import org.eclipse.jdt.ui.cleanup.CleanUpRequirements;
6362
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
@@ -122,7 +121,7 @@ public String getPreview() {
122121

123122
@Override
124123
protected ICleanUpFix createFix(final CompilationUnit unit) throws CoreException {
125-
if (!isEnabled(CleanUpConstants.MULTI_CATCH) || !JavaModelUtil.is1d7OrHigher(unit.getJavaElement().getJavaProject())) {
124+
if (!isEnabled(CleanUpConstants.MULTI_CATCH)) {
126125
return null;
127126
}
128127

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

Lines changed: 100 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 IBM Corporation and others.
2+
* Copyright (c) 2024, 2025 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
@@ -282,23 +282,21 @@ public void getUncaughtExceptionProposals(IInvocationContext context, IProblemLo
282282
proposals.add(refactoringCorrectionProposalToT(proposal, SURROUND_WITH_TRY_CATCH));
283283
}
284284

285-
if (JavaModelUtil.is1d7OrHigher(cu.getJavaProject())) {
286-
refactoring= SurroundWithTryCatchRefactoring.create(cu, offset, length, true);
287-
if (refactoring == null)
288-
return;
285+
refactoring= SurroundWithTryCatchRefactoring.create(cu, offset, length, true);
286+
if (refactoring == null)
287+
return;
289288

290-
refactoring.setLeaveDirty(true);
291-
if (refactoring.checkActivationBasics(astRoot).isOK()) {
292-
String label;
293-
if ((vType != null) && (vName != null) && ASTNodes.isVarType(selectedNode, astRoot) && affectedLocals.contains(vName.getIdentifier())) {
294-
label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_surroundwith_trymulticatch_var_description, new Object[] { vName.getIdentifier(), vType.getName() });
295-
} else {
296-
label= CorrectionMessages.LocalCorrectionsSubProcessor_surroundwith_trymulticatch_description;
297-
}
298-
RefactoringCorrectionProposalCore proposal= new RefactoringCorrectionProposalCore(label, cu, refactoring, IProposalRelevance.SURROUND_WITH_TRY_MULTICATCH);
299-
proposal.setLinkedProposalModel(refactoring.getLinkedProposalModel());
300-
proposals.add(refactoringCorrectionProposalToT(proposal, SURROUND_WITH_TRY_MULTI_CATCH));
289+
refactoring.setLeaveDirty(true);
290+
if (refactoring.checkActivationBasics(astRoot).isOK()) {
291+
String label;
292+
if ((vType != null) && (vName != null) && ASTNodes.isVarType(selectedNode, astRoot) && affectedLocals.contains(vName.getIdentifier())) {
293+
label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_surroundwith_trymulticatch_var_description, new Object[] { vName.getIdentifier(), vType.getName() });
294+
} else {
295+
label= CorrectionMessages.LocalCorrectionsSubProcessor_surroundwith_trymulticatch_description;
301296
}
297+
RefactoringCorrectionProposalCore proposal= new RefactoringCorrectionProposalCore(label, cu, refactoring, IProposalRelevance.SURROUND_WITH_TRY_MULTICATCH);
298+
proposal.setLinkedProposalModel(refactoring.getLinkedProposalModel());
299+
proposals.add(refactoringCorrectionProposalToT(proposal, SURROUND_WITH_TRY_MULTI_CATCH));
302300
}
303301

304302
//Catch exception
@@ -322,113 +320,111 @@ public void getUncaughtExceptionProposals(IInvocationContext context, IProblemLo
322320
if (surroundingTry != null && (ASTNodes.isParent(selectedNode, surroundingTry.getBody()) || selectedNode.getLocationInParent() == TryStatement.RESOURCES2_PROPERTY)) {
323321
addAdditionalCatchProposal(context, proposals, cu, selectedNode, offset, length, decl, uncaughtExceptions, surroundingTry, ast);
324322

325-
if (JavaModelUtil.is1d7OrHigher(cu.getJavaProject())) {
326-
List<CatchClause> catchClauses= surroundingTry.catchClauses();
327-
List<ITypeBinding> filteredExceptions= SurroundWithTryCatchRefactoring.filterSubtypeExceptions(uncaughtExceptions);
328-
ASTRewrite rewrite= ASTRewrite.create(ast);
329-
330-
if (catchClauses != null && catchClauses.size() == 1) {
331-
String label= filteredExceptions.size() > 1
332-
? CorrectionMessages.LocalCorrectionsSubProcessor_addexceptionstoexistingcatch_description
333-
: CorrectionMessages.LocalCorrectionsSubProcessor_addexceptiontoexistingcatch_description;
334-
LinkedCorrectionProposalCore proposal= new LinkedCorrectionProposalCore(label, cu, rewrite, IProposalRelevance.ADD_EXCEPTIONS_TO_EXISTING_CATCH);
335-
ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
336-
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
337-
338-
CatchClause catchClause= catchClauses.get(0);
339-
Type originalType= catchClause.getException().getType();
340-
341-
if (originalType instanceof UnionType) {
342-
UnionType unionType= (UnionType) originalType;
343-
ListRewrite listRewrite= rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY);
344-
@SuppressWarnings("unchecked")
345-
List<Type> existingTypes= new ArrayList<>(unionType.types());
346-
347-
for (int i= 0; i < filteredExceptions.size(); i++) {
348-
Type addedType= addNewException(ast, filteredExceptions, rewrite, proposal, imports, importRewriteContext, i);
349-
boolean isReplaced= false;
350-
351-
for (Type existingType : existingTypes) {
352-
if (existingType.resolveBinding().isSubTypeCompatible(filteredExceptions.get(i))) {
353-
listRewrite.replace(existingType, addedType, null);
354-
isReplaced= true;
355-
break;
356-
}
357-
}
323+
List<CatchClause> catchClauses= surroundingTry.catchClauses();
324+
List<ITypeBinding> filteredExceptions= SurroundWithTryCatchRefactoring.filterSubtypeExceptions(uncaughtExceptions);
325+
ASTRewrite rewrite= ASTRewrite.create(ast);
358326

359-
if (!isReplaced) {
360-
listRewrite.insertLast(addedType, null);
361-
}
362-
}
363-
} else {
364-
Type firstType= null;
365-
List<Type> typesToAdd= new ArrayList<>();
327+
if (catchClauses != null && catchClauses.size() == 1) {
328+
String label= filteredExceptions.size() > 1
329+
? CorrectionMessages.LocalCorrectionsSubProcessor_addexceptionstoexistingcatch_description
330+
: CorrectionMessages.LocalCorrectionsSubProcessor_addexceptiontoexistingcatch_description;
331+
LinkedCorrectionProposalCore proposal= new LinkedCorrectionProposalCore(label, cu, rewrite, IProposalRelevance.ADD_EXCEPTIONS_TO_EXISTING_CATCH);
332+
ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
333+
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
366334

367-
for (int i= 0; i < filteredExceptions.size(); i++) {
368-
Type addedType= addNewException(ast, filteredExceptions, rewrite, proposal, imports, importRewriteContext, i);
335+
CatchClause catchClause= catchClauses.get(0);
336+
Type originalType= catchClause.getException().getType();
369337

370-
if (originalType.resolveBinding().isSubTypeCompatible(filteredExceptions.get(i))) {
371-
firstType= addedType;
372-
} else {
373-
typesToAdd.add(addedType);
338+
if (originalType instanceof UnionType) {
339+
UnionType unionType= (UnionType) originalType;
340+
ListRewrite listRewrite= rewrite.getListRewrite(unionType, UnionType.TYPES_PROPERTY);
341+
@SuppressWarnings("unchecked")
342+
List<Type> existingTypes= new ArrayList<>(unionType.types());
343+
344+
for (int i= 0; i < filteredExceptions.size(); i++) {
345+
Type addedType= addNewException(ast, filteredExceptions, rewrite, proposal, imports, importRewriteContext, i);
346+
boolean isReplaced= false;
347+
348+
for (Type existingType : existingTypes) {
349+
if (existingType.resolveBinding().isSubTypeCompatible(filteredExceptions.get(i))) {
350+
listRewrite.replace(existingType, addedType, null);
351+
isReplaced= true;
352+
break;
374353
}
375354
}
376355

377-
if (!typesToAdd.isEmpty()) {
378-
UnionType newUnionType= ast.newUnionType();
379-
List<Type> types= newUnionType.types();
356+
if (!isReplaced) {
357+
listRewrite.insertLast(addedType, null);
358+
}
359+
}
360+
} else {
361+
Type firstType= null;
362+
List<Type> typesToAdd= new ArrayList<>();
380363

381-
if (firstType == null) {
382-
types.add(ASTNodes.createMoveTarget(rewrite, originalType));
383-
} else {
384-
types.add(firstType);
385-
}
386-
types.addAll(typesToAdd);
364+
for (int i= 0; i < filteredExceptions.size(); i++) {
365+
Type addedType= addNewException(ast, filteredExceptions, rewrite, proposal, imports, importRewriteContext, i);
387366

388-
rewrite.replace(originalType, newUnionType, null);
389-
} else if (firstType != null) {
390-
rewrite.replace(originalType, firstType, null);
367+
if (originalType.resolveBinding().isSubTypeCompatible(filteredExceptions.get(i))) {
368+
firstType= addedType;
369+
} else {
370+
typesToAdd.add(addedType);
391371
}
392372
}
393373

394-
proposals.add(linkedCorrectionProposalToT(proposal, ADD_EXCEPTION_TO_CATCH));
395-
} else if (catchClauses != null && catchClauses.isEmpty() && filteredExceptions.size() > 1) {
396-
String label= CorrectionMessages.LocalCorrectionsSubProcessor_addadditionalmulticatch_description;
397-
LinkedCorrectionProposalCore proposal= new LinkedCorrectionProposalCore(label, cu, rewrite, IProposalRelevance.ADD_EXCEPTIONS_TO_EXISTING_CATCH);
398-
ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
399-
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
374+
if (!typesToAdd.isEmpty()) {
375+
UnionType newUnionType= ast.newUnionType();
376+
List<Type> types= newUnionType.types();
377+
378+
if (firstType == null) {
379+
types.add(ASTNodes.createMoveTarget(rewrite, originalType));
380+
} else {
381+
types.add(firstType);
382+
}
383+
types.addAll(typesToAdd);
384+
385+
rewrite.replace(originalType, newUnionType, null);
386+
} else if (firstType != null) {
387+
rewrite.replace(originalType, firstType, null);
388+
}
389+
}
400390

401-
CodeScopeBuilder.Scope scope= CodeScopeBuilder.perform(decl, Selection.createFromStartLength(offset, length)).findScope(offset, length);
402-
scope.setCursor(offset);
391+
proposals.add(linkedCorrectionProposalToT(proposal, ADD_EXCEPTION_TO_CATCH));
392+
} else if (catchClauses != null && catchClauses.isEmpty() && filteredExceptions.size() > 1) {
393+
String label= CorrectionMessages.LocalCorrectionsSubProcessor_addadditionalmulticatch_description;
394+
LinkedCorrectionProposalCore proposal= new LinkedCorrectionProposalCore(label, cu, rewrite, IProposalRelevance.ADD_EXCEPTIONS_TO_EXISTING_CATCH);
395+
ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
396+
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
403397

404-
CatchClause newCatchClause= ast.newCatchClause();
405-
String varName= StubUtility.getExceptionVariableName(cu.getJavaProject());
406-
String name= scope.createName(varName, false);
407-
SingleVariableDeclaration var= ast.newSingleVariableDeclaration();
408-
var.setName(ast.newSimpleName(name));
398+
CodeScopeBuilder.Scope scope= CodeScopeBuilder.perform(decl, Selection.createFromStartLength(offset, length)).findScope(offset, length);
399+
scope.setCursor(offset);
409400

410-
UnionType newUnionType= ast.newUnionType();
411-
List<Type> types= newUnionType.types();
401+
CatchClause newCatchClause= ast.newCatchClause();
402+
String varName= StubUtility.getExceptionVariableName(cu.getJavaProject());
403+
String name= scope.createName(varName, false);
404+
SingleVariableDeclaration var= ast.newSingleVariableDeclaration();
405+
var.setName(ast.newSimpleName(name));
412406

413-
for (int i= 0; i < filteredExceptions.size(); i++) {
414-
types.add(addNewException(ast, filteredExceptions, rewrite, proposal, imports, importRewriteContext, i));
415-
}
407+
UnionType newUnionType= ast.newUnionType();
408+
List<Type> types= newUnionType.types();
416409

417-
String nameKey= "name"; //$NON-NLS-1$
418-
proposal.addLinkedPosition(rewrite.track(var.getName()), false, nameKey);
419-
var.setType(newUnionType);
420-
newCatchClause.setException(var);
421-
String catchBody= StubUtility.getCatchBodyContent(cu, "Exception", name, selectedNode, String.valueOf('\n')); //$NON-NLS-1$
410+
for (int i= 0; i < filteredExceptions.size(); i++) {
411+
types.add(addNewException(ast, filteredExceptions, rewrite, proposal, imports, importRewriteContext, i));
412+
}
422413

423-
if (catchBody != null) {
424-
ASTNode node= rewrite.createStringPlaceholder(catchBody, ASTNode.RETURN_STATEMENT);
425-
newCatchClause.getBody().statements().add(node);
426-
}
414+
String nameKey= "name"; //$NON-NLS-1$
415+
proposal.addLinkedPosition(rewrite.track(var.getName()), false, nameKey);
416+
var.setType(newUnionType);
417+
newCatchClause.setException(var);
418+
String catchBody= StubUtility.getCatchBodyContent(cu, "Exception", name, selectedNode, String.valueOf('\n')); //$NON-NLS-1$
427419

428-
ListRewrite listRewrite= rewrite.getListRewrite(surroundingTry, TryStatement.CATCH_CLAUSES_PROPERTY);
429-
listRewrite.insertFirst(newCatchClause, null);
430-
proposals.add(linkedCorrectionProposalToT(proposal, ADD_EXCEPTION_TO_MULTI_CATCH));
420+
if (catchBody != null) {
421+
ASTNode node= rewrite.createStringPlaceholder(catchBody, ASTNode.RETURN_STATEMENT);
422+
newCatchClause.getBody().statements().add(node);
431423
}
424+
425+
ListRewrite listRewrite= rewrite.getListRewrite(surroundingTry, TryStatement.CATCH_CLAUSES_PROPERTY);
426+
listRewrite.insertFirst(newCatchClause, null);
427+
proposals.add(linkedCorrectionProposalToT(proposal, ADD_EXCEPTION_TO_MULTI_CATCH));
432428
}
433429
}
434430

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 IBM Corporation and others.
2+
* Copyright (c) 2024, 2025 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
@@ -32,7 +32,6 @@
3232
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
3333

3434
import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
35-
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
3635
import org.eclipse.jdt.internal.corext.util.Messages;
3736

3837
import org.eclipse.jdt.ui.text.java.IInvocationContext;
@@ -64,9 +63,6 @@ public void createAddSafeVarargsProposals(IInvocationContext context, IProblemLo
6463
}
6564

6665
public void createAddSafeVarargsToDeclarationProposals(IInvocationContext context, IProblemLocation problem, Collection<T> proposals) {
67-
if (!JavaModelUtil.is1d7OrHigher(context.getCompilationUnit().getJavaProject()))
68-
return;
69-
7066
ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot());
7167
IMethodBinding methodBinding;
7268
if (coveringNode instanceof MethodInvocation) {

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2024 Gayan Perera and others.
2+
* Copyright (c) 2023, 2025 Gayan Perera and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,7 +17,6 @@
1717

1818
import org.eclipse.core.runtime.CoreException;
1919

20-
import org.eclipse.jdt.core.IJavaProject;
2120
import org.eclipse.jdt.core.dom.AST;
2221
import org.eclipse.jdt.core.dom.ASTMatcher;
2322
import org.eclipse.jdt.core.dom.ASTNode;
@@ -52,7 +51,6 @@
5251
import org.eclipse.jdt.internal.corext.refactoring.code.Invocations;
5352
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
5453
import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer;
55-
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
5654

5755
import org.eclipse.jdt.internal.ui.text.correction.CorrectionMessages;
5856

@@ -220,9 +218,7 @@ public JoinVariableProposalOperation(VariableDeclarationStatement statement, IfS
220218
@Override
221219
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModelCore linkedModel) throws CoreException {
222220
final ASTRewrite rewrite= cuRewrite.getASTRewrite();
223-
final CompilationUnit cup= (CompilationUnit) statement.getRoot();
224221
final AST ast= cuRewrite.getAST();
225-
final IJavaProject project= cup.getTypeRoot().getJavaProject();
226222

227223
TightSourceRangeComputer sourceRangeComputer= new TightSourceRangeComputer();
228224
sourceRangeComputer.addTightSourceNode(ifStatement != null ? ifStatement : assignParent);
@@ -236,10 +232,8 @@ public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModelCore
236232
Expression thenCopy= (Expression) rewrite.createCopyTarget(thenExpression);
237233
Expression elseCopy= (Expression) rewrite.createCopyTarget(elseExpression);
238234

239-
if (JavaModelUtil.is1d7OrHigher(project)) {
240-
addExplicitTypeArgumentsIfNecessary(rewrite, cuRewrite, thenExpression);
241-
addExplicitTypeArgumentsIfNecessary(rewrite, cuRewrite, elseExpression);
242-
}
235+
addExplicitTypeArgumentsIfNecessary(rewrite, cuRewrite, thenExpression);
236+
addExplicitTypeArgumentsIfNecessary(rewrite, cuRewrite, elseExpression);
243237
conditionalExpression.setThenExpression(thenCopy);
244238
conditionalExpression.setElseExpression(elseCopy);
245239
rewrite.set(fragment, VariableDeclarationFragment.INITIALIZER_PROPERTY, conditionalExpression, null);

0 commit comments

Comments
 (0)