Example usage for javax.lang.model.element AnnotationValue getValue

List of usage examples for javax.lang.model.element AnnotationValue getValue

Introduction

In this page you can find the example usage for javax.lang.model.element AnnotationValue getValue.

Prototype

Object getValue();

Source Link

Document

Returns the value.

Usage

From source file:com.airbnb.deeplinkdispatch.DeepLinkProcessor.java

private static List<String> enumerateCustomDeepLinks(Element element, Map<Element, String[]> prefixesMap) {
    Set<? extends AnnotationMirror> annotationMirrors = AnnotationMirrors.getAnnotatedAnnotations(element,
            DEEP_LINK_SPEC_CLASS);/*from   w w  w  . j  a  v  a  2  s. c  o  m*/
    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;
}

From source file:com.github.hexocraftapi.checkargs.processor.AnnotatedClass.java

/**
 * @param classElement TypeElement// w  w w. ja  va2  s .  com
 * @param elementUtils TypeElement
 * @throws ClassNotFoundException ClassNotFoundException
 */
public AnnotatedClass(TypeElement classElement, Elements elementUtils) throws ClassNotFoundException {
    this.annotatedClassElement = classElement;

    CheckArgs annotation = classElement.getAnnotation(CheckArgs.class);
    List<? extends AnnotationMirror> annotationMirrors = elementUtils.getAllAnnotationMirrors(classElement);

    for (AnnotationMirror annotationMirror : annotationMirrors) {
        Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror
                .getElementValues();

        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues
                .entrySet()) {
            String key = entry.getKey().getSimpleName().toString();
            Object value = entry.getValue().getValue();

            switch (key) {
            case "count":
                this.count = (int) value;
                break;
            case "types":
                List<? extends AnnotationValue> typeMirrors = (List<? extends AnnotationValue>) value;
                for (AnnotationValue annotationValue : typeMirrors) {
                    String clazz = annotationValue.getValue().toString();
                    this.qualifiedClassName.add(clazz);
                    this.simpleClassName.add(clazz.substring(clazz.lastIndexOf(".") + 1));
                }
                break;
            }
        }
    }

    if (this.qualifiedClassName.size() > 0 && this.count != this.qualifiedClassName.size())
        this.count = this.qualifiedClassName.size();
}

From source file:com.wesleyhome.dao.processor.ParameterInfoListProcessor.java

/**
 * @param annotationParamList/*from w ww .  j  a  v a  2s  .  co m*/
 * @param annotationHelper
 * @return
 */
private List<ParamInfo> getParameterListInfo(final List<AnnotationValue> annotationParamList,
        final AnnotationHelper annotationHelper) {
    List<ParamInfo> list = new ArrayList<>();
    for (AnnotationValue annotationParam : annotationParamList) {
        AnnotationMirror paramMirror = (AnnotationMirror) annotationParam.getValue();
        list.add(getMethodParam(paramMirror, annotationHelper));
    }
    return list;
}

From source file:com.wesleyhome.dao.processor.ParameterInfoListProcessor.java

/**
 * @param paramMirror//from  w  ww  . j a v a2s.c o  m
 * @param annotationHelper
 * @return
 */
private ParamInfo getMethodParam(final AnnotationMirror paramMirror, final AnnotationHelper annotationHelper) {
    AnnotationValue value = annotationHelper.getAnnotationValue(paramMirror, "paramClass");
    String parameterClassName = value == null ? Void.class.getName() : value.getValue().toString();
    String parameterName = (String) annotationHelper.getAnnotationValue(paramMirror, "paramName").getValue();
    AnnotationValue isCollectionValue = annotationHelper.getAnnotationValue(paramMirror, "isCollection");
    Boolean isCollection = isCollectionValue == null ? Boolean.FALSE : (Boolean) isCollectionValue.getValue();
    List<String> parameterClassVarList = getParameterClassList(paramMirror, "paramClassVars", annotationHelper);
    String paramClassTypeVar = (String) annotationHelper.getRealAnnotationValue(paramMirror,
            "paramClassTypeVar");
    return new ParamInfo(parameterClassName, parameterName, BooleanUtils.isTrue(isCollection),
            parameterClassVarList, paramClassTypeVar);
}

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static boolean annotationHasAttributeValue(AnnotationMirror am, String value) {
    if (am != null) {
        for (AnnotationValue av : am.getElementValues().values()) {
            if (value.equals(av.getValue())) {
                return true;
            }//from  www.j a v  a2s.co  m
        }
    }
    return false;
}

From source file:org.netbeans.jcode.core.util.JavaSourceHelper.java

public static Collection<String> getAnnotationValuesForAllMethods(JavaSource source, final String annotation) {
    final Collection<String> results = new HashSet<String>();
    try {//  w  w  w.  j ava 2s  .  co m
        source.runUserActionTask(new AbstractTask<CompilationController>() {

            public void run(CompilationController controller) throws IOException {
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
                TypeElement classElement = getTopLevelClassElement(controller);
                if (classElement == null) {
                    return;
                }
                List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements());

                for (ExecutableElement method : methods) {
                    for (AnnotationMirror mirror : method.getAnnotationMirrors()) {
                        if (((TypeElement) mirror.getAnnotationType().asElement()).getQualifiedName()
                                .contentEquals(annotation)) {
                            for (AnnotationValue value : mirror.getElementValues().values()) {
                                results.add(value.getValue().toString());
                            }
                        }
                    }
                }
            }
        }, true);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

    return results;
}

From source file:org.jsweet.transpiler.JSweetContext.java

/**
 * Gets the first value of the 'value' property.
 *///from w  w  w  .j  ava  2  s .  c om
private static Object getFirstAnnotationValue(AnnotationMirror annotation, Object defaultValue) {
    for (AnnotationValue value : annotation.getElementValues().values()) {
        return value.getValue();
    }
    return defaultValue;
}

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static Collection<String> getAnnotationValuesForAllMethods(JavaSource source, final String annotation) {
    final Collection<String> results = new HashSet<>();
    try {/*from  w w w  . java 2s  .  c  o  m*/
        source.runUserActionTask(new AbstractTask<CompilationController>() {

            public void run(CompilationController controller) throws IOException {
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
                TypeElement classElement = getTopLevelClassElement(controller);
                if (classElement == null) {
                    return;
                }
                List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements());

                for (ExecutableElement method : methods) {
                    for (AnnotationMirror mirror : method.getAnnotationMirrors()) {
                        if (((TypeElement) mirror.getAnnotationType().asElement()).getQualifiedName()
                                .contentEquals(annotation)) {
                            for (AnnotationValue value : mirror.getElementValues().values()) {
                                results.add(value.getValue().toString());
                            }
                        }
                    }
                }
            }
        }, true);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

    return results;
}

From source file:org.jdto.tools.AnnotationConfigVerifier.java

private TypeElement extractTargetType(Element element, TypeElement annotationElement, Messager messager) {

    List<? extends AnnotationMirror> am = element.getAnnotationMirrors();

    for (AnnotationMirror annotationMirror : am) {
        if (annotationMirror.getAnnotationType().equals(annotationElement.asType())) {

            //the annotation has only one argument so is easy to extract the value
            Map<? extends ExecutableElement, ? extends AnnotationValue> map = processingEnv.getElementUtils()
                    .getElementValuesWithDefaults(annotationMirror);

            //iterate and return the first value.
            for (ExecutableElement executableElement : map.keySet()) {

                AnnotationValue val = map.get(executableElement);

                String type = val.getValue().toString();

                return super.processingEnv.getElementUtils().getTypeElement(type);
            }//from  www.  j a  v  a 2  s  . c  o m

            return null;

        }
    }

    messager.printMessage(Diagnostic.Kind.ERROR, "Could not find target class on element", element);
    return null;
}

From source file:org.boundbox.processor.BoundBoxProcessor.java

private String getAnnotationValueAsString(AnnotationValue annotationValue) {
    return (String) annotationValue.getValue();
}