public class AnnotationUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static @BinaryName String |
annotationBinaryName(AnnotationMirror annotation)
Returns the binary name of an annotation as a String.
|
static Class<?> |
annotationMirrorToClass(AnnotationMirror am)
Converts an AnnotationMirror to a Class.
|
static @CanonicalName String |
annotationName(AnnotationMirror annotation)
Returns the fully-qualified name of an annotation as a String.
|
static boolean |
annotationValueContains(@Nullable AnnotationValue avList,
String s)
Returns true if an AnnotationValue list contains the given value.
|
static boolean |
annotationValueContains(List<? extends AnnotationValue> avList,
String s)
Returns true if an AnnotationValue list contains the given value.
|
static boolean |
annotationValueContainsToString(@Nullable AnnotationValue avList,
String s)
Returns true if an AnnotationValue list contains a value whose
toString() is the
given string. |
static boolean |
annotationValueContainsToString(List<? extends AnnotationValue> avList,
String s)
Returns true if an AnnotationValue list contains a value whose
toString() is the
given string. |
static <T extends Enum<T>> |
annotationValueListToEnumArray(AnnotationValue avList,
Class<T> expectedType)
Converts a list of AnnotationValue to an array of enum.
|
static <T extends Enum<T>> |
annotationValueListToEnumArray(List<AnnotationValue> la,
Class<T> expectedType)
Converts a list of AnnotationValue to an array of enum.
|
static <T> List<T> |
annotationValueToList(AnnotationValue avList,
Class<T> expectedType)
Converts an annotation value to a list.
|
static <T> List<T> |
annotationValueToList(List<? extends AnnotationValue> avList,
Class<T> expectedType)
Converts an annotation value to a list.
|
static boolean |
areSame(AnnotationMirror a1,
AnnotationMirror a2)
Returns true iff both annotations are of the same type and have the same annotation values.
|
static boolean |
areSame(Collection<? extends AnnotationMirror> c1,
Collection<? extends AnnotationMirror> c2)
Checks that two collections contain the same annotations.
|
static boolean |
areSameByClass(AnnotationMirror am,
Class<? extends Annotation> annoClass)
Deprecated.
use
AnnotatedTypeFactory#areSameByClass or areSameByName(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror) |
static boolean |
areSameByName(AnnotationMirror a1,
AnnotationMirror a2)
Return true iff a1 and a2 have the same annotation type.
|
static boolean |
areSameByName(AnnotationMirror am,
String aname)
Checks that the annotation
am has the name aname (a fully-qualified type
name). |
static int |
compareAnnotationMirrors(AnnotationMirror a1,
AnnotationMirror a2)
Provide ordering for
AnnotationMirrors. |
static boolean |
containsSame(Collection<? extends AnnotationMirror> c,
AnnotationMirror anno)
Checks that the collection contains the annotation.
|
static boolean |
containsSameByClass(Collection<? extends AnnotationMirror> c,
Class<? extends Annotation> anno)
Checks that the collection contains the annotation.
|
static boolean |
containsSameByName(Collection<? extends AnnotationMirror> c,
AnnotationMirror anno)
Checks that the collection contains an annotation of the given name.
|
static boolean |
containsSameByName(Collection<? extends AnnotationMirror> c,
String anno)
Checks that the collection contains an annotation of the given name.
|
static <V> Map<AnnotationMirror,V> |
createAnnotationMap()
Create a map suitable for storing
AnnotationMirror as keys. |
static NavigableSet<AnnotationMirror> |
createAnnotationSet()
Constructs a
Set for storing AnnotationMirrors. |
static NavigableSet<AnnotationMirror> |
createAnnotationSet(Collection<AnnotationMirror> annos)
|
static NavigableSet<AnnotationMirror> |
createUnmodifiableAnnotationSet(Collection<AnnotationMirror> annos)
|
static @Nullable AnnotationMirror |
getAnnotationByClass(Collection<? extends AnnotationMirror> c,
Class<? extends Annotation> anno)
Returns the AnnotationMirror in
c that has the same class as anno. |
static @Nullable AnnotationMirror |
getAnnotationByName(Collection<? extends AnnotationMirror> c,
String anno)
Returns the AnnotationMirror in
c that has the same name as anno. |
static EnumSet<ElementKind> |
getElementKindsForElementType(ElementType elementType)
Returns the set of
ElementKinds corresponding to elementType. |
static EnumSet<ElementKind> |
getElementKindsForTarget(@Nullable Target target)
Returns the set of
ElementKinds to which target applies, ignoring TYPE_USE. |
static <T> T |
getElementValue(AnnotationMirror anno,
CharSequence elementName,
Class<T> expectedType,
boolean useDefaults)
|
static <T> T |
getElementValue(AnnotationMirror anno,
ExecutableElement element,
Class<T> expectedType)
Get the given element of the annotation
anno. |
static <T> T |
getElementValue(AnnotationMirror anno,
ExecutableElement element,
Class<T> expectedType,
T defaultValue)
Get the given element of the annotation
anno. |
static <T> List<T> |
getElementValueArray(AnnotationMirror anno,
CharSequence elementName,
Class<T> expectedType,
boolean useDefaults)
Deprecated.
use
#getElementValueArray(AnnotationMirror, ExecutableElement, Class) or
#getElementValueArray(AnnotationMirror, ExecutableElement, Class, Object) |
static <T> List<T> |
getElementValueArray(AnnotationMirror anno,
ExecutableElement element,
Class<T> expectedType)
Get the given element of the annotation
anno, where the element has an array type. |
static <T> List<T> |
getElementValueArray(AnnotationMirror anno,
ExecutableElement element,
Class<T> expectedType,
List<T> defaultValue)
Get the given element of the annotation
anno, where the element has an array type. |
static <T> @Nullable List<T> |
getElementValueArrayOrNull(AnnotationMirror anno,
CharSequence elementName,
Class<T> expectedType,
boolean useDefaults)
Get the element with the name
elementName of the annotation anno, or return
null if no such element exists. |
static boolean |
getElementValueBoolean(AnnotationMirror anno,
ExecutableElement element,
boolean defaultValue)
Get the given boolean element of the annotation
anno. |
static @CanonicalName Name |
getElementValueClassName(AnnotationMirror anno,
CharSequence elementName,
boolean useDefaults)
Deprecated.
use an ExecutableElement
|
static @CanonicalName Name |
getElementValueClassName(AnnotationMirror anno,
ExecutableElement element)
Get the Name of the class that is referenced by element
element. |
static List<Name> |
getElementValueClassNames(AnnotationMirror anno,
CharSequence annoElement,
boolean useDefaults)
Deprecated.
|
static List<Name> |
getElementValueClassNames(AnnotationMirror anno,
ExecutableElement element)
Get the list of Names of the classes that are referenced by element
element. |
static <T extends Enum<T>> |
getElementValueEnum(AnnotationMirror anno,
CharSequence elementName,
Class<T> expectedType,
boolean useDefaults)
|
static <T extends Enum<T>> |
getElementValueEnum(AnnotationMirror anno,
ExecutableElement element,
Class<T> expectedType)
Get the element with the name
name of the annotation anno. |
static <T extends Enum<T>> |
getElementValueEnum(AnnotationMirror anno,
ExecutableElement element,
Class<T> expectedType,
T defaultValue)
Get the element with the name
name of the annotation anno. |
static <T extends Enum<T>> |
getElementValueEnumArray(AnnotationMirror anno,
CharSequence elementName,
Class<T> expectedType,
boolean useDefaults)
|
static <T extends Enum<T>> |
getElementValueEnumArray(AnnotationMirror anno,
ExecutableElement element,
Class<T> expectedType)
Get the element with the name
name of the annotation anno. |
static <T extends Enum<T>> |
getElementValueEnumArray(AnnotationMirror anno,
ExecutableElement element,
Class<T> expectedType,
T[] defaultValue)
Get the element with the name
name of the annotation anno. |
static int |
getElementValueInt(AnnotationMirror anno,
ExecutableElement element)
Get the given integer element of the annotation
anno. |
static int |
getElementValueInt(AnnotationMirror anno,
ExecutableElement element,
int defaultValue)
Get the given integer element of the annotation
anno. |
static long |
getElementValueLong(AnnotationMirror anno,
ExecutableElement element,
long defaultValue)
Get the given long element of the annotation
anno. |
static <T> T |
getElementValueOrNull(AnnotationMirror anno,
CharSequence elementName,
Class<T> expectedType,
boolean useDefaults)
Get the element with the name
elementName of the annotation anno, or return
null if no such element exists. |
static Map<? extends ExecutableElement,? extends AnnotationValue> |
getElementValuesWithDefaults(AnnotationMirror ad)
Deprecated.
use a method that takes an
ExecutableElement |
static Set<AnnotationMirror> |
getExplicitAnnotationsOnConstructorResult(MethodTree constructorDeclaration)
Returns the annotations explicitly written on a constructor result.
|
static @Nullable AnnotationMirror |
getSame(Collection<? extends AnnotationMirror> c,
AnnotationMirror anno)
Returns the AnnotationMirror in
c that is the same annotation as anno. |
static @Nullable AnnotationMirror |
getSameByName(Collection<? extends AnnotationMirror> c,
AnnotationMirror anno)
Returns the AnnotationMirror in
c that is the same annotation as anno
ignoring values. |
static boolean |
hasElementValue(AnnotationMirror anno,
CharSequence elementName)
Deprecated.
use a method that takes an
ExecutableElement |
static boolean |
hasInheritedMeta(AnnotationMirror anno)
Returns true if the given annotation has a @Inherited meta-annotation.
|
static boolean |
hasTypeQualifierElementTypes(ElementType[] elements,
Class<?> cls)
Returns true if the given array contains
ElementType.TYPE_USE, false otherwise. |
static boolean |
isDeclarationAnnotation(AnnotationMirror anno)
Returns true if anno is a declaration annotation.
|
static boolean |
sameAnnotationValue(AnnotationValue av1,
AnnotationValue av2)
Return true iff the two AnnotationValue objects are the same.
|
static boolean |
sameElementValues(AnnotationMirror am1,
AnnotationMirror am2)
Returns true if the two annotations have the same elements (fields).
|
static String |
toStringSimple(AnnotationMirror am)
Returns a string representation of the annotation mirror, using simple (not fully-qualified)
names.
|
static void |
toStringSimple(AnnotationMirror am,
StringBuilder sb)
Appends a string representation of the annotation mirror, using simple (not fully-qualified)
names, to the StringBuilder.
|
static String |
toStringSimple(Set<AnnotationMirror> annos)
Returns a string representation of the annotation mirrors, using simple (not fully-qualified)
names.
|
static <T> void |
updateMappingToImmutableSet(Map<T,Set<AnnotationMirror>> map,
T key,
Set<AnnotationMirror> newQual)
Update a map, to add
newQual to the set that key maps to. |
public static final @CanonicalName String annotationName(AnnotationMirror annotation)
annotation - the annotation whose name to returnpublic static final @BinaryName String annotationBinaryName(AnnotationMirror annotation)
annotation - the annotation whose binary name to return@EqualsMethod public static boolean areSame(AnnotationMirror a1, AnnotationMirror a2)
This behavior differs from AnnotationMirror.equals(Object). The equals method
returns true iff both annotations are the same and annotate the same annotation target (e.g.
field, variable, etc) -- that is, if its arguments are the same annotation instance.
a1 - the first AnnotationMirror to comparea2 - the second AnnotationMirror to compare@EqualsMethod public static boolean areSameByName(AnnotationMirror a1, AnnotationMirror a2)
a1 - the first AnnotationMirror to comparea2 - the second AnnotationMirror to compareareSame(AnnotationMirror, AnnotationMirror)public static boolean areSameByName(AnnotationMirror am, String aname)
am has the name aname (a fully-qualified type
name). Values are ignored.am - the AnnotationMirror whose name to compareaname - the string to compare@Deprecated public static boolean areSameByClass(AnnotationMirror am, Class<? extends Annotation> annoClass)
AnnotatedTypeFactory#areSameByClass or areSameByName(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)am has the name of annoClass. Values are ignored.
This method is not very efficient. It is more efficient to use AnnotatedTypeFactory#areSameByClass or areSameByName(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror).
am - the AnnotationMirror whose class to compareannoClass - the class to comparepublic static boolean areSame(Collection<? extends AnnotationMirror> c1, Collection<? extends AnnotationMirror> c2)
c1 - the first collection to comparec2 - the second collection to compareareSame(AnnotationMirror, AnnotationMirror)public static boolean containsSame(Collection<? extends AnnotationMirror> c, AnnotationMirror anno)
c - a collection of AnnotationMirrorsanno - the AnnotationMirror to search for in cpublic static @Nullable AnnotationMirror getSame(Collection<? extends AnnotationMirror> c, AnnotationMirror anno)
c that is the same annotation as anno.c - a collection of AnnotationMirrorsanno - the AnnotationMirror to search for in canno iff c contains anno, according
to areSame; otherwise, nullpublic static boolean containsSameByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> anno)
This method is not very efficient. It is more efficient to use AnnotatedTypeFactory#containsSameByClass or containsSameByName(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror>, java.lang.String).
c - a collection of AnnotationMirrorsanno - the annotation class to search for in cpublic static @Nullable AnnotationMirror getAnnotationByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> anno)
c that has the same class as anno.
This method is not very efficient. It is more efficient to use AnnotatedTypeFactory#getAnnotationByClass or getAnnotationByName(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror>, java.lang.String).
c - a collection of AnnotationMirrorsanno - the class to search for in canno iff c contains anno, according
to areSameByClass; otherwise, nullpublic static boolean containsSameByName(Collection<? extends AnnotationMirror> c, String anno)
c - a collection of AnnotationMirrorsanno - the name to search for in cpublic static @Nullable AnnotationMirror getAnnotationByName(Collection<? extends AnnotationMirror> c, String anno)
c that has the same name as anno.c - a collection of AnnotationMirrorsanno - the name to search for in canno iff c contains anno, according to
areSameByName; otherwise, nullpublic static boolean containsSameByName(Collection<? extends AnnotationMirror> c, AnnotationMirror anno)
c - a collection of AnnotationMirrorsanno - the annotation whose name to search for in cpublic static @Nullable AnnotationMirror getSameByName(Collection<? extends AnnotationMirror> c, AnnotationMirror anno)
c that is the same annotation as anno
ignoring values.c - a collection of AnnotationMirrorsanno - the annotation whose name to search for in canno iff c contains anno, according
to areSameByName; otherwise, nullpublic static int compareAnnotationMirrors(AnnotationMirror a1, AnnotationMirror a2)
AnnotationMirrors. AnnotationMirrors are first compared by their
fully-qualified names, then by their element values in order of the name of the element.a1 - the first annotationa2 - the second annotationpublic static <V> Map<AnnotationMirror,V> createAnnotationMap()
AnnotationMirror as keys.
It can store one instance of AnnotationMirror of a given declared type, regardless
of the annotation element values.
V - the value of the mapAnnotationMirror as keypublic static NavigableSet<AnnotationMirror> createAnnotationSet()
Set for storing AnnotationMirrors.
It stores at most once instance of AnnotationMirror of a given type, regardless of
the annotation element values.
AnnotationMirror as elementpublic static NavigableSet<AnnotationMirror> createAnnotationSet(Collection<AnnotationMirror> annos)
Set for storing AnnotationMirrors contain all the annotations in
annos.
It stores at most once instance of AnnotationMirror of a given type, regardless of
the annotation element values.
annos - a Collection of AnnotationMirrors to put in the created setAnnotationMirror as elementpublic static NavigableSet<AnnotationMirror> createUnmodifiableAnnotationSet(Collection<AnnotationMirror> annos)
Set for storing AnnotationMirrors contain all the
annotations in annos.
It stores at most once instance of AnnotationMirror of a given type, regardless of
the annotation element values.
annos - a Collection of AnnotationMirrors to put in the created setAnnotationMirror as elementpublic static boolean hasInheritedMeta(AnnotationMirror anno)
anno - the annotation to check for an @Inherited meta-annotationpublic static EnumSet<ElementKind> getElementKindsForTarget(@Nullable Target target)
ElementKinds to which target applies, ignoring TYPE_USE.target - a location where an annotation can be writtenElementKinds to which target applies, ignoring TYPE_USEpublic static EnumSet<ElementKind> getElementKindsForElementType(ElementType elementType)
ElementKinds corresponding to elementType. If the element
type is TYPE_USE, then ElementKinds returned should be the same as those returned for TYPE
and TYPE_PARAMETER, but this method returns the empty set instead.elementType - the elementType to find ElementKinds forElementKinds corresponding to elementType@Deprecated public static Map<? extends ExecutableElement,? extends AnnotationValue> getElementValuesWithDefaults(AnnotationMirror ad)
ExecutableElementThis method is intended for use only by the framework. Clients should use a method that
takes an ExecutableElement.
ad - annotation to examineAnnotationMirror.getElementValues(),
JavacElements.getElementValuesWithDefaults(AnnotationMirror)@Deprecated public static boolean hasElementValue(AnnotationMirror anno, CharSequence elementName)
ExecutableElementelementName exists in the annotation anno.
This method is intended for use only by the framework. Clients should use a method that
takes an ExecutableElement.
anno - the annotation to examineelementName - the name of the element@Deprecated public static <T> T getElementValue(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults)
getElementValue(AnnotationMirror, ExecutableElement, Class) or
getElementValue(AnnotationMirror, ExecutableElement, Class, Object)elementName of the annotation anno. The result
has type expectedType.
If the return type is an array, use getElementValueArray(javax.lang.model.element.AnnotationMirror, java.lang.CharSequence, java.lang.Class<T>, boolean) instead.
If the return type is an enum, use getElementValueEnum(javax.lang.model.element.AnnotationMirror, java.lang.CharSequence, java.lang.Class<T>, boolean) instead.
This method is intended only for use by the framework. A checker implementation should use
getElementValue(AnnotationMirror, ExecutableElement, Class) or getElementValue(AnnotationMirror, ExecutableElement, Class, Object).
T - the class of the typeanno - the annotation whose element to accesselementName - the name of the element to accessexpectedType - the type of the element and the return valueuseDefaults - whether to apply default values to the elementpublic static <T> T getElementValueOrNull(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults)
elementName of the annotation anno, or return
null if no such element exists.
This method is intended only for use by the framework. A checker implementation should use
getElementValue(AnnotationMirror, ExecutableElement, Class, Object).
T - the class of the typeanno - the annotation whose element to accesselementName - the name of the element to accessexpectedType - the type of the element and the return valueuseDefaults - whether to apply default values to the elementpublic static <T> @Nullable List<T> getElementValueArrayOrNull(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults)
elementName of the annotation anno, or return
null if no such element exists. One element of the result has type expectedType.
This method is intended only for use by the framework. A checker implementation should use
getElementValue(AnnotationMirror, ExecutableElement, Class, Object).
T - the class of the component typeanno - the annotation whose element to accesselementName - the name of the element to accessexpectedType - the component type of the element and of the return valueuseDefaults - whether to apply default values to the element@Deprecated public static <T extends Enum<T>> T getElementValueEnum(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults)
getElementValueEnum(AnnotationMirror, ExecutableElement, Class) or
getElementValueEnum(AnnotationMirror, ExecutableElement, Class, Enum)name of the annotation anno. The result is an
enum of type T.
This method is intended only for use by the framework. A checker implementation should use
getElementValueEnum(AnnotationMirror, ExecutableElement, Class) or getElementValueEnum(AnnotationMirror, ExecutableElement, Class, Enum).
T - the class of the typeanno - the annotation to disassembleelementName - the name of the element to accessexpectedType - the type of the element and the return value, an enumuseDefaults - whether to apply default values to the element@Deprecated public static <T> List<T> getElementValueArray(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults)
#getElementValueArray(AnnotationMirror, ExecutableElement, Class) or
#getElementValueArray(AnnotationMirror, ExecutableElement, Class, Object)elementName of the annotation anno, where the
element has an array type. One element of the result has type expectedType.
Parameter useDefaults is used to determine whether default values should be used for annotation values. Finding defaults requires more computation, so should be false when no defaulting is needed.
This method is intended only for use by the framework. A checker implementation should use
#getElementValueArray(AnnotationMirror, ExecutableElement, Class) or #getElementValueArray(AnnotationMirror, ExecutableElement, Class, Object).
T - the class of the typeanno - the annotation to disassembleelementName - the name of the element to accessexpectedType - the component type of the element and of the return typeuseDefaults - whether to apply default values to the element@Deprecated public static <T extends Enum<T>> T[] getElementValueEnumArray(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults)
getElementValueEnumArray(AnnotationMirror, ExecutableElement, Class)
or getElementValueEnumArray(AnnotationMirror, ExecutableElement, Class, Enum[])elementName of the annotation anno, or the
default value if no element is present explicitly, where the element has an array type and
the elements are Enums. One element of the result has type expectedType.
This method is intended only for use by the framework. A checker implementation should use
getElementValueEnumArray(AnnotationMirror, ExecutableElement, Class) or getElementValueEnumArray(AnnotationMirror, ExecutableElement, Class, Enum[]).
T - the class of the typeanno - the annotation to disassembleelementName - the name of the element to accessexpectedType - the component type of the element and of the return type, an enumuseDefaults - whether to apply default values to the element@Deprecated public static @CanonicalName Name getElementValueClassName(AnnotationMirror anno, CharSequence elementName, boolean useDefaults)
elementName.
This is a convenience method for the most common use-case. It is like getElementValue(anno, elementName, ClassType.class).getQualifiedName(), but this method
ensures consistent use of the qualified name.
This method is intended only for use by the framework. A checker implementation should use
anno.getElementValues().get(someElement).getValue().asElement().getQualifiedName();.
anno - the annotation to disassembleelementName - the name of the element to access; it must be present in the annotationuseDefaults - whether to apply default values to the element@Deprecated public static List<Name> getElementValueClassNames(AnnotationMirror anno, CharSequence annoElement, boolean useDefaults)
getElementValueClassNames(AnnotationMirror,ExecutableElement)elementName. It
fails if the class wasn't found.
This method is intended only for use by the framework. A checker implementation should use
getElementValueClassNames(AnnotationMirror, ExecutableElement).
anno - the annotation whose field to access; it must be present in the annotationannoElement - the element/field of anno whose content is a list of classesuseDefaults - whether to apply default values to the elementanno.annoElementpublic static <T> T getElementValue(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType)
anno. The result has type expectedType.
If the return type is primitive, use getElementValueInt(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.ExecutableElement) or getElementValueLong(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.ExecutableElement, long) instead.
If the return type is an array, use getElementValueArray(javax.lang.model.element.AnnotationMirror, java.lang.CharSequence, java.lang.Class<T>, boolean) instead.
If the return type is an enum, use getElementValueEnum(javax.lang.model.element.AnnotationMirror, java.lang.CharSequence, java.lang.Class<T>, boolean) instead.
T - the class of the typeanno - the annotation whose element to accesselement - the element to access; it must be present in the annotationexpectedType - the type of the element and the return valuepublic static <T> T getElementValue(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, T defaultValue)
anno. The result has type expectedType.
If the return type is primitive, use getElementValueInt(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.ExecutableElement) or getElementValueLong(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.ExecutableElement, long) instead.
If the return type is an array, use getElementValueArray(javax.lang.model.element.AnnotationMirror, java.lang.CharSequence, java.lang.Class<T>, boolean) instead.
If the return type is an enum, use getElementValueEnum(javax.lang.model.element.AnnotationMirror, java.lang.CharSequence, java.lang.Class<T>, boolean) instead.
T - the class of the typeanno - the annotation whose element to accesselement - the element to accessexpectedType - the type of the element and the return valuedefaultValue - the value to return if the element is not presentpublic static boolean getElementValueBoolean(AnnotationMirror anno, ExecutableElement element, boolean defaultValue)
anno.anno - the annotation whose element to accesselement - the element to accessdefaultValue - the value to return if the element is not presentpublic static int getElementValueInt(AnnotationMirror anno, ExecutableElement element)
anno.anno - the annotation whose element to accesselement - the element to accesspublic static int getElementValueInt(AnnotationMirror anno, ExecutableElement element, int defaultValue)
anno.anno - the annotation whose element to accesselement - the element to accessdefaultValue - the value to return if the element is not presentpublic static long getElementValueLong(AnnotationMirror anno, ExecutableElement element, long defaultValue)
anno.anno - the annotation whose element to accesselement - the element to accessdefaultValue - the value to return if the element is not presentpublic static <T extends Enum<T>> T getElementValueEnum(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType)
name of the annotation anno. The result is an
enum of type T.T - the class of the typeanno - the annotation to disassembleelement - the element to access; it must be present in the annotationexpectedType - the type of the element and the return value, an enumpublic static <T extends Enum<T>> T getElementValueEnum(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, T defaultValue)
name of the annotation anno. The result is an
enum of type T.T - the class of the typeanno - the annotation to disassembleelement - the element to accessexpectedType - the type of the element and the return value, an enumdefaultValue - the value to return if the element is not presentpublic static <T extends Enum<T>> T[] getElementValueEnumArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType)
name of the annotation anno. The result is an
array of type T.T - the enum class of the component typeanno - the annotation to disassembleelement - the element to access; it must be present in the annotationexpectedType - the component type of the element and of the return value, an enumpublic static <T extends Enum<T>> T[] getElementValueEnumArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, T[] defaultValue)
name of the annotation anno. The result is an
array of type T.T - the enum class of the component typeanno - the annotation to disassembleelement - the element to accessexpectedType - the component type of the element and of the return typedefaultValue - the value to return if the annotation does not have the elementpublic static <T> List<T> getElementValueArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType)
anno, where the element has an array type.
One element of the result has type expectedType.T - the class of the component typeanno - the annotation to disassembleelement - the element to access; it must be present in the annotationexpectedType - the component type of the element and of the return typepublic static <T> List<T> getElementValueArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, List<T> defaultValue)
anno, where the element has an array type.
One element of the result has type expectedType.T - the class of the component typeanno - the annotation to disassembleelement - the element to accessexpectedType - the component type of the element and of the return typedefaultValue - the value to return if the element is not presentpublic static <T extends Enum<T>> T[] annotationValueListToEnumArray(AnnotationValue avList, Class<T> expectedType)
T - the element type of the enum arrayavList - a list of AnnotationValueexpectedType - the component type of the element and of the return type, an enumpublic static <T extends Enum<T>> T[] annotationValueListToEnumArray(List<AnnotationValue> la, Class<T> expectedType)
T - the element type of the enum arrayla - a list of AnnotationValueexpectedType - the component type of the element and of the return type, an enumpublic static @CanonicalName Name getElementValueClassName(AnnotationMirror anno, ExecutableElement element)
element.
This is a convenience method for the most common use-case. It is like getElementValue(anno, element, ClassType.class).getQualifiedName(), but this method ensures
consistent use of the qualified name.
This method is intended only for use by the framework. A checker implementation should use
anno.getElementValues().get(someElement).getValue().asElement().getQualifiedName();.
anno - the annotation to disassembleelement - the element to access; it must be present in the annotationpublic static List<Name> getElementValueClassNames(AnnotationMirror anno, ExecutableElement element)
element. It fails
if the class wasn't found.anno - the annotation whose field to access; it must be present in the annotationelement - the element/field of anno whose content is a list of classesanno.annoElement@EqualsMethod public static boolean sameElementValues(AnnotationMirror am1, AnnotationMirror am2)
am1 and am2 must be the same type of annotation.am1 - the first AnnotationMirror to compaream2 - the second AnnotationMirror to comparepublic static boolean sameAnnotationValue(AnnotationValue av1, AnnotationValue av2)
av1 - the first AnnotationValue to compareav2 - the second AnnotationValue to comparepublic static boolean annotationValueContains(@Nullable AnnotationValue avList, String s)
Using this method is slightly cheaper than creating a new List<String> just for
the purpose of testing containment within it.
avList - an AnnotationValue that is null or a list of Stringss - a stringav contains spublic static boolean annotationValueContains(List<? extends AnnotationValue> avList, String s)
Using this method is slightly cheaper than creating a new List<String> just for
the purpose of testing containment within it.
avList - a list of Strings (as AnnotationValues)s - a stringav contains spublic static boolean annotationValueContainsToString(@Nullable AnnotationValue avList, String s)
toString() is the
given string.
Using this method is slightly cheaper than creating a new List just for the
purpose of testing containment within it.
avList - an AnnotationValue that is null or a lists - a stringav contains spublic static boolean annotationValueContainsToString(List<? extends AnnotationValue> avList, String s)
toString() is the
given string.
Using this method is slightly cheaper than creating a new List just for the
purpose of testing containment within it.
avList - a list of Strings (as AnnotationValues)s - a stringav contains spublic static <T> List<T> annotationValueToList(AnnotationValue avList, Class<T> expectedType)
To test containment, use annotationValueContains(AnnotationValue, String) or
annotationValueContainsToString(AnnotationValue, String).
T - the class of the typeavList - an AnnotationValue that is null or a list of StringsexpectedType - the component type of the argument and of the return type, an enumpublic static <T> List<T> annotationValueToList(List<? extends AnnotationValue> avList, Class<T> expectedType)
To test containment, use annotationValueContains(List, String) or annotationValueContainsToString(List, String).
T - the class of the typeavList - a list of Strings (as AnnotationValues)expectedType - the component type of the argument and of the return type, an enumpublic static <T> void updateMappingToImmutableSet(Map<T,Set<AnnotationMirror>> map, T key, Set<AnnotationMirror> newQual)
newQual to the set that key maps to. The mapped-to
element is an unmodifiable set.
See org.checkerframework.framework.type.QualifierHierarchy#updateMappingToMutableSet(QualifierHierarchy, Map, Object, AnnotationMirror).
T - the key typemap - the map to updatekey - the key whose value to updatenewQual - the element to add to the given key's valuepublic static Set<AnnotationMirror> getExplicitAnnotationsOnConstructorResult(MethodTree constructorDeclaration)
constructorDeclaration is in fact a declaration of a constructor.constructorDeclaration - declaration tree of constructorpublic static boolean isDeclarationAnnotation(AnnotationMirror anno)
anno - the AnnotationMirrorpublic static boolean hasTypeQualifierElementTypes(ElementType[] elements, Class<?> cls)
ElementType.TYPE_USE, false otherwise.elements - an array of ElementType valuescls - the annotation class being tested; used for diagnostic messages onlyElementType.TYPE_USERuntimeException - if the array contains both ElementType.TYPE_USE and
something besides ElementType.TYPE_PARAMETER@SideEffectFree public static String toStringSimple(Set<AnnotationMirror> annos)
annos - annotations to format@SideEffectFree public static String toStringSimple(AnnotationMirror am)
am - annotation to formatpublic static void toStringSimple(AnnotationMirror am, StringBuilder sb)
am - annotation to formatsb - StringBuilder to which the string representation of am, using simple (not
fully-qualified) names, is appendedpublic static Class<?> annotationMirrorToClass(AnnotationMirror am)
am - an AnnotationMirror