Skip to content

Commit

Permalink
Add unit test coverage for getTypeSubstitution
Browse files Browse the repository at this point in the history
Including a case that shows the bug that will be fixed by unknown commit.

PiperOrigin-RevId: 719062324
  • Loading branch information
cushon authored and Error Prone Team committed Jan 24, 2025
1 parent b6a2b10 commit 27cc70f
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
<T> void f(T[] t) {}
<T> void g(List<T> t) {}
void test(Integer[] i, List<String> s) {
// BUG: Diagnostic contains: {}
f(i);
// BUG: Diagnostic contains: {T=[java.lang.String]}
g(s);
}
}
""")
.doTest();
}
}

0 comments on commit 27cc70f

Please sign in to comment.