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

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

Introduction

In this page you can find the example usage for javax.lang.model.element Element 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:Main.java

public static boolean hasNullableAnnotation(Element columnElement) {
    for (AnnotationMirror annotationMirror : columnElement.getAnnotationMirrors()) {
        final String name = annotationMirror.getAnnotationType().asElement().getSimpleName().toString();
        if ("Nullable".equals(name)) {
            return true;
        }//www.  j  av  a 2  s  . com
    }
    return false;
}

From source file:Main.java

public static boolean hasNotNullAnnotation(Element columnElement) {
    for (AnnotationMirror annotationMirror : columnElement.getAnnotationMirrors()) {
        final String name = annotationMirror.getAnnotationType().asElement().getSimpleName().toString();
        if ("NonNull".equals(name) || "NotNull".equals(name)) {
            return true;
        }/*from  w  w w .  j a v a2s . c o m*/
    }
    return false;
}

From source file:cop.raml.processor.RestProcessor.java

private static AnnotationMirror getAnnotationMirror(@NotNull Element element, String className) {
    List<? extends AnnotationMirror> mirrors = element.getAnnotationMirrors();

    if (CollectionUtils.isEmpty(mirrors) || StringUtils.isBlank(className))
        return null;

    for (AnnotationMirror mirror : mirrors)
        if (className.equals(mirror.getAnnotationType().toString()))
            return mirror;

    return null;/*from  w  w w . j  av a 2 s.com*/
}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.RequestAttributeResolver.java

public Set<String> resolve(String filter) {
    Set<String> ret = new LinkedHashSet<>();
    // only display results if filter contains @
    if (!StringUtils.contains(text, "@") || !StringUtils.contains(text, "data-sly-use")) {
        return ret;
    }//w ww .  j a va 2s  . c  o  m
    ElementUtilities.ElementAcceptor acceptor = new ElementUtilities.ElementAcceptor() {
        @Override
        public boolean accept(Element e, TypeMirror type) {
            // we are looking for the annotations
            for (AnnotationMirror mirror : e.getAnnotationMirrors()) {
                if (mirror.getAnnotationType() != null && mirror.getAnnotationType().asElement() != null
                        && StringUtils.equalsIgnoreCase(REQUEST_ATTRIBUTE_CLASSNAME,
                                mirror.getAnnotationType().asElement().toString())) {
                    return true;
                }
            }
            return false;
        }
    };
    String clazz = StringUtils.substringBetween(text, "'");

    Set<Element> elems = getMembersFromJavaSource(clazz, acceptor);
    for (Element elem : elems) {
        if (StringUtils.startsWithIgnoreCase(elem.getSimpleName().toString(), filter)
                && !StringUtils.contains(text, elem.getSimpleName().toString() + " ")
                && !StringUtils.contains(text, elem.getSimpleName().toString() + "=")) {
            ret.add(elem.getSimpleName().toString());
        }
    }
    if (ret.isEmpty()) {
        for (String att : getAttributesFromClassLoader(clazz)) {
            if (StringUtils.startsWithIgnoreCase(att, filter) && !StringUtils.contains(text, att + " ")
                    && !StringUtils.contains(text, att + "=")) {
                ret.add(att);
            }
        }
    }
    return ret;
}

From source file:com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessor.java

private void processElement(Element element) {
    for (AnnotationMirror annotation : element.getAnnotationMirrors()) {
        Element annotationTypeElement = annotation.getAnnotationType().asElement();

        if (annotationTypeElement.equals(this.configurationTypeElement)) {
            List<? extends Element> enclosedElements = element.getEnclosedElements();
            processClass(element, ElementFilter.constructorsIn(enclosedElements));

        } else if (annotationTypeElement.equals(this.beanTypeElement)) {
            processBeanMethod((ExecutableElement) element);
        }/*from ww w.  j  a v  a2s  .c  o m*/
    }
}

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   w w  w  . ja  v  a2s.  co m*/

            return null;

        }
    }

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

From source file:com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessor.java

private boolean isInConfigurationClass(ExecutableElement methodElement) {
    Element enclosingElement = methodElement.getEnclosingElement();

    List<? extends AnnotationMirror> annotationMirrors = enclosingElement.getAnnotationMirrors();
    for (AnnotationMirror annotationMirror : annotationMirrors) {
        DeclaredType annotationType = annotationMirror.getAnnotationType();

        if (this.configurationTypeElement.equals(annotationType.asElement())) {
            return true;
        }//from w  w w.  jav  a  2s .c o  m
    }

    return false;
}

From source file:com.spotify.docgenerator.JacksonJerseyAnnotationProcessor.java

/**
 * Find the request method annotation the method was annotated with and return a string
 * representing the request method./*  w  w w.ja  va2 s  . co  m*/
 */
private String computeRequestMethod(Element e) {
    for (AnnotationMirror am : e.getAnnotationMirrors()) {
        final String typeString = am.getAnnotationType().toString();
        if (typeString.endsWith(".GET")) {
            return "GET";
        } else if (typeString.endsWith(".PUT")) {
            return "PUT";
        } else if (typeString.endsWith(".POST")) {
            return "POST";
        } else if (typeString.endsWith(".PATCH")) {
            return "PATCH";
        } else if (typeString.endsWith(".DELETE")) {
            return "DELETE";
        }
    }

    return null;
}

From source file:com.predic8.membrane.annot.SpringConfigurationXSDGeneratingAnnotationProcessor.java

private boolean isRequired(Element e2) {
    for (AnnotationMirror am : e2.getAnnotationMirrors())
        if (((TypeElement) am.getAnnotationType().asElement()).getQualifiedName().toString().equals(REQUIRED))
            return true;
    return false;
}

From source file:org.androidtransfuse.adapter.element.ASTElementFactory.java

private ImmutableSet<ASTAnnotation> getAnnotations(Element element) {
    ImmutableSet.Builder<ASTAnnotation> annotationBuilder = ImmutableSet.builder();

    for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
        ASTType type = annotationMirror.getAnnotationType().accept(astTypeBuilderVisitor, null);

        annotationBuilder.add(astFactory.buildASTElementAnnotation(annotationMirror, type));
    }/* ww w .  j  av a 2  s.c om*/

    return annotationBuilder.build();
}