Search in sources :

Example 26 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 27 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 28 with AnnotationValue

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

the class AndroidObservableExtension method addToSetter.

@Override
public void addToSetter(AttributeDescriptor member, MethodSpec.Builder builder) {
    if (!observable || !isBindable(member)) {
        return;
    }
    Elements elements = processingEnvironment.getElementUtils();
    // data binding compiler will create a useful set of classes in /data-binding-info
    String bindingInfo = BINDING_PACKAGE + ".layouts.DataBindingInfo";
    TypeElement dataBindingType = elements.getTypeElement(bindingInfo);
    ClassName BRclass = null;
    if (dataBindingType != null) {
        Optional<String> modulePackage = Mirrors.findAnnotationMirror(dataBindingType, BINDING_PACKAGE + ".BindingBuildInfo").map(mirror -> Mirrors.findAnnotationValue(mirror, "modulePackage")).filter(Optional::isPresent).map(Optional::get).map(AnnotationValue::toString);
        if (modulePackage.isPresent()) {
            // not actually checking the BR class exists since it maybe generated later
            BRclass = ClassName.get(modulePackage.get().replaceAll("\"", ""), "BR");
        }
    }
    if (BRclass == null) {
        PackageElement packageElement = elements.getPackageOf(entity.element());
        String packageName = packageElement.getQualifiedName().toString();
        BRclass = ClassName.get(packageName, "BR");
    }
    // matching the way the BR property names are generated
    // https://code.google.com/p/android/issues/detail?id=199436
    String propertyName = member.setterName().replaceFirst("set", "");
    /*
        if (Names.isAllUpper(propertyName)) {
            propertyName = propertyName.toLowerCase();
        } else {
            propertyName = Names.lowerCaseFirst(propertyName);
        }*/
    propertyName = Names.lowerCaseFirst(propertyName);
    builder.addStatement("notifyPropertyChanged($L.$L)", BRclass, propertyName);
}
Also used : Arrays(java.util.Arrays) PackageElement(javax.lang.model.element.PackageElement) MethodSpec(com.squareup.javapoet.MethodSpec) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) ClassName(com.squareup.javapoet.ClassName) Optional(java.util.Optional) AnnotationValue(javax.lang.model.element.AnnotationValue) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) TypeSpec(com.squareup.javapoet.TypeSpec) Elements(javax.lang.model.util.Elements) Optional(java.util.Optional) TypeElement(javax.lang.model.element.TypeElement) ClassName(com.squareup.javapoet.ClassName) AnnotationValue(javax.lang.model.element.AnnotationValue) PackageElement(javax.lang.model.element.PackageElement) Elements(javax.lang.model.util.Elements)

Example 29 with AnnotationValue

use of javax.lang.model.element.AnnotationValue in project stitch by bambootang.

the class StithBinderProcess method getAutoLink.

public Object getAutoLink(TypeElement foo) {
    AnnotationMirror am = getAnnotationMirror(foo, Exported.class);
    if (am == null) {
        return null;
    }
    AnnotationValue av = getAnnotationValue(am, "value");
    if (av == null) {
        return null;
    } else {
        return av.getValue();
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationValue(javax.lang.model.element.AnnotationValue)

Example 30 with AnnotationValue

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

the class AnnotationHelper method extractAnnotationClassArrayParameter.

public List<DeclaredType> extractAnnotationClassArrayParameter(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();
            @SuppressWarnings("unchecked") List<AnnotationValue> annotationClassArray = (List<AnnotationValue>) annotationValue.getValue();
            List<DeclaredType> result = new ArrayList<>(annotationClassArray.size());
            for (AnnotationValue annotationClassValue : annotationClassArray) {
                result.add((DeclaredType) annotationClassValue.getValue());
            }
            return result;
        }
    }
    return null;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ArrayList(java.util.ArrayList) AnnotationValue(javax.lang.model.element.AnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

AnnotationValue (javax.lang.model.element.AnnotationValue)43 AnnotationMirror (javax.lang.model.element.AnnotationMirror)23 TypeElement (javax.lang.model.element.TypeElement)20 List (java.util.List)16 ArrayList (java.util.ArrayList)13 ExecutableElement (javax.lang.model.element.ExecutableElement)12 TypeMirror (javax.lang.model.type.TypeMirror)11 HashSet (java.util.HashSet)8 Map (java.util.Map)8 DeclaredType (javax.lang.model.type.DeclaredType)8 ImmutableMap (com.google.common.collect.ImmutableMap)3 Element (javax.lang.model.element.Element)3 ImmutableList (com.google.common.collect.ImmutableList)2 ClassName (com.squareup.javapoet.ClassName)2 MethodSpec (com.squareup.javapoet.MethodSpec)2 TypeSpec (com.squareup.javapoet.TypeSpec)2 HashMap (java.util.HashMap)2 MoreElements.getAnnotationMirror (com.google.auto.common.MoreElements.getAnnotationMirror)1 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1