diff --git a/check_api/src/test/java/com/google/errorprone/util/ASTHelpersTest.java b/check_api/src/test/java/com/google/errorprone/util/ASTHelpersTest.java index cbd5030b4c9..05acfdfff90 100644 --- a/check_api/src/test/java/com/google/errorprone/util/ASTHelpersTest.java +++ b/check_api/src/test/java/com/google/errorprone/util/ASTHelpersTest.java @@ -1985,4 +1985,47 @@ abstract class Test { """) .doTest(); } + + /** Helper for testing {@link ASTHelpers#getTypeSubstitution}. */ + @BugPattern(summary = "", severity = WARNING) + public static final class GetTypeSubstitution extends BugChecker + implements MethodInvocationTreeMatcher { + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + return buildDescription(tree) + .setMessage( + ASTHelpers.getTypeSubstitution( + ASTHelpers.getType(tree.getMethodSelect()).asMethodType(), + ASTHelpers.getSymbol(tree)) + .toString()) + .build(); + } + } + + @Test + public void getTypeSubstitution() { + CompilationTestHelper.newInstance(GetTypeSubstitution.class, getClass()) + .addSourceLines( + "Test.java", + """ + package p; + + import java.util.List; + + class Test { + void f(T[] t) {} + + void g(List t) {} + + void test(Integer[] i, List s) { + // BUG: Diagnostic contains: {} + f(i); + // BUG: Diagnostic contains: {T=[java.lang.String]} + g(s); + } + } + """) + .doTest(); + } }