Package com.google.auto.common
Class AnnotationMirrors
java.lang.Object
com.google.auto.common.AnnotationMirrors
A utility class for working with
AnnotationMirror
instances.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.google.common.base.Equivalence<AnnotationMirror>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.common.base.Equivalence<AnnotationMirror>
Returns anEquivalence
forAnnotationMirror
as some implementations delegate equality tests toObject.equals(java.lang.Object)
whereas the documentation explicitly states that instance/reference equality is not the proper test.static com.google.common.collect.ImmutableSet<? extends AnnotationMirror>
getAnnotatedAnnotations
(Element element, Class<? extends Annotation> annotationType) Returns all annotations that are present on the givenElement
which are themselves annotated withannotationType
.getAnnotationElementAndValue
(AnnotationMirror annotationMirror, String elementName) Returns aExecutableElement
and its associatedAnnotationValue
if such an element was either declared in the usage represented by the providedAnnotationMirror
, or if such an element was defined with a default.static AnnotationValue
getAnnotationValue
(AnnotationMirror annotationMirror, String elementName) Returns anAnnotationValue
for the named element if such an element was either declared in the usage represented by the providedAnnotationMirror
, or if such an element was defined with a default.static com.google.common.collect.ImmutableMap<ExecutableElement,
AnnotationValue> getAnnotationValuesWithDefaults
(AnnotationMirror annotation) Returns theAnnotationMirror
's map ofAnnotationValue
indexed byExecutableElement
, supplying default values from the annotation if the annotation property has not been set.
-
Field Details
-
ANNOTATION_MIRROR_EQUIVALENCE
private static final com.google.common.base.Equivalence<AnnotationMirror> ANNOTATION_MIRROR_EQUIVALENCE
-
-
Constructor Details
-
AnnotationMirrors
private AnnotationMirrors()
-
-
Method Details
-
equivalence
Returns anEquivalence
forAnnotationMirror
as some implementations delegate equality tests toObject.equals(java.lang.Object)
whereas the documentation explicitly states that instance/reference equality is not the proper test. -
getAnnotationValuesWithDefaults
public static com.google.common.collect.ImmutableMap<ExecutableElement,AnnotationValue> getAnnotationValuesWithDefaults(AnnotationMirror annotation) Returns theAnnotationMirror
's map ofAnnotationValue
indexed byExecutableElement
, supplying default values from the annotation if the annotation property has not been set. This is equivalent toElements.getElementValuesWithDefaults(AnnotationMirror)
but can be called statically without anElements
instance.The iteration order of elements of the returned map will be the order in which the
ExecutableElement
s are defined inannotation
's type. -
getAnnotationValue
public static AnnotationValue getAnnotationValue(AnnotationMirror annotationMirror, String elementName) Returns anAnnotationValue
for the named element if such an element was either declared in the usage represented by the providedAnnotationMirror
, or if such an element was defined with a default.- Throws:
IllegalArgumentException
- if no element is defined with the given elementName.
-
getAnnotationElementAndValue
public static Map.Entry<ExecutableElement,AnnotationValue> getAnnotationElementAndValue(AnnotationMirror annotationMirror, String elementName) Returns aExecutableElement
and its associatedAnnotationValue
if such an element was either declared in the usage represented by the providedAnnotationMirror
, or if such an element was defined with a default.- Throws:
IllegalArgumentException
- if no element is defined with the given elementName.
-
getAnnotatedAnnotations
public static com.google.common.collect.ImmutableSet<? extends AnnotationMirror> getAnnotatedAnnotations(Element element, Class<? extends Annotation> annotationType) Returns all annotations that are present on the givenElement
which are themselves annotated withannotationType
.
-