Example usage for javax.lang.model.element VariableElement getAnnotationMirrors

List of usage examples for javax.lang.model.element VariableElement getAnnotationMirrors

Introduction

In this page you can find the example usage for javax.lang.model.element VariableElement getAnnotationMirrors.

Prototype

@Override
List<? extends AnnotationMirror> getAnnotationMirrors();

Source Link

Document

To get inherited annotations as well, use Elements#getAllAnnotationMirrors(Element) getAllAnnotationMirrors .

Usage

From source file:org.leandreck.endpoints.processor.model.VariableAnnotations.java

public static boolean isOptionalByAnnotation(final VariableElement variableElement) {
    return variableElement.getAnnotationMirrors().stream().map(VariableAnnotations::isOptional)
            .reduce((r, r2) -> (r || r2)).orElse(false);
}

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

public static String getIdFieldName(JavaSource source) {
    final String[] fieldName = new String[1];

    try {/*www .jav  a 2  s.c  om*/
        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<VariableElement> fields = ElementFilter.fieldsIn(classElement.getEnclosedElements());

                for (VariableElement field : fields) {
                    List<? extends AnnotationMirror> annotations = field.getAnnotationMirrors();

                    for (AnnotationMirror annotation : annotations) {
                        if (annotation.toString().equals("@javax.persistence.Id")) {
                            //NOI18N
                            fieldName[0] = field.getSimpleName().toString();
                            return;
                        }
                    }
                }
            }
        }, true);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

    return fieldName[0];
}

From source file:org.ez18n.apt.processor.LabelBundleProcessor.java

private void processLabels(TypeElement resourcesType, List<LabelTemplateMethod> methods) {
    for (Element element : resourcesType.getEnclosedElements()) {
        if (element.getKind() != ElementKind.METHOD) {
            continue;
        }// ww w  . j  a v a 2 s .  c om
        final ExecutableElement method = (ExecutableElement) element;
        Message labelAnnotation = element.getAnnotation(Message.class);
        final TemplateParam returnType = new TemplateParam(method.getReturnType().toString());
        final boolean deprecated = method.getAnnotation(Deprecated.class) != null;
        final LabelTemplateMethod labelMethod;
        try {
            labelMethod = new LabelTemplateMethod(method.getSimpleName().toString(), deprecated, returnType,
                    labelAnnotation.value(), labelAnnotation.mobile());
        } catch (Throwable t) {
            processingEnv.getMessager().printMessage(Kind.WARNING, t.getMessage(), resourcesType);
            continue;
        }

        for (VariableElement variable : method.getParameters()) {
            final String paramName = variable.getSimpleName().toString();
            final String paramType = variable.asType().toString();

            List<TemplateAnnotation> annotations = new ArrayList<TemplateAnnotation>();
            for (AnnotationMirror annotationMirrors : variable.getAnnotationMirrors()) {
                annotations.add(new TemplateAnnotation(annotationMirrors.getAnnotationType().toString()));
            }

            labelMethod.getParams().add(new TemplateParam(paramType, paramName, annotations));
        }
        methods.add(labelMethod);
    }
}