use of com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration in project javaparser by javaparser.
the class AnnotationsResolutionTest method solveJavassistNormalAnnotation.
@Test
void solveJavassistNormalAnnotation() throws IOException {
// parse compilation unit and get annotation expression
CompilationUnit cu = parseSample("Annotations");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CD");
MethodDeclaration method = Navigator.demandMethod(clazz, "testSomethingElse");
NormalAnnotationExpr annotationExpr = (NormalAnnotationExpr) method.getAnnotation(0);
// resolve annotation expression
ResolvedAnnotationDeclaration resolved = annotationExpr.resolve();
// check that the expected annotation declaration equals the resolved annotation declaration
assertEquals("org.junit.Test", resolved.getQualifiedName());
assertEquals("org.junit", resolved.getPackageName());
assertEquals("Test", resolved.getName());
}
use of com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration in project javaparser by javaparser.
the class AnnotationsResolutionTest method solveJavaParserMarkerAnnotation.
@Test
void solveJavaParserMarkerAnnotation() {
// parse compilation unit and get annotation expression
CompilationUnit cu = parseSample("Annotations");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CA");
MarkerAnnotationExpr annotationExpr = (MarkerAnnotationExpr) clazz.getAnnotation(0);
// resolve annotation expression
ResolvedAnnotationDeclaration resolved = annotationExpr.resolve();
// check that the expected annotation declaration equals the resolved annotation declaration
assertEquals("foo.bar.MyAnnotation", resolved.getQualifiedName());
assertEquals("foo.bar", resolved.getPackageName());
assertEquals("MyAnnotation", resolved.getName());
}
use of com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration in project javaparser by javaparser.
the class AnnotationsResolutionTest method solveReflectionSingleMemberAnnotation.
@Test
void solveReflectionSingleMemberAnnotation() {
// parse compilation unit and get annotation expression
CompilationUnit cu = parseSample("Annotations");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CC");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo");
SingleMemberAnnotationExpr annotationExpr = (SingleMemberAnnotationExpr) method.getBody().get().getStatement(0).asExpressionStmt().getExpression().asVariableDeclarationExpr().getAnnotation(0);
// resolve annotation expression
ResolvedAnnotationDeclaration resolved = annotationExpr.resolve();
// check that the expected annotation declaration equals the resolved annotation declaration
assertEquals("java.lang.SuppressWarnings", resolved.getQualifiedName());
assertEquals("java.lang", resolved.getPackageName());
assertEquals("SuppressWarnings", resolved.getName());
}
use of com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration in project javaparser by javaparser.
the class AnnotationsResolutionTest method solveJavaParserSingleMemberAnnotation.
@Test
void solveJavaParserSingleMemberAnnotation() {
// parse compilation unit and get annotation expression
CompilationUnit cu = parseSample("Annotations");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CC");
SingleMemberAnnotationExpr annotationExpr = (SingleMemberAnnotationExpr) clazz.getAnnotation(0);
// resolve annotation expression
ResolvedAnnotationDeclaration resolved = annotationExpr.resolve();
// check that the expected annotation declaration equals the resolved annotation declaration
assertEquals("foo.bar.MyAnnotationWithSingleValue", resolved.getQualifiedName());
assertEquals("foo.bar", resolved.getPackageName());
assertEquals("MyAnnotationWithSingleValue", resolved.getName());
}
use of com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration in project javaparser by javaparser.
the class AnnotationsResolutionTest method solveJavassistNormalAnnotationWithDefault.
@Test
void solveJavassistNormalAnnotationWithDefault() throws IOException {
// parse compilation unit and get annotation expression
CompilationUnit cu = parseSample("Annotations");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "CG");
MethodDeclaration method = Navigator.demandMethod(clazz, "testSomething");
MarkerAnnotationExpr annotationExpr = (MarkerAnnotationExpr) method.getAnnotation(0);
// resolve annotation expression
ResolvedAnnotationDeclaration resolved = annotationExpr.resolve();
// check that the expected annotation declaration equals the resolved annotation declaration
assertEquals("org.junit.Ignore", resolved.getQualifiedName());
Expression memberValue = resolved.getAnnotationMembers().get(0).getDefaultValue();
assertEquals(StringLiteralExpr.class, memberValue.getClass());
ResolvedType rt = resolved.getAnnotationMembers().get(0).getType();
assertEquals("java.lang.String", rt.describe());
}
Aggregations