Skip to content

Commit 3bc6112

Browse files
klueverError Prone Team
authored andcommitted
PUBLIC: Add a test for a constructor + static import bug in the InlineMeSuggester.
See also[] PiperOrigin-RevId: 831408448
1 parent 85697f7 commit 3bc6112

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

core/src/test/java/com/google/errorprone/bugpatterns/inlineme/SuggesterTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,4 +1408,42 @@ public ExecutionError(String message) {
14081408
.expectUnchanged()
14091409
.doTest();
14101410
}
1411+
1412+
@Test
1413+
public void inlineMeSuggestionStaticImportInConstructor() {
1414+
refactoringTestHelper
1415+
.addInputLines(
1416+
"Client.java",
1417+
"""
1418+
import static java.nio.charset.StandardCharsets.UTF_8;
1419+
1420+
public final class Client {
1421+
@Deprecated
1422+
public static String getString(byte[] bytes, int offset, int length) {
1423+
return new String(bytes, offset, length, UTF_8);
1424+
}
1425+
}
1426+
""")
1427+
// TODO: b/459759186 - this is a bug! UTF_8 should be fully qualified in the staticImports
1428+
// parameter, and not in the imports parameter. The @InlineMe annotation should be:
1429+
// @InlineMe(
1430+
// replacement = "new String(bytes, offset, length, UTF_8)",
1431+
// staticImports = "java.nio.charset.StandardCharsets.UTF_8")
1432+
.addOutputLines(
1433+
"Client.java",
1434+
"""
1435+
import static java.nio.charset.StandardCharsets.UTF_8;
1436+
1437+
import com.google.errorprone.annotations.InlineMe;
1438+
1439+
public final class Client {
1440+
@InlineMe(replacement = "new String(bytes, offset, length, UTF_8)", imports = "UTF_8")
1441+
@Deprecated
1442+
public static String getString(byte[] bytes, int offset, int length) {
1443+
return new String(bytes, offset, length, UTF_8);
1444+
}
1445+
}
1446+
""")
1447+
.doTest();
1448+
}
14111449
}

0 commit comments

Comments
 (0)