Search in sources :

Example 1 with AnnotationValue

use of javax.lang.model.element.AnnotationValue in project DeepLinkDispatch by airbnb.

the class DeepLinkProcessor method enumerateCustomDeepLinks.

private static List<String> enumerateCustomDeepLinks(Element element, Map<Element, String[]> prefixesMap) {
    Set<? extends AnnotationMirror> annotationMirrors = AnnotationMirrors.getAnnotatedAnnotations(element, DEEP_LINK_SPEC_CLASS);
    final List<String> deepLinks = new ArrayList<>();
    for (AnnotationMirror customAnnotation : annotationMirrors) {
        List<? extends AnnotationValue> suffixes = asAnnotationValues(AnnotationMirrors.getAnnotationValue(customAnnotation, "value"));
        String[] prefixes = prefixesMap.get(customAnnotation.getAnnotationType().asElement());
        for (String prefix : prefixes) {
            for (AnnotationValue suffix : suffixes) {
                deepLinks.add(prefix + suffix.getValue());
            }
        }
    }
    return deepLinks;
}
Also used : MoreElements.getAnnotationMirror(com.google.auto.common.MoreElements.getAnnotationMirror) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ArrayList(java.util.ArrayList) AnnotationValue(javax.lang.model.element.AnnotationValue)

Example 2 with AnnotationValue

use of javax.lang.model.element.AnnotationValue in project neo4j by neo4j.

the class ServiceProcessor method process.

@SuppressWarnings("unchecked")
@Override
protected void process(TypeElement annotationType, Element annotated, AnnotationMirror annotation, Map<? extends ExecutableElement, ? extends AnnotationValue> values) throws IOException {
    for (AnnotationValue o : (List<? extends AnnotationValue>) values.values().iterator().next().getValue()) {
        TypeMirror service = (TypeMirror) o.getValue();
        addTo(((TypeElement) annotated).getQualifiedName().toString(), "META-INF", "services", service.toString());
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) AnnotationValue(javax.lang.model.element.AnnotationValue) List(java.util.List)

Example 3 with AnnotationValue

use of javax.lang.model.element.AnnotationValue in project bazel by bazelbuild.

the class AnnotationUtils method getElementValueEnumArray.

/**
     * Get the attribute with the name {@code name} of the annotation
     * {@code anno}, or the default value if no attribute is present explicitly,
     * where the attribute has an array type and the elements are {@code Enum}s.
     * One element of the result is expected to have type {@code expectedType}.
     */
public static <T extends Enum<T>> List<T> getElementValueEnumArray(AnnotationMirror anno, CharSequence name, Class<T> t, boolean useDefaults) {
    @SuppressWarnings("unchecked") List<AnnotationValue> la = getElementValue(anno, name, List.class, useDefaults);
    List<T> result = new ArrayList<T>(la.size());
    for (AnnotationValue a : la) {
        T value = Enum.valueOf(t, a.getValue().toString());
        result.add(value);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) AnnotationValue(javax.lang.model.element.AnnotationValue)

Example 4 with AnnotationValue

use of javax.lang.model.element.AnnotationValue in project bazel by bazelbuild.

the class AnnotationUtils method getElementValueArray.

/**
     * Get the attribute with the name {@code name} of the annotation
     * {@code anno}, where the attribute has an array type. One element of the
     * result is expected to have type {@code expectedType}.
     *
     * Parameter useDefaults is used to determine whether default values
     * should be used for annotation values. Finding defaults requires
     * more computation, so should be false when no defaulting is needed.
     *
     * @param anno the annotation to disassemble
     * @param name the name of the attribute to access
     * @param expectedType the expected type used to cast the return type
     * @param useDefaults whether to apply default values to the attribute.
     * @return the value of the attribute with the given name
     */
public static <T> List<T> getElementValueArray(AnnotationMirror anno, CharSequence name, Class<T> expectedType, boolean useDefaults) {
    @SuppressWarnings("unchecked") List<AnnotationValue> la = getElementValue(anno, name, List.class, useDefaults);
    List<T> result = new ArrayList<T>(la.size());
    for (AnnotationValue a : la) {
        result.add(expectedType.cast(a.getValue()));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) AnnotationValue(javax.lang.model.element.AnnotationValue)

Example 5 with AnnotationValue

use of javax.lang.model.element.AnnotationValue in project tiger by google.

the class Utils method findAllModulesRecursively.

@SuppressWarnings("unchecked")
public static Set<TypeElement> findAllModulesRecursively(TypeElement inModule) {
    Set<TypeElement> result = new HashSet<>();
    result.add(inModule);
    for (AnnotationMirror annotationMirror : inModule.getAnnotationMirrors()) {
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
            ExecutableElement key = entry.getKey();
            /** Checks for {@link Module.includes}. */
            if (key.getSimpleName().contentEquals("includes")) {
                for (AnnotationValue annotationValue : (List<AnnotationValue>) entry.getValue().getValue()) {
                    TypeElement childModule = (TypeElement) ((DeclaredType) annotationValue.getValue()).asElement();
                    result.addAll(findAllModulesRecursively(childModule));
                }
            }
        }
    }
    return result;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) AnnotationValue(javax.lang.model.element.AnnotationValue) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) IntoMap(dagger.multibindings.IntoMap) HashSet(java.util.HashSet)

Aggregations

AnnotationValue (javax.lang.model.element.AnnotationValue)160 AnnotationMirror (javax.lang.model.element.AnnotationMirror)69 TypeElement (javax.lang.model.element.TypeElement)56 ArrayList (java.util.ArrayList)43 ExecutableElement (javax.lang.model.element.ExecutableElement)41 List (java.util.List)40 TypeMirror (javax.lang.model.type.TypeMirror)37 Test (org.junit.Test)30 DeclaredType (javax.lang.model.type.DeclaredType)23 HashSet (java.util.HashSet)18 Map (java.util.Map)18 HashMap (java.util.HashMap)15 VariableElement (javax.lang.model.element.VariableElement)12 Element (javax.lang.model.element.Element)11 Component (dagger.Component)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 Nullable (javax.annotation.Nullable)6 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)5 ImmutableList (com.google.common.collect.ImmutableList)4 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)4