Skip to content

Commit

Permalink
Fix local var cleanup to avoid method references (#1541)
Browse files Browse the repository at this point in the history
- fix VarCleanUpCore visitor maybeUserVar() method to return false
  for a method reference initializer
- add new test to CleanUpTest11
- fixes #1524
  • Loading branch information
jjohnstn authored Jul 25, 2024
1 parent 754889c commit 22e6bef
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 Fabrice TIERCELIN and others.
* Copyright (c) 2020, 2024 Fabrice TIERCELIN 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 @@ -34,6 +34,7 @@
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionMethodReference;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
Expand Down Expand Up @@ -148,6 +149,9 @@ public boolean visit(final SingleVariableDeclaration node) {
}

private boolean maybeUseVar(final Type type, final Expression initializer, final int extraDimensions) {
if (initializer instanceof ExpressionMethodReference) {
return false;
}
if (type.isVar()
|| initializer == null
|| initializer.resolveTypeBinding() == null
Expand Down
Loading

0 comments on commit 22e6bef

Please sign in to comment.