Example usage for javax.lang.model.element AnnotationMirror getAnnotationType

List of usage examples for javax.lang.model.element AnnotationMirror getAnnotationType

Introduction

In this page you can find the example usage for javax.lang.model.element AnnotationMirror getAnnotationType.

Prototype

DeclaredType getAnnotationType();

Source Link

Document

Returns the type of this annotation.

Usage

From source file:Main.java

/** Returns true if the given annotation has a @Inherited meta-annotation. */
public static boolean hasInheritedMeta(AnnotationMirror anno) {
    return anno.getAnnotationType().asElement().getAnnotation(Inherited.class) != null;
}

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;
        }/*from   ww w .  j a  v a 2 s .  co m*/
    }
    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;
        }//  w  w  w  . j a  va2 s .  c o  m
    }
    return false;
}

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

public static boolean isOptional(final AnnotationMirror annotationMirror) {
    final boolean relevantAnnotation = Arrays.stream(VariableAnnotations.values())
            .map(it -> annotationMirror.getAnnotationType().toString().startsWith(it.annotation))
            .reduce((a, b) -> a || b).orElse(false);

    final boolean optional;
    if (relevantAnnotation) {
        final String required = annotationMirror.getElementValues().entrySet().stream()
                .filter(e -> e.getKey().toString().equals("required()")).map(e -> e.getValue().toString())
                .findFirst().orElse("true");
        optional = !Boolean.valueOf(required);
    } else {/*w  ww .  j a v  a  2  s .co m*/
        optional = false;
    }

    return optional;
}

From source file:org.netbeans.jcode.rest.util.RestUtils.java

public static String findUri(JavaSource rSrc) {
    String path = null;/*from w  w  w  . j  a v  a 2 s.  c  o m*/
    List<? extends AnnotationMirror> annotations = JavaSourceHelper.getClassAnnotations(rSrc);
    for (AnnotationMirror annotation : annotations) {
        String cAnonType = annotation.getAnnotationType().toString();
        if (RestConstants.PATH.equals(cAnonType)) {
            path = getValueFromAnnotation(annotation);
        }
    }
    return path;
}

From source file:org.netbeans.jcode.rest.util.RestUtils.java

public static boolean isStaticResource(JavaSource src) {
    List<? extends AnnotationMirror> annotations = JavaSourceHelper.getClassAnnotations(src);
    if (annotations != null && annotations.size() > 0) {
        for (AnnotationMirror annotation : annotations) {
            String classAnonType = annotation.getAnnotationType().toString();
            if (RestConstants.PATH.equals(classAnonType)) {
                return true;
            }/*from   w  ww .  j av a 2s. 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  .c  om
}

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);/*w  w  w.ja v  a 2s.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: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 w  w. j  a v a2  s  .c  om
    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.jazoon2012.JazoonProcessor.java

private void processElement(TypeElement typeElement) {
    for (AnnotationMirror annotation : typeElement.getAnnotationMirrors()) {
        Element annotationTypeElement = annotation.getAnnotationType().asElement();
        if (annotationTypeElement.equals(this.configurationTypeElement)) {
            List<? extends Element> enclosedElements = typeElement.getEnclosedElements();

            processClass(typeElement, ElementFilter.constructorsIn(enclosedElements));

            for (ExecutableElement method : ElementFilter.methodsIn(enclosedElements)) {
                processMethod(typeElement, method);
            }//  w w  w.j ava 2 s . c om
        }
    }

}