From ed6b121f2b24f9706d0ae3db4a1e7eb60e1e6c4e Mon Sep 17 00:00:00 2001 From: Scott Wegner Date: Thu, 24 Oct 2024 10:18:29 -0700 Subject: [PATCH] Add a repro test for broken behavior inlining the parameter value into the fully-qualified type package in the replacement. PiperOrigin-RevId: 689427470 --- .../bugpatterns/inlineme/InlinerTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) 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 4e7084a98d2..530b44218e7 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 @@ -1511,6 +1511,59 @@ public void doTest() { .doTest(); } + @Test + public void inlinerReplacesParameterValueInPackageName_b375421323() { + refactoringTestHelper + .addInputLines( + "Bar.java", + """ + package foo; + + public class Bar { + public static void baz(String s) {} + } + """) + .expectUnchanged() + .addInputLines( + "Client.java", + """ + import com.google.errorprone.annotations.InlineMe; + import foo.Bar; + + public class Client { + @InlineMe(replacement = "Bar.baz(foo)", imports = "foo.Bar") + public static void inlinedMethod(String foo) { + Bar.baz(foo); + } + } + """) + .expectUnchanged() + .addInputLines( + "Caller.java", + """ + class Caller { + class Bar {} + + void doTest() { + Client.inlinedMethod("abc"); + } + } + """) + .addOutputLines( + "out/Caller.java", + """ + class Caller { + class Bar {} + + void doTest() { + "abc".Bar.baz("abc"); + } + } + """) + .allowBreakingChanges() + .doTest(); + } + private BugCheckerRefactoringTestHelper bugCheckerWithPrefixFlag(String prefix) { return BugCheckerRefactoringTestHelper.newInstance(Inliner.class, getClass()) .setArgs("-XepOpt:" + PREFIX_FLAG + "=" + prefix);