Skip to content

Commit

Permalink
Merge pull request #1819 from eclipse-jdt/master
Browse files Browse the repository at this point in the history
Merge master to BETA_JAVA24
  • Loading branch information
noopur2507 authored Nov 27, 2024
2 parents dd43c05 + 8aac2ca commit a177cfe
Show file tree
Hide file tree
Showing 28 changed files with 267 additions and 98 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.bcoview/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<artifactId>eclipse.jdt.ui</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.34.0-SNAPSHOT</version>
<version>4.35.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.bcoview</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Pattern;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;

import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.RenameUnusedVariableFixCore;
import org.eclipse.jdt.internal.corext.fix.UnusedCodeFixCore;
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 @@ -150,9 +147,7 @@ public int computeNumberOfFixes(CompilationUnit compilationUnit) {
if (id == IProblem.LocalVariableIsNeverUsed) {
ProblemLocation location= new ProblemLocation(problem);
SimpleName name= UnusedCodeFixCore.getUnusedName(compilationUnit, location);
if (JavaModelUtil.is22OrHigher(compilationUnit.getJavaElement().getJavaProject()) &&
name.getParent() instanceof SingleVariableDeclaration nameParent &&
nameParent.getParent() instanceof Pattern) {
if (RenameUnusedVariableFixCore.canRenameToUnnamedVariable(compilationUnit, name)) {
result++;
}
} else if (id == IProblem.LambdaParameterIsNeverUsed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Pattern;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;

import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.RenameUnusedVariableFixCore;
import org.eclipse.jdt.internal.corext.fix.UnusedCodeFixCore;
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 @@ -277,9 +275,7 @@ public int computeNumberOfFixes(CompilationUnit compilationUnit) {
if (id == IProblem.LocalVariableIsNeverUsed) {
ProblemLocation location= new ProblemLocation(problem);
SimpleName name= UnusedCodeFixCore.getUnusedName(compilationUnit, location);
if (!JavaModelUtil.is22OrHigher(compilationUnit.getJavaElement().getJavaProject()) ||
!(name.getParent() instanceof SingleVariableDeclaration nameParent) ||
!(nameParent.getParent() instanceof Pattern)) {
if (!RenameUnusedVariableFixCore.canRenameToUnnamedVariable(compilationUnit, name)) {
result++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.EnhancedForStatement;
import org.eclipse.jdt.core.dom.ForStatement;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.LambdaExpression;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Pattern;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.TryStatement;
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;

import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;

Expand Down Expand Up @@ -78,15 +80,10 @@ public static RenameUnusedVariableFixCore createRenameToUnnamedFix(CompilationUn
if (name != null) {
IBinding binding= name.resolveBinding();
if (binding != null) {
if (JavaModelUtil.is22OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
if (name.getParent() instanceof SingleVariableDeclaration parent &&
parent.getParent() instanceof Pattern ||
name.getParent() instanceof VariableDeclarationFragment parent2 &&
parent2.getParent() instanceof LambdaExpression) {
String label= FixMessages.UnusedCodeFix_RenameToUnnamedVariable_description;
RenameToUnnamedVariableOperation operation= new RenameToUnnamedVariableOperation(name);
return new RenameUnusedVariableFixCore(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions());
}
if (canRenameToUnnamedVariable(compilationUnit, name)) {
String label= FixMessages.UnusedCodeFix_RenameToUnnamedVariable_description;
RenameToUnnamedVariableOperation operation= new RenameToUnnamedVariableOperation(name);
return new RenameUnusedVariableFixCore(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions());
}
}
}
Expand Down Expand Up @@ -131,16 +128,8 @@ public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProble
if (name != null) {
IBinding binding= name.resolveBinding();
if (binding instanceof IVariableBinding) {
VariableDeclarationFragment parent= ASTNodes.getParent(name, VariableDeclarationFragment.class);
if (parent == null || id == IProblem.LambdaParameterIsNeverUsed) {
if (JavaModelUtil.is22OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
if (name.getParent() instanceof SingleVariableDeclaration nameParent &&
nameParent.getParent() instanceof Pattern ||
name.getParent() instanceof VariableDeclarationFragment varFragment &&
varFragment.getParent() instanceof LambdaExpression) {
result.add(new RenameToUnnamedVariableOperation(name));
}
}
if (canRenameToUnnamedVariable(compilationUnit, name)) {
result.add(new RenameToUnnamedVariableOperation(name));
}
}
}
Expand All @@ -153,8 +142,23 @@ public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProble
return new RenameUnusedVariableFixCore(FixMessages.UnusedCodeFix_change_name, compilationUnit, result.toArray(new CompilationUnitRewriteOperation[result.size()]));
}

public static boolean isFormalParameterInEnhancedForStatement(SimpleName name) {
return name.getParent() instanceof SingleVariableDeclaration && name.getParent().getLocationInParent() == EnhancedForStatement.PARAMETER_PROPERTY;
public static boolean canRenameToUnnamedVariable(CompilationUnit compilationUnit, SimpleName name) {
if (JavaModelUtil.is22OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
if (name.getParent() instanceof SingleVariableDeclaration nameParent) {
if (nameParent.getParent() instanceof Pattern || nameParent.getParent() instanceof EnhancedForStatement) {
return true;
}
} else if (name.getParent() instanceof VariableDeclarationFragment varFragment) {
if (varFragment.getParent() instanceof LambdaExpression) {
return true;
} else if (varFragment.getParent() instanceof VariableDeclarationExpression varFragmentParent) {
if (varFragmentParent.getParent() instanceof TryStatement || varFragmentParent.getParent() instanceof ForStatement) {
return true;
}
}
}
}
return false;
}

public static SimpleName getUnusedName(CompilationUnit compilationUnit, IProblemLocation problem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.NodeFinder;
import org.eclipse.jdt.core.dom.ParenthesizedExpression;
import org.eclipse.jdt.core.dom.Pattern;
import org.eclipse.jdt.core.dom.PostfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
import org.eclipse.jdt.core.dom.QualifiedName;
Expand All @@ -90,7 +89,6 @@
import org.eclipse.jdt.internal.corext.dom.ReplaceRewrite;
import org.eclipse.jdt.internal.corext.dom.StatementRewrite;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.corext.util.Messages;

import org.eclipse.jdt.ui.cleanup.CleanUpOptions;
Expand Down Expand Up @@ -930,7 +928,7 @@ public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProble

if ((removeUnusedLocalVariables && id == IProblem.LocalVariableIsNeverUsed) || (removeUnusedPrivateFields && id == IProblem.UnusedPrivateField)) {
SimpleName name= getUnusedName(compilationUnit, problem);
if (name != null) {
if (name != null && !RenameUnusedVariableFixCore.canRenameToUnnamedVariable(compilationUnit, name)) {
IBinding binding= name.resolveBinding();
if (binding instanceof IVariableBinding && !isFormalParameterInEnhancedForStatement(name) && (!((IVariableBinding) binding).isField() || isSideEffectFree(name, compilationUnit))) {
VariableDeclarationFragment parent= ASTNodes.getParent(name, VariableDeclarationFragment.class);
Expand All @@ -941,16 +939,7 @@ public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProble
}
variableDeclarations.get(varDecl).add(name);
} else {
if (id == IProblem.LocalVariableIsNeverUsed) {
SimpleName nameNode= UnusedCodeFixCore.getUnusedName(compilationUnit, problem);
if (!JavaModelUtil.is22OrHigher(compilationUnit.getJavaElement().getJavaProject()) ||
!(nameNode.getParent() instanceof SingleVariableDeclaration nameParent) ||
!(nameParent.getParent() instanceof Pattern)) {
result.add(new RemoveUnusedMemberOperation(new SimpleName[] { name }, false));
}
} else {
result.add(new RemoveUnusedMemberOperation(new SimpleName[] { name }, false));
}
result.add(new RemoveUnusedMemberOperation(new SimpleName[] { name }, false));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.junit.runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<artifactId>eclipse.jdt.ui</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.34.0-SNAPSHOT</version>
<version>4.35.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.junit.runtime</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.junit/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.junit
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.junit;singleton:=true
Bundle-Version: 3.16.600.qualifier
Bundle-Version: 3.16.700.qualifier
Bundle-Activator: org.eclipse.jdt.internal.junit.ui.JUnitPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Expand Down
Binary file modified org.eclipse.jdt.junit/icons/full/etool16/run_exc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified org.eclipse.jdt.junit/icons/full/etool16/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.junit4.runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<artifactId>eclipse.jdt.ui</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.34.0-SNAPSHOT</version>
<version>4.35.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.junit4.runtime</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.junit5.runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<artifactId>eclipse.jdt.ui</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.34.0-SNAPSHOT</version>
<version>4.35.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.junit5.runtime</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.text.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.34.0-SNAPSHOT</version>
<version>4.35.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.jdt</groupId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ui.examples.projects/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<artifactId>eclipse.jdt.ui</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.34.0-SNAPSHOT</version>
<version>4.35.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.ui.examples.projects</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ui.junit.sampleproject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>eclipse.jdt.ui</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.34.0-SNAPSHOT</version>
<version>4.35.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jdt.ui</groupId>
<artifactId>org.eclipse.jdt.ui.junit.sampleproject</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ui.tests.refactoring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.34.0-SNAPSHOT</version>
<version>4.35.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.jdt</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ private void followFieldReference(ReferencedObject ref, Object curr, Field fld)
if (fieldVal != null) {
fQueue.add(new ReferencedFieldElement(ref, fld, fieldVal));
}
} catch (IllegalArgumentException e) {
// XXX workaround for error in JDK: https://bugs.openjdk.org/browse/JDK-8337622
if (!"Can not get final java.lang.Class field java.lang.Class.componentType on java.lang.Class".equals(e.getMessage())) {
throw e;
}
} catch (IllegalAccessException e) {
handleError(e, fld);
}
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ui.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>eclipse.jdt.ui</groupId>
<version>4.34.0-SNAPSHOT</version>
<version>4.35.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.jdt</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 IBM Corporation and others.
* Copyright (c) 2019, 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 @@ -126,7 +126,7 @@ enum Day {
public void testSplitSwitchCaseLabelRuleStatement() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
fJProject1.setRawClasspath(projectSetup.getDefaultClasspath(), null);
JavaProjectHelper.set12CompilerOptions(fJProject1, true);
JavaProjectHelper.set14CompilerOptions(fJProject1, true);
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");

String str= """
Expand Down
Loading

0 comments on commit a177cfe

Please sign in to comment.