Top Description Fields Constructors Methods
com.google.auto.common

public final Class AnnotationMirrors

extends Object
Class Inheritance
Static Imports
com.google.auto.common.MoreElements.isAnnotationPresent, .MoreStreams.toImmutableSet, com.google.common.base.Preconditions.checkNotNull, java.util.Collections.unmodifiableMap

A utility class for working with AnnotationMirror instances.
Author
Gregory Kick

Field Summary

Modifier and TypeField and Description
private static final Equivalence<AnnotationMirror>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Equivalence<AnnotationMirror>
equivalence()

Returns an Equivalence for AnnotationMirror as some implementations delegate equality tests to Object#equals whereas the documentation explicitly states that instance/reference equality is not the proper test.

public static ImmutableSet<? extends AnnotationMirror>
getAnnotatedAnnotations(Element element, Class<? extends Annotation> annotationClass)

Returns all annotations that are present on the given Element which are themselves annotated with annotationClass.

public static ImmutableSet<? extends AnnotationMirror>
getAnnotatedAnnotations(Element element, TypeElement annotation)

Returns all annotations that are present on the given Element which are themselves annotated with annotation.

public static ImmutableSet<? extends AnnotationMirror>
getAnnotatedAnnotations(Element element, String annotationName)

Returns all annotations that are present on the given Element which are themselves annotated with an annotation whose type's canonical name is annotationName.

public static Map.Entry<ExecutableElement, AnnotationValue>
getAnnotationElementAndValue(AnnotationMirror annotationMirror, final String elementName)

Returns a ExecutableElement and its associated AnnotationValue if such an element was either declared in the usage represented by the provided AnnotationMirror, or if such an element was defined with a default.

public static AnnotationValue
getAnnotationValue(AnnotationMirror annotationMirror, String elementName)

Returns an AnnotationValue for the named element if such an element was either declared in the usage represented by the provided AnnotationMirror, or if such an element was defined with a default.

public static ImmutableMap<ExecutableElement, AnnotationValue>
getAnnotationValuesWithDefaults(AnnotationMirror annotation)

Returns the AnnotationMirror's map of AnnotationValue indexed by ExecutableElement, supplying default values from the annotation if the annotation property has not been set.

public static String
toString(AnnotationMirror annotationMirror)

Returns a string representation of the given annotation mirror, suitable for inclusion in a Java source file to reproduce the annotation in source form.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANNOTATION_MIRROR_EQUIVALENCEback to summary
private static final Equivalence<AnnotationMirror> ANNOTATION_MIRROR_EQUIVALENCE

Constructor Detail

AnnotationMirrorsback to summary
private AnnotationMirrors()

Method Detail

equivalenceback to summary
public static Equivalence<AnnotationMirror> equivalence()

Returns an Equivalence for AnnotationMirror as some implementations delegate equality tests to Object#equals whereas the documentation explicitly states that instance/reference equality is not the proper test.

getAnnotatedAnnotationsback to summary
public static ImmutableSet<? extends AnnotationMirror> getAnnotatedAnnotations(Element element, Class<? extends Annotation> annotationClass)

Returns all annotations that are present on the given Element which are themselves annotated with annotationClass.

getAnnotatedAnnotationsback to summary
public static ImmutableSet<? extends AnnotationMirror> getAnnotatedAnnotations(Element element, TypeElement annotation)

Returns all annotations that are present on the given Element which are themselves annotated with annotation.

getAnnotatedAnnotationsback to summary
public static ImmutableSet<? extends AnnotationMirror> getAnnotatedAnnotations(Element element, String annotationName)

Returns all annotations that are present on the given Element which are themselves annotated with an annotation whose type's canonical name is annotationName.

getAnnotationElementAndValueback to summary
public static Map.Entry<ExecutableElement, AnnotationValue> getAnnotationElementAndValue(AnnotationMirror annotationMirror, final String elementName)

Returns a ExecutableElement and its associated AnnotationValue if such an element was either declared in the usage represented by the provided AnnotationMirror, or if such an element was defined with a default.

Exceptions
IllegalArgumentException:
if no element is defined with the given elementName.
getAnnotationValueback to summary
public static AnnotationValue getAnnotationValue(AnnotationMirror annotationMirror, String elementName)

Returns an AnnotationValue for the named element if such an element was either declared in the usage represented by the provided AnnotationMirror, or if such an element was defined with a default.

Exceptions
IllegalArgumentException:
if no element is defined with the given elementName.
getAnnotationValuesWithDefaultsback to summary
public static ImmutableMap<ExecutableElement, AnnotationValue> getAnnotationValuesWithDefaults(AnnotationMirror annotation)

Returns the AnnotationMirror's map of AnnotationValue indexed by ExecutableElement, supplying default values from the annotation if the annotation property has not been set. This is equivalent to Elements#getElementValuesWithDefaults(AnnotationMirror) but can be called statically without an Elements instance.

The iteration order of elements of the returned map will be the order in which the ExecutableElements are defined in annotation's type.

toStringback to summary
public static String toString(AnnotationMirror annotationMirror)

Returns a string representation of the given annotation mirror, suitable for inclusion in a Java source file to reproduce the annotation in source form.

Fully qualified names are used for types in annotations, class literals, and enum constants, ensuring that the source form will compile without requiring additional imports.