use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class UsesDirectiveTreeImplTest method moduleDirective.
private UsesDirectiveTree moduleDirective(String exportsDirective) {
CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n " + exportsDirective + "\n}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (UsesDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class LeastUpperBoundTest method declaredTypes.
private static List<Type> declaredTypes(String... lines) {
CompilationUnitTree tree = treeOf(lines);
List<Type> results = Lists.newLinkedList();
for (Tree classTree : tree.types()) {
Type type = ((ClassTree) classTree).symbol().type();
results.add(type);
}
return results;
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class LeastUpperBoundTest method treeOf.
private static CompilationUnitTree treeOf(String... lines) {
StringBuilder builder = new StringBuilder();
for (String line : lines) {
builder.append(line).append(System.lineSeparator());
}
CompilationUnitTree cut = (CompilationUnitTree) JavaParser.createParser().parse(builder.toString());
SemanticModel.createFor(cut, new SquidClassLoader(Lists.newArrayList(new File("target/test-classes"), new File("target/classes"))));
return cut;
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class TypeAndReferenceSolverTest method annotation_on_variable.
@Test
public void annotation_on_variable() {
CompilationUnitTree compilationUnit = treeOf("@interface MyAnnotation { } class Class { @MyAnnotation Object field; }");
ClassTreeImpl annotation = (ClassTreeImpl) compilationUnit.types().get(0);
ClassTreeImpl clazz = (ClassTreeImpl) compilationUnit.types().get(1);
VariableTreeImpl variable = (VariableTreeImpl) clazz.members().get(0);
List<AnnotationInstance> annotations = variable.getSymbol().metadata().annotations();
assertThat(annotations.size()).isEqualTo(1);
assertThat(annotations.get(0).symbol().type().is(annotation.symbol().name())).isTrue();
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class TypeAndReferenceSolverTest method identifier_of_variable_symbol.
@Test
public void identifier_of_variable_symbol() {
CompilationUnitTree compilationUnit = treeOf("class A { Object field; }");
ClassTreeImpl clazz = (ClassTreeImpl) compilationUnit.types().get(0);
VariableTree variable = (VariableTree) clazz.members().get(0);
assertThat(variable.symbol().isUnknown()).isFalse();
assertThat(variable.symbol().usages()).isEmpty();
assertThat(variable.simpleName().symbol().isUnknown()).isFalse();
assertThat(variable.simpleName().symbol()).isEqualTo(variable.symbol());
}
Aggregations