use of org.sonar.java.ast.visitors.SubscriptionVisitor in project sonar-java by SonarSource.
the class MethodJavaSymbolTest method test_throws.
@Test
public void test_throws() {
File bytecodeDir = new File("target/test-classes");
JavaAstScanner.scanSingleFileForTests(new File("src/test/java/org/sonar/java/resolve/targets/MethodThrowingExceptionsUsage.java"), new VisitorsBridge(Collections.singleton(new SubscriptionVisitor() {
@Override
public List<Tree.Kind> nodesToVisit() {
return Lists.newArrayList(Tree.Kind.METHOD_INVOCATION);
}
@Override
public void visitNode(Tree tree) {
Symbol.MethodSymbol methodSymbol = (Symbol.MethodSymbol) ((MethodInvocationTree) tree).symbol();
List<Type> thrownTypes = methodSymbol.thrownTypes();
assertThat(thrownTypes).hasSize(2);
if ("test".equals(methodSymbol.name())) {
// FIXME substitution should be done : see SONARJAVA-1778
assertThat(((JavaType) thrownTypes.get(0)).isTagged(JavaType.TYPEVAR)).isTrue();
} else {
assertThat(thrownTypes.get(0).is("java.sql.SQLException")).isTrue();
}
assertThat(thrownTypes.get(1).is("java.io.IOException")).isTrue();
}
}), Lists.newArrayList(bytecodeDir), null));
}
Aggregations