@Override public String apply(AnnotationMirror input) { return input.getAnnotationType().asElement().toString(); } })
private static boolean hasAnnotationWithName(Element element, String simpleName) { for (AnnotationMirror mirror : element.getAnnotationMirrors()) { String annotationName = mirror.getAnnotationType().asElement().getSimpleName().toString(); if (simpleName.equals(annotationName)) { return true; } } return false; }
private static @Nullable AnnotationMirror getMirror(Element element, Class<? extends Annotation> annotation) { for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { if (annotationMirror.getAnnotationType().toString().equals(annotation.getCanonicalName())) { return annotationMirror; } } return null; }
public AnnotationMirror getAnnotationMirror() { List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { TypeElement annotationElement = (TypeElement) annotationMirror.getAnnotationType().asElement(); if (annotationElement.getQualifiedName().toString().equals(annotationName)) { return annotationMirror; } } return null; }
public static MetaAnnotated from(AnnotationMirror mirror, Environment environment) { TypeElement element = (TypeElement) mirror.getAnnotationType().asElement(); String name = element.getQualifiedName().toString(); @Nullable MetaAnnotated metaAnnotated = cache.get(name); if (metaAnnotated == null) { metaAnnotated = ImmutableProto.MetaAnnotated.of(element, name, environment); @Nullable MetaAnnotated existing = cache.putIfAbsent(name, metaAnnotated); if (existing != null) { metaAnnotated = existing; } } return metaAnnotated; } }
/** * Check for the presence of an annotation with a specific simple name directly on this symbol. * Does *not* consider annotation inheritance. * * @param sym the symbol to check for the presence of the annotation * @param simpleName the simple name of the annotation to look for, e.g. "Nullable" or * "CheckReturnValue" */ public static boolean hasDirectAnnotationWithSimpleName(Symbol sym, String simpleName) { for (AnnotationMirror annotation : sym.getAnnotationMirrors()) { if (annotation.getAnnotationType().asElement().getSimpleName().contentEquals(simpleName)) { return true; } } return false; }
/** * Retrieves the attribute value from the annotation and assumes it's an array {@link Class classes}. * * @param element the element the annotation is on * @param annotation the annotation to get the value from * @param attributeName the name of the attribute to retrieve the class value array for * * @return a list of {@link TypeMirror} representing the value for the annotation attribute or an empty list */ public static List<TypeMirror> getClassArrayAnnotationValue(final Element element, final Class<? extends Annotation> annotation, @SuppressWarnings("SameParameterValue") final String attributeName) { for (AnnotationMirror mirror : element.getAnnotationMirrors()) { final DeclaredType annotationType = mirror.getAnnotationType(); if (annotationType.toString().equals(annotation.getName())) { final Map<? extends ExecutableElement, ? extends AnnotationValue> map = mirror.getElementValues(); for (ExecutableElement key : map.keySet()) { if (key.getSimpleName().contentEquals(attributeName)) { @SuppressWarnings("unchecked") final List<AnnotationValue> annotationValues = (List<AnnotationValue>) map.get(key).getValue(); final List<TypeMirror> result = new ArrayList<>(annotationValues.size()); for (AnnotationValue value : annotationValues) { result.add((TypeMirror) value.getValue()); } return result; } } } } return Collections.emptyList(); }
@Override public Void visitAnnotation(AnnotationMirror a, Void p) { builder.append('@').append(a.getAnnotationType()); Map<? extends ExecutableElement, ? extends AnnotationValue> values = a.getElementValues(); if (!values.isEmpty()) { builder.append('('); boolean notFirst = false; for (Entry<? extends ExecutableElement, ? extends AnnotationValue> e : values.entrySet()) { if (notFirst) { builder.append(", "); } notFirst = true; Name name = e.getKey().getSimpleName(); boolean onlyValue = values.size() == 1 && name.contentEquals(ATTRIBUTE_VALUE); if (!onlyValue) { builder.append(name).append(" = "); } printValue(e.getValue()); } builder.append(')'); } return null; }
@Nullable public static AnnotationMirror findAnnotation( List<? extends AnnotationMirror> annotationMirrors, String annotationTypeName) { for (AnnotationMirror annotation : annotationMirrors) { if (((TypeElement) annotation.getAnnotationType().asElement()) .getQualifiedName() .contentEquals(annotationTypeName)) { return annotation; } } return null; }
public AnnotationMirror findAnnotationMirror(Element annotatedElement, String annotationName) { List<? extends AnnotationMirror> annotationMirrors = annotatedElement.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { TypeElement annotationElement = (TypeElement) annotationMirror.getAnnotationType().asElement(); if (isAnnotation(annotationElement, annotationName)) { return annotationMirror; } } return null; }
|| !"org.openide.util.lookup.ServiceProvider".contentEquals(((TypeElement) annotation.getAnnotationType().asElement()).getQualifiedName())) { return Collections.emptyList(); TypeElement c = toProcess.remove(0); result.add(new TypeCompletion(c.getQualifiedName().toString() + ".class"));
private boolean isXmlAnnotation(AnnotationMirror mirror) { Name pkg = elements.getPackageOf(mirror.getAnnotationType().asElement()).getQualifiedName(); return pkg.contentEquals(JACKSON_XML_ANNOTATION_PACKAGE); }
private Element getCandidateAnnotationElement(Set<Element> seen, AnnotationMirror annotation) { Element element = annotation.getAnnotationType().asElement(); if (seen.contains(element)) { return null; } // We need to visit all indexed annotations. if (!isIndexedAnnotation(annotation)) { seen.add(element); } return (!element.toString().startsWith("java.lang") ? element : null); }
public boolean isAnnotatedWith(Element element, String qualifiedName) { for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { if (annotationMirror.getAnnotationType().toString().equals(qualifiedName)) { return true; } } return false; }
AnnotationValue value = null; if (e != null) { for (AnnotationMirror _mirror : e.getAnnotationMirrors()) { if (_mirror.getAnnotationType().toString().equals(NbBundle.Messages.class.getCanonicalName())) { mirror = _mirror; for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().contentEquals("value")) {
/** * Checks whether the given mirror represents the {@code Valid} annotation. * * @param annotationMirror The annotation mirror of interest. * * @return True, if the given mirror represents the {@code Valid} annotation, false * otherwise. */ private boolean isGraphValidationAnnotation( AnnotationMirror annotationMirror) { return getName( annotationMirror.getAnnotationType() ).contentEquals( BeanValidationTypes.VALID ); }
private void extractAnnotations(AnnotationElementsHolder extractedModel, Set<String> annotationTypesToCheck, TypeElement rootTypeElement, Element ancestorEnclosedElement) { List<? extends AnnotationMirror> ancestorEnclosedElementAnnotations = ancestorEnclosedElement.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : ancestorEnclosedElementAnnotations) { DeclaredType annotationType = annotationMirror.getAnnotationType(); if (annotationTypesToCheck.contains(annotationType.toString())) { TypeElement annotation = (TypeElement) annotationType.asElement(); /* * rootTypeElement is one of the types that are being compiled * * ancestorEnclosedElement is the annotated element in an ancestor of * rootTypeElement * * annotation is a type representing the annotation on ancestorEnclosedElement */ extractedModel.putAncestorAnnotatedElement(annotation.getQualifiedName().toString(), ancestorEnclosedElement, rootTypeElement); } } }
static Optional<? extends AnnotationMirror> findAnnotationMirror( Element element, String qualifiedName) { return element.getAnnotationMirrors().stream() .filter(mirror -> namesEqual((TypeElement) mirror.getAnnotationType().asElement(), qualifiedName)) .findFirst(); }
private Name getAnnotationQualifiedName(AnnotationMirror annotationMirror) { return ( (TypeElement) annotationMirror.getAnnotationType().asElement() ).getQualifiedName(); }
private static Set<TypeElement> nullablesIn(Iterable<? extends AnnotationMirror> annotations) { ImmutableSet.Builder<TypeElement> nullableAnnotations = ImmutableSet.builder(); for (AnnotationMirror mirror : annotations) { if (mirror.getElementValues().isEmpty()) { TypeElement type = (TypeElement) mirror.getAnnotationType().asElement(); if (type.getSimpleName().contentEquals("Nullable")) { nullableAnnotations.add(type); } } } return nullableAnnotations.build(); } }