use of com.google.errorprone.scanner.Scanner in project error-prone by google.
the class CompileTimeConstantExpressionMatcherTest method assertCompilerMatchesOnAssignment.
// Helper methods.
private void assertCompilerMatchesOnAssignment(final Map<String, Boolean> expectedMatches, String... lines) {
final Matcher<ExpressionTree> matcher = new CompileTimeConstantExpressionMatcher();
final Scanner scanner = new Scanner() {
@Override
public Void visitAssignment(AssignmentTree t, VisitorState state) {
ExpressionTree lhs = t.getVariable();
if (expectedMatches.containsKey(lhs.toString())) {
boolean matches = matcher.matches(t.getExpression(), state);
if (expectedMatches.get(lhs.toString())) {
assertTrue("Matcher should match expression" + t.getExpression(), matches);
} else {
assertFalse("Matcher should not match expression" + t.getExpression(), matches);
}
}
return super.visitAssignment(t, state);
}
};
CompilationTestHelper.newInstance(ScannerSupplier.fromScanner(scanner), getClass()).expectResult(Result.OK).addSourceLines("test/CompileTimeConstantExpressionMatcherTestCase.java", lines).doTest();
}
use of com.google.errorprone.scanner.Scanner in project error-prone by google.
the class DescendantOfTransitiveTest method shouldMatchTransitively.
@Test
public void shouldMatchTransitively() throws Exception {
writeFileToLocalDisk("I1.java", "package i;", "public interface I1 {", " void count();", "}");
writeFileToLocalDisk("I2.java", "package i;", "public interface I2 extends I1 {", "}");
writeFileToLocalDisk("B.java", "package b;", "public class B implements i.I2 {", " public void count() {", " }", "}");
assertCompilesWithLocalDisk(new Scanner());
clearSourceFiles();
writeFileToLocalDisk("C.java", "public class C {", " public void test(b.B b) {", " b.count();", " }", "}");
assertCompilesWithLocalDisk(memberSelectMatches(/* shouldMatch= */
true, new DescendantOf("i.I1", "count()")));
}
Aggregations