use of org.sonar.java.model.declaration.ClassTreeImpl in project sonar-java by SonarSource.
the class TypeAndReferenceSolverTest method annotation_on_method.
@Test
public void annotation_on_method() {
CompilationUnitTree compilationUnit = treeOf("@interface MyAnnotation { } class Class { @MyAnnotation void method() { } }");
ClassTreeImpl annotation = (ClassTreeImpl) compilationUnit.types().get(0);
ClassTreeImpl clazz = (ClassTreeImpl) compilationUnit.types().get(1);
MethodTreeImpl method = (MethodTreeImpl) clazz.members().get(0);
List<AnnotationInstance> annotations = ((JavaSymbol.MethodJavaSymbol) method.symbol()).metadata().annotations();
assertThat(annotations.size()).isEqualTo(1);
assertThat(annotations.get(0).symbol().type().is(annotation.symbol().name())).isTrue();
}
use of org.sonar.java.model.declaration.ClassTreeImpl in project sonar-java by SonarSource.
the class TypeAndReferenceSolverTest method annotation_on_type.
@Test
public void annotation_on_type() {
CompilationUnitTree compilationUnit = treeOf("@interface MyAnnotation { } @MyAnnotation class Class { }");
ClassTreeImpl annotation = (ClassTreeImpl) compilationUnit.types().get(0);
ClassTreeImpl clazz = (ClassTreeImpl) compilationUnit.types().get(1);
List<AnnotationInstance> annotations = ((JavaSymbol.TypeJavaSymbol) clazz.symbol()).metadata().annotations();
assertThat(annotations.size()).isEqualTo(1);
assertThat(annotations.get(0).symbol().type().is(annotation.symbol().name())).isTrue();
}
use of org.sonar.java.model.declaration.ClassTreeImpl in project sonar-java by SonarSource.
the class TypeAndReferenceSolverTest method parametrized_constructor.
@Test
public void parametrized_constructor() {
CompilationUnitTree compilationUnit = treeOf("class A { <T> A(T t) {} void test() { new A(\"hello\"); } }");
MethodTree testMethod = (MethodTree) ((ClassTreeImpl) compilationUnit.types().get(0)).members().get(1);
NewClassTree newClassTree = (NewClassTree) ((ExpressionStatementTree) testMethod.block().body().get(0)).expression();
Type identifierType = newClassTree.identifier().symbolType();
assertThat(identifierType).isInstanceOf(MethodJavaType.class);
assertThat(((MethodJavaType) identifierType).argTypes.get(0).is("java.lang.String")).isTrue();
}
use of org.sonar.java.model.declaration.ClassTreeImpl in project sonar-java by SonarSource.
the class TypeAndReferenceSolverTest method returnTypeOf.
private Type returnTypeOf(String method, String invocation) {
CompilationUnitTree compilationUnit = treeOf("class A { " + method + " void test() { " + invocation + " } }");
MethodTree testMethod = (MethodTree) ((ClassTreeImpl) compilationUnit.types().get(0)).members().get(1);
ExpressionTree methodInvocation = ((ExpressionStatementTree) testMethod.block().body().get(0)).expression();
return methodInvocation.symbolType();
}
use of org.sonar.java.model.declaration.ClassTreeImpl in project sonar-java by SonarSource.
the class TypeAndReferenceSolverTest method annotation_on_method_parameter.
@Test
public void annotation_on_method_parameter() {
CompilationUnitTree compilationUnit = treeOf("@interface MyAnnotation { } class Class { void method(@MyAnnotation int a) { } }");
ClassTreeImpl annotation = (ClassTreeImpl) compilationUnit.types().get(0);
ClassTreeImpl clazz = (ClassTreeImpl) compilationUnit.types().get(1);
MethodTreeImpl method = (MethodTreeImpl) clazz.members().get(0);
VariableTreeImpl parameter = (VariableTreeImpl) method.parameters().get(0);
List<AnnotationInstance> annotations = parameter.getSymbol().metadata().annotations();
assertThat(annotations.size()).isEqualTo(1);
assertThat(annotations.get(0).symbol().type().is(annotation.symbol().name())).isTrue();
}
Aggregations