diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java index 717de4a2c5b..5b234814c50 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java @@ -234,7 +234,17 @@ && stringContainsComments(state.getSourceForNode(tree), state.context)) { "\\b" + Pattern.quote(typeName.getKey()) + "\\b", Matcher.quoteReplacement(typeName.getValue())); } + for (int i = 0; i < varNames.size(); i++) { + // The replacement logic below assumes the existence of another token after the parameter + // in the replacement string (ex: a trailing parens, comma, dot, etc.). However, in the case + // where the replacement is _just_ one parameter, there isn't a trailing token. We just make + // the direct replacement here. + if (replacement.equals(varNames.get(i))) { + replacement = callingVars.get(i); + break; + } + // Ex: foo(int a, int... others) -> this.bar(a, others) // If caller passes 0 args in the varargs position, we want to remove the preceding comma to // make this.bar(a) (as opposed to "this.bar(a, )" diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java index eb8b969f8f2..ff1523dc8a4 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java @@ -29,9 +29,10 @@ /** Tests for the {@link Inliner}. */ @RunWith(JUnit4.class) public class InlinerTest { - /* We expect that all @InlineMe annotations we try to use as inlineable targets are valid, - so we run both checkers here. If the Validator trips on a method, we'll suggest some - replacement which should trip up the checker. + /* + We expect that all @InlineMe annotations we try to use as inlineable targets are valid, + so we run both checkers here. If the Validator trips on a method, we'll suggest some + replacement which should trip up the checker. */ private final BugCheckerRefactoringTestHelper refactoringTestHelper = BugCheckerRefactoringTestHelper.newInstance( @@ -912,9 +913,7 @@ public void replaceWithJustParameter() { "public final class Caller {", " public void doTest() {", " Client client = new Client();", - // TODO(b/180976346): replacements of the form that terminate in a parameter by itself - // don't work with the new replacement tool, but this is uncommon enough - " int x = client.identity(42);", + " int x = 42;", " }", "}") .doTest();