Skip to content

Commit

Permalink
Handle method references in renameMethodWithInvocations
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 553202443
  • Loading branch information
cushon authored and Error Prone Team committed Aug 2, 2023
1 parent a2d6ad7 commit 449e6f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.InstanceOfTree;
import com.sun.source.tree.MemberReferenceTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.MethodTree;
Expand Down Expand Up @@ -785,6 +786,17 @@ public Void visitMemberSelect(MemberSelectTree tree, Void unused) {
}
return super.visitMemberSelect(tree, null);
}

@Override
public Void visitMemberReference(MemberReferenceTree tree, Void unused) {
if (sym.equals(getSymbol(tree))) {
fix.replace(
state.getEndPosition(tree.getQualifierExpression()),
state.getEndPosition(tree),
"::" + replacement);
}
return super.visitMemberReference(tree, unused);
}
}.scan(state.getPath().getCompilationUnit(), null);
return fix.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,22 @@ public void lambdaExpressionParameterInsideOverridingMethod() {
"}")
.doTest();
}

@Test
public void methodReference() {
refactoringHelper
.addInputLines(
"Test.java",
"class Test {",
" private void foo_bar() {}",
" private Runnable r = this::foo_bar;",
"}")
.addOutputLines(
"Test.java",
"class Test {",
" private void fooBar() {}",
" private Runnable r = this::fooBar;",
"}")
.doTest();
}
}

0 comments on commit 449e6f4

Please sign in to comment.