Skip to content

Commit

Permalink
UnnecessaryMethodReference: drop the requirement that the offending m…
Browse files Browse the repository at this point in the history
…ethod reference must be a method argument.

This lets us refactor variable assignments too.

I'm not sure what the rationale for this restriction was, given no tests fail having removed it.

PiperOrigin-RevId: 631745347
  • Loading branch information
graememorgan authored and Error Prone Team committed May 8, 2024
1 parent 93861b8 commit af521ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Expand Up @@ -41,7 +41,6 @@
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.MemberReferenceTree;
import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.code.Scope;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
Expand All @@ -59,9 +58,6 @@ public Description matchMemberReference(MemberReferenceTree tree, VisitorState s
if (!tree.getMode().equals(ReferenceMode.INVOKE)) {
return NO_MATCH;
}
if (!(state.getPath().getParentPath().getLeaf() instanceof MethodInvocationTree)) {
return NO_MATCH;
}
TargetType targetType = targetType(state);
if (targetType == null) {
return NO_MATCH;
Expand Down
Expand Up @@ -249,4 +249,21 @@ public void range_isGuavaPredicate() {
"}")
.doTest();
}

@Test
public void listToIterator() {
helper
.addSourceLines(
"T.java",
"import com.google.common.collect.ImmutableList;",
"import java.util.List;",
"abstract class T {",
" void test() {",
" List<Integer> x = ImmutableList.of(1, 2);",
" // BUG: Diagnostic contains:",
" Iterable<Integer> xi = x::iterator;",
" }",
"}")
.doTest();
}
}

0 comments on commit af521ef

Please sign in to comment.