Package com.google.auto.common
Class AnnotationMirrors
- java.lang.Object
-
- com.google.auto.common.AnnotationMirrors
-
public final class AnnotationMirrors extends java.lang.ObjectA utility class for working withAnnotationMirrorinstances.- Author:
- Gregory Kick
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.google.common.base.Equivalence<javax.lang.model.element.AnnotationMirror>equivalence()Returns anEquivalenceforAnnotationMirroras 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 javax.lang.model.element.AnnotationMirror>getAnnotatedAnnotations(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)Returns all annotations that are present on the givenElementwhich are themselves annotated withannotationClass.static com.google.common.collect.ImmutableSet<? extends javax.lang.model.element.AnnotationMirror>getAnnotatedAnnotations(javax.lang.model.element.Element element, java.lang.String annotationName)Returns all annotations that are present on the givenElementwhich are themselves annotated with an annotation whose type's canonical name isannotationName.static com.google.common.collect.ImmutableSet<? extends javax.lang.model.element.AnnotationMirror>getAnnotatedAnnotations(javax.lang.model.element.Element element, javax.lang.model.element.TypeElement annotation)Returns all annotations that are present on the givenElementwhich are themselves annotated withannotation.static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>getAnnotationElementAndValue(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.String elementName)Returns aExecutableElementand its associatedAnnotationValueif such an element was either declared in the usage represented by the providedAnnotationMirror, or if such an element was defined with a default.static javax.lang.model.element.AnnotationValuegetAnnotationValue(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.String elementName)Returns anAnnotationValuefor 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<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>getAnnotationValuesWithDefaults(javax.lang.model.element.AnnotationMirror annotation)Returns theAnnotationMirror's map ofAnnotationValueindexed byExecutableElement, supplying default values from the annotation if the annotation property has not been set.static java.lang.StringtoString(javax.lang.model.element.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.
-
-
-
Method Detail
-
equivalence
public static com.google.common.base.Equivalence<javax.lang.model.element.AnnotationMirror> equivalence()
Returns anEquivalenceforAnnotationMirroras 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<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getAnnotationValuesWithDefaults(javax.lang.model.element.AnnotationMirror annotation)
Returns theAnnotationMirror's map ofAnnotationValueindexed 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 anElementsinstance.The iteration order of elements of the returned map will be the order in which the
ExecutableElements are defined inannotation's type.
-
getAnnotationValue
public static javax.lang.model.element.AnnotationValue getAnnotationValue(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.String elementName)Returns anAnnotationValuefor 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:
java.lang.IllegalArgumentException- if no element is defined with the given elementName.
-
getAnnotationElementAndValue
public static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getAnnotationElementAndValue(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.String elementName)Returns aExecutableElementand its associatedAnnotationValueif such an element was either declared in the usage represented by the providedAnnotationMirror, or if such an element was defined with a default.- Throws:
java.lang.IllegalArgumentException- if no element is defined with the given elementName.
-
getAnnotatedAnnotations
public static com.google.common.collect.ImmutableSet<? extends javax.lang.model.element.AnnotationMirror> getAnnotatedAnnotations(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)Returns all annotations that are present on the givenElementwhich are themselves annotated withannotationClass.
-
getAnnotatedAnnotations
public static com.google.common.collect.ImmutableSet<? extends javax.lang.model.element.AnnotationMirror> getAnnotatedAnnotations(javax.lang.model.element.Element element, javax.lang.model.element.TypeElement annotation)Returns all annotations that are present on the givenElementwhich are themselves annotated withannotation.
-
getAnnotatedAnnotations
public static com.google.common.collect.ImmutableSet<? extends javax.lang.model.element.AnnotationMirror> getAnnotatedAnnotations(javax.lang.model.element.Element element, java.lang.String annotationName)Returns all annotations that are present on the givenElementwhich are themselves annotated with an annotation whose type's canonical name isannotationName.
-
toString
public static java.lang.String toString(javax.lang.model.element.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.
-
-