From 913d11151a64dc99f5cdba5ab51d4fc97b98787e Mon Sep 17 00:00:00 2001 From: Scott Wegner Date: Thu, 24 Oct 2024 09:48:52 -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: 689416576 --- .../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 4e7084a98d2d..530b44218e7e 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);