Search in sources :

Example 11 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project realm-java by realm.

the class ModuleMetaData method getClassMetaDataFromModule.

// Detour needed to access the class elements in the array
// See http://blog.retep.org/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/
@SuppressWarnings("unchecked")
private Set<String> getClassMetaDataFromModule(Element classElement) {
    AnnotationMirror annotationMirror = getAnnotationMirror(classElement);
    AnnotationValue annotationValue = getAnnotationValue(annotationMirror);
    Set<String> classes = new HashSet<String>();
    List<? extends AnnotationValue> moduleClasses = (List<? extends AnnotationValue>) annotationValue.getValue();
    for (AnnotationValue classMirror : moduleClasses) {
        String fullyQualifiedClassName = classMirror.getValue().toString();
        classes.add(fullyQualifiedClassName);
    }
    return classes;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationValue(javax.lang.model.element.AnnotationValue) List(java.util.List) HashSet(java.util.HashSet)

Example 12 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project realm-java by realm.

the class ModuleMetaData method hasCustomClassList.

// Work-around for asking for a Class primitive array which would otherwise throw a TypeMirrorException
// https://community.oracle.com/thread/1184190
@SuppressWarnings("unchecked")
private boolean hasCustomClassList(Element classElement) {
    AnnotationMirror annotationMirror = getAnnotationMirror(classElement);
    AnnotationValue annotationValue = getAnnotationValue(annotationMirror);
    if (annotationValue == null) {
        return false;
    } else {
        List<? extends AnnotationValue> moduleClasses = (List<? extends AnnotationValue>) annotationValue.getValue();
        return moduleClasses.size() > 0;
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationValue(javax.lang.model.element.AnnotationValue) List(java.util.List)

Example 13 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project robolectric by robolectric.

the class Validator method message.

protected void message(Kind severity, String msg, AnnotationValue av) {
    final AnnotationMirror am = getCurrentAnnotation();
    messager.printMessage(severity, msg, currentElement, am, av);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror)

Example 14 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessor method processNestedType.

private void processNestedType(String prefix, TypeElement element, ExecutableElement source, String name, ExecutableElement getter, VariableElement field, TypeMirror returnType) {
    Element returnElement = this.processingEnv.getTypeUtils().asElement(returnType);
    boolean isNested = isNested(returnElement, field, element);
    AnnotationMirror annotation = getAnnotation(getter, configurationPropertiesAnnotation());
    if (returnElement != null && returnElement instanceof TypeElement && annotation == null && isNested) {
        String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, name);
        this.metadataCollector.add(ItemMetadata.newGroup(nestedPrefix, this.typeUtils.getQualifiedName(returnElement), this.typeUtils.getQualifiedName(element), (getter == null ? null : getter.toString())));
        processTypeElement(nestedPrefix, (TypeElement) returnElement, source);
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element)

Example 15 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessor method getItemDeprecation.

private ItemDeprecation getItemDeprecation(ExecutableElement getter) {
    AnnotationMirror annotation = getAnnotation(getter, deprecatedConfigurationPropertyAnnotation());
    String reason = null;
    String replacement = null;
    if (annotation != null) {
        Map<String, Object> elementValues = getAnnotationElementValues(annotation);
        reason = (String) elementValues.get("reason");
        replacement = (String) elementValues.get("replacement");
    }
    return new ItemDeprecation(("".equals(reason) ? null : reason), ("".equals(replacement) ? null : replacement));
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation)

Aggregations

AnnotationMirror (javax.lang.model.element.AnnotationMirror)88 TypeElement (javax.lang.model.element.TypeElement)46 AnnotationValue (javax.lang.model.element.AnnotationValue)21 Element (javax.lang.model.element.Element)19 DeclaredType (javax.lang.model.type.DeclaredType)19 ExecutableElement (javax.lang.model.element.ExecutableElement)18 VariableElement (javax.lang.model.element.VariableElement)16 TypeMirror (javax.lang.model.type.TypeMirror)16 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)13 List (java.util.List)12 Map (java.util.Map)10 PackageElement (javax.lang.model.element.PackageElement)7 HashMap (java.util.HashMap)5 Nullable (javax.annotation.Nullable)5 IOException (java.io.IOException)4 MoreElements.getAnnotationMirror (com.google.auto.common.MoreElements.getAnnotationMirror)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ClassName (com.squareup.javapoet.ClassName)3