Search in sources :

Example 86 with AnnotationValue

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

the class Tiger3ProcessorForPackaged method collectComponentToParentMapByModule.

/**
 * Return mappings by checking (sub)component -> module -> subcomponent.
 */
private Map<TypeElement, TypeElement> collectComponentToParentMapByModule(Set<TypeElement> components) {
    Map<TypeElement, TypeElement> result = new HashMap<>();
    for (TypeElement c : components) {
        for (TypeElement module : utils.findAllModulesOfComponentRecursively(c)) {
            AnnotationMirror annotationMirror = utils.getAnnotationMirror(module, Module.class);
            AnnotationValue subcomponentsAnnotationValue = Utils.getAnnotationValue(elements, annotationMirror, MODULE_ANNOTATION_ELEMENT_SUBCOMPONENTS);
            if (subcomponentsAnnotationValue == null) {
                continue;
            }
            for (AnnotationValue av : (List<AnnotationValue>) subcomponentsAnnotationValue.getValue()) {
                TypeElement subcomponent = (TypeElement) ((DeclaredType) av.getValue()).asElement();
                Preconditions.checkState(utils.isSubcomponent(subcomponent));
                result.put(subcomponent, c);
            }
        }
    }
    logger.n("result" + result);
    return result;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) HashMap(java.util.HashMap) TypeElement(javax.lang.model.element.TypeElement) AnnotationValue(javax.lang.model.element.AnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List)

Example 87 with AnnotationValue

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

the class TigerDaggerGeneratorProcessor method getModulesInComponents.

private void getModulesInComponents(Collection<? extends Element> components, SetMultimap<CoreInjectorInfo, TypeElement> scopeModules, Set<TypeElement> unscopedModules) {
    Set<TypeElement> modules = new HashSet<>();
    for (Element component : components) {
        AnnotationMirror componentAnnotationMirror = utils.isComponent(component) ? utils.getAnnotationMirror(component, Component.class) : utils.getAnnotationMirror(component, Subcomponent.class);
        AnnotationValue moduleAnnotationValue = Utils.getAnnotationValue(elements, componentAnnotationMirror, "modules");
        if (moduleAnnotationValue != null) {
            for (AnnotationValue annotationValue : (List<AnnotationValue>) moduleAnnotationValue.getValue()) {
                modules.add((TypeElement) ((DeclaredType) annotationValue.getValue()).asElement());
            }
        }
    }
    modules = utils.findAllModulesRecursively(modules, elements);
    for (TypeElement module : modules) {
        TypeElement scopeType = utils.getModuleScope((DeclaredType) module.asType(), scopeAliasCondenser);
        if (scopeType != null) {
            scopeModules.put(new CoreInjectorInfo(scopeType), module);
        } else {
            unscopedModules.add(module);
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) Subcomponent(dagger.Subcomponent) AnnotationValue(javax.lang.model.element.AnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List) Component(dagger.Component) HashSet(java.util.HashSet) DeclaredType(javax.lang.model.type.DeclaredType)

Example 88 with AnnotationValue

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

the class Tiger2Processor method findDirectModules.

private void findDirectModules(Set<TypeElement> modules, Element component) {
    AnnotationMirror componentAnnotationMirror = utils.isComponent(component) ? utils.getAnnotationMirror(component, Component.class) : utils.getAnnotationMirror(component, Subcomponent.class);
    AnnotationValue moduleAnnotationValue = Utils.getAnnotationValue(elements, componentAnnotationMirror, "modules");
    if (moduleAnnotationValue != null) {
        for (AnnotationValue annotationValue : (List<AnnotationValue>) moduleAnnotationValue.getValue()) {
            modules.add((TypeElement) ((DeclaredType) annotationValue.getValue()).asElement());
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) Subcomponent(dagger.Subcomponent) AnnotationValue(javax.lang.model.element.AnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List) Component(dagger.Component) DeclaredType(javax.lang.model.type.DeclaredType)

Example 89 with AnnotationValue

use of javax.lang.model.element.AnnotationValue in project dubbo by alibaba.

the class AnnotationUtils method getAttribute.

static <T> T getAttribute(Map<? extends ExecutableElement, ? extends AnnotationValue> attributesMap, String attributeName) {
    T annotationValue = null;
    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : attributesMap.entrySet()) {
        ExecutableElement attributeMethod = entry.getKey();
        if (Objects.equals(attributeName, attributeMethod.getSimpleName().toString())) {
            TypeMirror attributeType = attributeMethod.getReturnType();
            AnnotationValue value = entry.getValue();
            if (attributeType instanceof ArrayType) {
                // array-typed attribute values
                ArrayType arrayType = (ArrayType) attributeType;
                String componentType = arrayType.getComponentType().toString();
                ClassLoader classLoader = AnnotationUtils.class.getClassLoader();
                List<AnnotationValue> values = (List<AnnotationValue>) value.getValue();
                int size = values.size();
                try {
                    Class componentClass = classLoader.loadClass(componentType);
                    boolean isEnum = componentClass.isEnum();
                    Object array = Array.newInstance(componentClass, values.size());
                    for (int i = 0; i < size; i++) {
                        Object element = values.get(i).getValue();
                        if (isEnum) {
                            element = valueOf(componentClass, element.toString());
                        }
                        Array.set(array, i, element);
                    }
                    annotationValue = (T) array;
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                }
            } else {
                annotationValue = (T) value.getValue();
            }
            break;
        }
    }
    return annotationValue;
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayType(javax.lang.model.type.ArrayType) TypeMirror(javax.lang.model.type.TypeMirror) AnnotationValue(javax.lang.model.element.AnnotationValue) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Map(java.util.Map)

Example 90 with AnnotationValue

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

the class AnnotationHelper method extractAnnotationClassParameter.

public DeclaredType extractAnnotationClassParameter(Element element, String annotationName, String methodName) {
    AnnotationMirror annotationMirror = findAnnotationMirror(element, annotationName);
    Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues();
    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) {
        /*
			 * "methodName" is unset when the default value is used
			 */
        if (methodName.equals(entry.getKey().getSimpleName().toString())) {
            AnnotationValue annotationValue = entry.getValue();
            return (DeclaredType) annotationValue.getValue();
        }
    }
    return null;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationValue(javax.lang.model.element.AnnotationValue) Map(java.util.Map) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

AnnotationValue (javax.lang.model.element.AnnotationValue)182 AnnotationMirror (javax.lang.model.element.AnnotationMirror)81 TypeElement (javax.lang.model.element.TypeElement)62 ArrayList (java.util.ArrayList)54 ExecutableElement (javax.lang.model.element.ExecutableElement)53 TypeMirror (javax.lang.model.type.TypeMirror)48 List (java.util.List)45 Test (org.junit.Test)30 DeclaredType (javax.lang.model.type.DeclaredType)27 Map (java.util.Map)20 HashSet (java.util.HashSet)19 HashMap (java.util.HashMap)18 VariableElement (javax.lang.model.element.VariableElement)15 Element (javax.lang.model.element.Element)14 ElementUtils.getAnnotationValue (com.oracle.truffle.dsl.processor.java.ElementUtils.getAnnotationValue)10 ElementUtils.fromTypeMirror (com.oracle.truffle.dsl.processor.java.ElementUtils.fromTypeMirror)9 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)8 ElementUtils.resolveAnnotationValue (com.oracle.truffle.dsl.processor.java.ElementUtils.resolveAnnotationValue)7 ElementUtils.unboxAnnotationValue (com.oracle.truffle.dsl.processor.java.ElementUtils.unboxAnnotationValue)7 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)7