Search in sources :

Example 1 with AnnotationRuntimeBuilderContext

use of spoon.support.visitor.java.internal.AnnotationRuntimeBuilderContext in project spoon by INRIA.

the class JavaReflectionTreeBuilder method visitAnnotation.

@Override
public void visitAnnotation(final Annotation annotation) {
    final CtAnnotation<Annotation> ctAnnotation = factory.Core().createAnnotation();
    enter(new AnnotationRuntimeBuilderContext(ctAnnotation) {

        @Override
        public void addMethod(CtMethod ctMethod) {
            try {
                Object value = annotation.annotationType().getMethod(ctMethod.getSimpleName()).invoke(annotation);
                ctAnnotation.addValue(ctMethod.getSimpleName(), value);
            } catch (Exception ignore) {
                ctAnnotation.addValue(ctMethod.getSimpleName(), "");
            }
        }
    });
    super.visitAnnotation(annotation);
    exit();
    contexts.peek().addAnnotation(ctAnnotation);
}
Also used : AnnotationRuntimeBuilderContext(spoon.support.visitor.java.internal.AnnotationRuntimeBuilderContext) CtAnnotation(spoon.reflect.declaration.CtAnnotation) Annotation(java.lang.annotation.Annotation) CtMethod(spoon.reflect.declaration.CtMethod)

Aggregations

Annotation (java.lang.annotation.Annotation)1 CtAnnotation (spoon.reflect.declaration.CtAnnotation)1 CtMethod (spoon.reflect.declaration.CtMethod)1 AnnotationRuntimeBuilderContext (spoon.support.visitor.java.internal.AnnotationRuntimeBuilderContext)1