use of java.lang.annotation.Target in project epoxy by airbnb.
the class AttributeInfo method buildAnnotationLists.
/**
* Keeps track of annotations on the attribute so that they can be used in the generated setter
* and getter method. Setter and getter annotations are stored separately since the annotation may
* not target both method and parameter types.
*/
private void buildAnnotationLists(List<? extends AnnotationMirror> annotationMirrors) {
for (AnnotationMirror annotationMirror : annotationMirrors) {
if (!annotationMirror.getElementValues().isEmpty()) {
// Not supporting annotations with values for now
continue;
}
ClassName annotationClass = ClassName.bestGuess(annotationMirror.getAnnotationType().toString());
if (annotationClass.equals(ClassName.get(EpoxyAttribute.class))) {
// Don't include our own annotation
continue;
}
DeclaredType annotationType = annotationMirror.getAnnotationType();
// A target may exist on an annotation type to specify where the annotation can
// be used, for example fields, methods, or parameters.
Target targetAnnotation = annotationType.asElement().getAnnotation(Target.class);
// Allow all target types if no target was specified on the annotation
List<ElementType> elementTypes = Arrays.asList(targetAnnotation == null ? ElementType.values() : targetAnnotation.value());
AnnotationSpec annotationSpec = AnnotationSpec.builder(annotationClass).build();
if (elementTypes.contains(ElementType.PARAMETER)) {
setterAnnotations.add(annotationSpec);
}
if (elementTypes.contains(ElementType.METHOD)) {
getterAnnotations.add(annotationSpec);
}
}
}
Aggregations