Search in sources :

Example 1 with CtAnnotatedElementType

use of spoon.reflect.declaration.CtAnnotatedElementType in project spoon by INRIA.

the class ParentExiter method scanCtElement.

@Override
public void scanCtElement(CtElement e) {
    if (child instanceof CtAnnotation && this.jdtTreeBuilder.getContextBuilder().annotationValueName.isEmpty()) {
        // we check if the current element can have the annotation attached
        CtAnnotatedElementType annotatedElementType = CtAnnotation.getAnnotatedElementTypeForCtElement(e);
        annotatedElementType = (e instanceof CtTypeParameter || e instanceof CtTypeParameterReference) ? CtAnnotatedElementType.TYPE_USE : annotatedElementType;
        // in case of noclasspath, we cannot be 100% sure, so we guess it must be attached...
        if (this.jdtTreeBuilder.getFactory().getEnvironment().getNoClasspath() || (annotatedElementType != null && JDTTreeBuilderQuery.hasAnnotationWithType((Annotation) childJDT, annotatedElementType))) {
            e.addAnnotation((CtAnnotation<?>) child);
        }
        // in this case the annotation should be (also) attached to the type
        if (e instanceof CtTypedElement && JDTTreeBuilderQuery.hasAnnotationWithType((Annotation) childJDT, CtAnnotatedElementType.TYPE_USE)) {
            List<CtAnnotation> annotations = new ArrayList<>();
            if (!annotationsMap.containsKey(e)) {
                annotationsMap.put((CtTypedElement<?>) e, annotations);
            } else {
                annotations = annotationsMap.get(e);
            }
            annotations.add((CtAnnotation) child.clone());
            annotationsMap.put((CtTypedElement<?>) e, annotations);
        }
    }
}
Also used : CtAnnotation(spoon.reflect.declaration.CtAnnotation) CtTypeParameterReference(spoon.reflect.reference.CtTypeParameterReference) CtTypeParameter(spoon.reflect.declaration.CtTypeParameter) CtAnnotatedElementType(spoon.reflect.declaration.CtAnnotatedElementType) ArrayList(java.util.ArrayList) CtTypedElement(spoon.reflect.declaration.CtTypedElement) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation) CtAnnotation(spoon.reflect.declaration.CtAnnotation)

Aggregations

ArrayList (java.util.ArrayList)1 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)1 CtAnnotatedElementType (spoon.reflect.declaration.CtAnnotatedElementType)1 CtAnnotation (spoon.reflect.declaration.CtAnnotation)1 CtTypeParameter (spoon.reflect.declaration.CtTypeParameter)1 CtTypedElement (spoon.reflect.declaration.CtTypedElement)1 CtTypeParameterReference (spoon.reflect.reference.CtTypeParameterReference)1