Class AnnotationUtils
- 
Method SummaryModifier and TypeMethodDescriptionstatic final @BinaryName StringannotationBinaryName(AnnotationMirror annotation) Returns the binary name of an annotation as a String.static Class<?>Converts an AnnotationMirror to a Class.static final @CanonicalName StringannotationName(AnnotationMirror annotation) Returns the fully-qualified name of an annotation as a String.static booleanannotationValueContains(@Nullable AnnotationValue avList, String s) Returns true if an AnnotationValue list contains the given value.static booleanannotationValueContains(List<? extends AnnotationValue> avList, String s) Returns true if an AnnotationValue list contains the given value.static booleanReturns true if an AnnotationValue list contains a value whosetoString()is the given string.static booleanannotationValueContainsToString(List<? extends AnnotationValue> avList, String s) Returns true if an AnnotationValue list contains a value whosetoString()is the given string.static <T extends Enum<T>>
 T[]annotationValueListToEnumArray(List<AnnotationValue> la, Class<T> expectedType) Converts a list of AnnotationValue to an array of enum.static <T extends Enum<T>>
 T[]annotationValueListToEnumArray(AnnotationValue avList, Class<T> expectedType) Converts a list of AnnotationValue to an array of enum.static <T> List<T>annotationValueToList(List<? extends AnnotationValue> avList, Class<T> expectedType) Converts an annotation value to a list.static <T> List<T>annotationValueToList(AnnotationValue avList, Class<T> expectedType) Converts an annotation value to a list.static booleanareSame(Collection<? extends AnnotationMirror> c1, Collection<? extends AnnotationMirror> c2) Checks that two collections contain the same annotations.static booleanareSame(AnnotationMirror a1, AnnotationMirror a2) Returns true iff both annotations are of the same type and have the same annotation values.static booleanareSameByClass(AnnotationMirror am, Class<? extends Annotation> annoClass) Deprecated.static booleanareSameByName(AnnotationMirror am, String aname) Checks that the annotationamhas the nameaname(a fully-qualified type name).static booleanReturn true iff a1 and a2 have the same annotation type.static intProvide an ordering forAnnotationMirrors.static intReturn -1, 0, or 1 depending on whether the name of a1 is less, equal to, or greater than that of a2 (lexicographically).static booleancontainsSame(Collection<? extends AnnotationMirror> c, AnnotationMirror anno) Checks that the collection contains the annotation.static booleancontainsSameByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> anno) Checks that the collection contains the annotation.static booleancontainsSameByName(Collection<? extends AnnotationMirror> c, String anno) Checks that the collection contains an annotation of the given name.static booleancontainsSameByName(Collection<? extends AnnotationMirror> c, AnnotationMirror anno) Checks that the collection contains an annotation of the given name.static @Nullable AnnotationMirrorgetAnnotationByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> anno) Returns the AnnotationMirror incthat has the same class asanno.static @Nullable AnnotationMirrorgetAnnotationByName(Collection<? extends AnnotationMirror> c, String anno) Returns the AnnotationMirror incthat has the same name asanno.static EnumSet<ElementKind>getElementKindsForElementType(ElementType elementType) Returns the set ofElementKinds corresponding toelementType.static EnumSet<ElementKind>getElementKindsForTarget(@Nullable Target target) Returns the set ofElementKinds to whichtargetapplies, ignoring TYPE_USE.static <T> TgetElementValue(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) static <T> @Nullable TgetElementValue(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType) Get the given element of the annotationanno.static <T> @Nullable TgetElementValue(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, T defaultValue) Get the given element of the annotationanno.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 annotationanno, 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 annotationanno, where the element has an array type.getElementValueArrayOrNull(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) Get the element with the nameelementNameof the annotationanno, or return null if no such element exists.static booleangetElementValueBoolean(AnnotationMirror anno, ExecutableElement element, boolean defaultValue) Get the given boolean element of the annotationanno.static @CanonicalName NamegetElementValueClassName(AnnotationMirror anno, CharSequence elementName, boolean useDefaults) Deprecated.use an ExecutableElementstatic @CanonicalName NamegetElementValueClassName(AnnotationMirror anno, ExecutableElement element) Get the Name of the class that is referenced by elementelement.static List<@CanonicalName Name>getElementValueClassNames(AnnotationMirror anno, CharSequence annoElement, boolean useDefaults) Deprecated.static List<@CanonicalName Name>getElementValueClassNames(AnnotationMirror anno, ExecutableElement element) Get the list of Names of the classes that are referenced by elementelement.static <T extends Enum<T>>
 TgetElementValueEnum(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) static <T extends Enum<T>>
 TgetElementValueEnum(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType) Get the element with the namenameof the annotationanno.static <T extends Enum<T>>
 TgetElementValueEnum(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, T defaultValue) Get the element with the namenameof the annotationanno.static <T extends Enum<T>>
 T[]getElementValueEnumArray(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) static <T extends Enum<T>>
 T[]getElementValueEnumArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType) Get the element with the namenameof the annotationanno.static <T extends Enum<T>>
 T[]getElementValueEnumArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, T[] defaultValue) Get the element with the namenameof the annotationanno.static intgetElementValueInt(AnnotationMirror anno, ExecutableElement element) Get the given integer element of the annotationanno.static intgetElementValueInt(AnnotationMirror anno, ExecutableElement element, int defaultValue) Get the given integer element of the annotationanno.static longgetElementValueLong(AnnotationMirror anno, ExecutableElement element, long defaultValue) Get the given long element of the annotationanno.static <T> @Nullable TgetElementValueOrNull(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) Get the element with the nameelementNameof the annotationanno, or return null if no such element exists.static Map<? extends ExecutableElement,? extends AnnotationValue> Deprecated.use a method that takes anExecutableElementstatic AnnotationMirrorSetgetExplicitAnnotationsOnConstructorResult(MethodTree constructorDeclaration) Returns the annotations explicitly written on a constructor result.static @Nullable AnnotationMirrorgetSame(Collection<? extends AnnotationMirror> c, AnnotationMirror anno) Returns the AnnotationMirror incthat is the same annotation asanno.static @Nullable AnnotationMirrorgetSameByName(Collection<? extends AnnotationMirror> c, AnnotationMirror anno) Returns the AnnotationMirror incthat is the same annotation asannoignoring values.static booleanhasElementValue(AnnotationMirror anno, CharSequence elementName) Deprecated.use a method that takes anExecutableElementstatic booleanReturns true if the given annotation has a @Inherited meta-annotation.static booleanhasTypeQualifierElementTypes(ElementType[] elements, Class<?> cls) Returns true if the given array containsElementType.TYPE_USE, false otherwise.static booleanReturns true if anno is a declaration annotation.static booleanReturn true iff the two AnnotationValue objects are the same.static booleanReturns true if the two annotations have the same elements (fields).static StringReturns a string representation of the annotation mirrors, using simple (not fully-qualified) names.updateMappingToImmutableSet(Map<T, AnnotationMirrorSet> map, T key, AnnotationMirrorSet newQual) Update a map, to addnewQualto the set thatkeymaps to.
- 
Method Details- 
annotationNameReturns the fully-qualified name of an annotation as a String.- Parameters:
- annotation- the annotation whose name to return
- Returns:
- the fully-qualified name of an annotation as a String
 
- 
annotationBinaryNameReturns the binary name of an annotation as a String.- Parameters:
- annotation- the annotation whose binary name to return
- Returns:
- the binary name of an annotation as a String
 
- 
areSameReturns true iff both annotations are of the same type and have the same annotation values.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.- Parameters:
- a1- the first AnnotationMirror to compare
- a2- the second AnnotationMirror to compare
- Returns:
- true iff a1 and a2 are the same annotation
 
- 
compareByNameReturn -1, 0, or 1 depending on whether the name of a1 is less, equal to, or greater than that of a2 (lexicographically).- Parameters:
- a1- the first AnnotationMirror to compare
- a2- the second AnnotationMirror to compare
- Returns:
- true iff a1 and a2 have the same annotation name
- See Also:
 
- 
areSameByNameReturn true iff a1 and a2 have the same annotation type.- Parameters:
- a1- the first AnnotationMirror to compare
- a2- the second AnnotationMirror to compare
- Returns:
- true iff a1 and a2 have the same annotation name
- See Also:
 
- 
areSameByNameChecks that the annotationamhas the nameaname(a fully-qualified type name). Values are ignored.- Parameters:
- am- the AnnotationMirror whose name to compare
- aname- the string to compare
- Returns:
- true if aname is the name of am
 
- 
areSameByClass@Deprecated public static boolean areSameByClass(AnnotationMirror am, Class<? extends Annotation> annoClass) Deprecated.useAnnotatedTypeFactory#areSameByClassorareSameByName(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)Checks that the annotationamhas the name ofannoClass. Values are ignored.This method is not very efficient. It is more efficient to use AnnotatedTypeFactory#areSameByClassorareSameByName(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror).- Parameters:
- am- the AnnotationMirror whose class to compare
- annoClass- the class to compare
- Returns:
- true if annoclass is the class of am
 
- 
areSamepublic static boolean areSame(Collection<? extends AnnotationMirror> c1, Collection<? extends AnnotationMirror> c2) Checks that two collections contain the same annotations.- Parameters:
- c1- the first collection to compare
- c2- the second collection to compare
- Returns:
- true iff c1 and c2 contain the same annotations, according to areSame(AnnotationMirror, AnnotationMirror)
 
- 
containsSameChecks that the collection contains the annotation. Using Collection.contains does not always work, because it does not use areSame for comparison.- Parameters:
- c- a collection of AnnotationMirrors
- anno- the AnnotationMirror to search for in c
- Returns:
- true iff c contains anno, according to areSame
 
- 
getSamepublic static @Nullable AnnotationMirror getSame(Collection<? extends AnnotationMirror> c, AnnotationMirror anno) Returns the AnnotationMirror incthat is the same annotation asanno.- Parameters:
- c- a collection of AnnotationMirrors
- anno- the AnnotationMirror to search for in c
- Returns:
- AnnotationMirror with the same class as annoiff c contains anno, according to areSame; otherwise,null
 
- 
containsSameByClasspublic static boolean containsSameByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> anno) Checks that the collection contains the annotation. Using Collection.contains does not always work, because it does not use areSame for comparison.This method is not very efficient. It is more efficient to use AnnotatedTypeFactory#containsSameByClassorcontainsSameByName(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror>, java.lang.String).- Parameters:
- c- a collection of AnnotationMirrors
- anno- the annotation class to search for in c
- Returns:
- true iff c contains anno, according to areSameByClass
 
- 
getAnnotationByClasspublic static @Nullable AnnotationMirror getAnnotationByClass(Collection<? extends AnnotationMirror> c, Class<? extends Annotation> anno) Returns the AnnotationMirror incthat has the same class asanno.This method is not very efficient. It is more efficient to use AnnotatedTypeFactory#getAnnotationByClassorgetAnnotationByName(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror>, java.lang.String).- Parameters:
- c- a collection of AnnotationMirrors
- anno- the class to search for in c
- Returns:
- AnnotationMirror with the same class as annoiff c contains anno, according to areSameByClass; otherwise,null
 
- 
containsSameByNameChecks that the collection contains an annotation of the given name. Differs from using Collection.contains, which does not use areSameByName for comparison.- Parameters:
- c- a collection of AnnotationMirrors
- anno- the name to search for in c
- Returns:
- true iff c contains anno, according to areSameByName
 
- 
getAnnotationByNamepublic static @Nullable AnnotationMirror getAnnotationByName(Collection<? extends AnnotationMirror> c, String anno) Returns the AnnotationMirror incthat has the same name asanno.- Parameters:
- c- a collection of AnnotationMirrors
- anno- the name to search for in c
- Returns:
- AnnotationMirror with the same name as annoiff c contains anno, according to areSameByName; otherwise,null
 
- 
containsSameByNamepublic static boolean containsSameByName(Collection<? extends AnnotationMirror> c, AnnotationMirror anno) Checks that the collection contains an annotation of the given name. Differs from using Collection.contains, which does not use areSameByName for comparison.- Parameters:
- c- a collection of AnnotationMirrors
- anno- the annotation whose name to search for in c
- Returns:
- true iff c contains anno, according to areSameByName
 
- 
getSameByNamepublic static @Nullable AnnotationMirror getSameByName(Collection<? extends AnnotationMirror> c, AnnotationMirror anno) Returns the AnnotationMirror incthat is the same annotation asannoignoring values.- Parameters:
- c- a collection of AnnotationMirrors
- anno- the annotation whose name to search for in c
- Returns:
- AnnotationMirror with the same class as annoiff c contains anno, according to areSameByName; otherwise,null
 
- 
compareAnnotationMirrorsProvide an ordering forAnnotationMirrors. AnnotationMirrors are first compared by their fully-qualified names, then by their element values in order of the name of the element.- Parameters:
- a1- the first annotation
- a2- the second annotation
- Returns:
- an ordering over AnnotationMirrors based on their name and values
 
- 
hasInheritedMetaReturns true if the given annotation has a @Inherited meta-annotation.- Parameters:
- anno- the annotation to check for an @Inherited meta-annotation
- Returns:
- true if the given annotation has a @Inherited meta-annotation
 
- 
getElementKindsForTargetReturns the set ofElementKinds to whichtargetapplies, ignoring TYPE_USE.- Parameters:
- target- a location where an annotation can be written
- Returns:
- the set of ElementKinds to whichtargetapplies, ignoring TYPE_USE
 
- 
getElementKindsForElementTypeReturns the set ofElementKinds corresponding toelementType. 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.- Parameters:
- elementType- the elementType to find ElementKinds for
- Returns:
- the set of ElementKinds corresponding toelementType
 
- 
getElementValuesWithDefaults@Deprecated public static Map<? extends ExecutableElement,? extends AnnotationValue> getElementValuesWithDefaults(AnnotationMirror ad) Deprecated.use a method that takes anExecutableElementReturns the values of an annotation's elements, including defaults. The method with the same name in JavacElements cannot be used directly, because it includes a cast to Attribute.Compound, which doesn't hold for annotations generated by the Checker Framework.This method is intended for use only by the framework. Clients should use a method that takes an ExecutableElement.- Parameters:
- ad- annotation to examine
- Returns:
- the values of the annotation's elements, including defaults
- See Also:
- 
- AnnotationMirror.getElementValues()
- JavacElements.getElementValuesWithDefaults(AnnotationMirror)
 
 
- 
hasElementValueDeprecated.use a method that takes anExecutableElementVerify whether the element with the nameelementNameexists in the annotationanno.This method is intended for use only by the framework. Clients should use a method that takes an ExecutableElement.- Parameters:
- anno- the annotation to examine
- elementName- the name of the element
- Returns:
- whether the element exists in anno
 
- 
getElementValue@Deprecated public static <T> T getElementValue(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) Deprecated.Get the element with the nameelementNameof the annotationanno. The result has typeexpectedType.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)orgetElementValue(AnnotationMirror, ExecutableElement, Class, Object).- Type Parameters:
- T- the class of the type
- Parameters:
- anno- the annotation whose element to access
- elementName- the name of the element to access
- expectedType- the type of the element and the return value
- useDefaults- whether to apply default values to the element
- Returns:
- the value of the element with the given name
 
- 
getElementValueOrNullpublic static <T> @Nullable T getElementValueOrNull(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) Get the element with the nameelementNameof the annotationanno, 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).- Type Parameters:
- T- the class of the type
- Parameters:
- anno- the annotation whose element to access
- elementName- the name of the element to access
- expectedType- the type of the element and the return value
- useDefaults- whether to apply default values to the element
- Returns:
- the value of the element with the given name, or null
 
- 
getElementValueArrayOrNullpublic static <T> @Nullable List<T> getElementValueArrayOrNull(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) Get the element with the nameelementNameof the annotationanno, or return null if no such element exists. One element of the result has typeexpectedType.This method is intended only for use by the framework. A checker implementation should use getElementValue(AnnotationMirror, ExecutableElement, Class, Object).- Type Parameters:
- T- the class of the component type
- Parameters:
- anno- the annotation whose element to access
- elementName- the name of the element to access
- expectedType- the component type of the element and of the return value
- useDefaults- whether to apply default values to the element
- Returns:
- the value of the element with the given name, or null
 
- 
getElementValueEnum@Deprecated public static <T extends Enum<T>> T getElementValueEnum(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) Deprecated.Get the element with the namenameof the annotationanno. The result is an enum of typeT.This method is intended only for use by the framework. A checker implementation should use getElementValueEnum(AnnotationMirror, ExecutableElement, Class)orgetElementValueEnum(AnnotationMirror, ExecutableElement, Class, Enum).- Type Parameters:
- T- the class of the type
- Parameters:
- anno- the annotation to disassemble
- elementName- the name of the element to access
- expectedType- the type of the element and the return value, an enum
- useDefaults- whether to apply default values to the element
- Returns:
- the value of the element with the given name
 
- 
getElementValueArray@Deprecated public 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)Get the element with the nameelementNameof the annotationanno, where the element has an array type. One element of the result has typeexpectedType.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).- Type Parameters:
- T- the class of the type
- Parameters:
- anno- the annotation to disassemble
- elementName- the name of the element to access
- expectedType- the component type of the element and of the return type
- useDefaults- whether to apply default values to the element
- Returns:
- the value of the element with the given name; it is a new list, so it is safe for clients to side-effect
 
- 
getElementValueEnumArray@Deprecated public static <T extends Enum<T>> T[] getElementValueEnumArray(AnnotationMirror anno, CharSequence elementName, Class<T> expectedType, boolean useDefaults) Deprecated.Get the element with the nameelementNameof the annotationanno, or the default value if no element is present explicitly, where the element has an array type and the elements areEnums. One element of the result has typeexpectedType.This method is intended only for use by the framework. A checker implementation should use getElementValueEnumArray(AnnotationMirror, ExecutableElement, Class)orgetElementValueEnumArray(AnnotationMirror, ExecutableElement, Class, Enum[]).- Type Parameters:
- T- the class of the type
- Parameters:
- anno- the annotation to disassemble
- elementName- the name of the element to access
- expectedType- the component type of the element and of the return type, an enum
- useDefaults- whether to apply default values to the element
- Returns:
- the value of the element with the given name
 
- 
getElementValueClassName@Deprecated public static @CanonicalName Name getElementValueClassName(AnnotationMirror anno, CharSequence elementName, boolean useDefaults) Deprecated.use an ExecutableElementGet the Name of the class that is referenced by elementelementName.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();.- Parameters:
- anno- the annotation to disassemble
- elementName- the name of the element to access; it must be present in the annotation
- useDefaults- whether to apply default values to the element
- Returns:
- the name of the class that is referenced by element with the given name; may be an empty name, for a local or anonymous class
 
- 
getElementValueClassNames@Deprecated public static List<@CanonicalName Name> getElementValueClassNames(AnnotationMirror anno, CharSequence annoElement, boolean useDefaults) Deprecated.Get the list of Names of the classes that are referenced by elementelementName. 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).- Parameters:
- anno- the annotation whose field to access; it must be present in the annotation
- annoElement- the element/field of- annowhose content is a list of classes
- useDefaults- whether to apply default values to the element
- Returns:
- the names of classes in anno.annoElement
 
- 
getElementValuepublic static <T> @Nullable T getElementValue(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType) Get the given element of the annotationanno. The result has typeexpectedType.If the return type is primitive, use getElementValueInt(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.ExecutableElement)orgetElementValueLong(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.- Type Parameters:
- T- the class of the type
- Parameters:
- anno- the annotation whose element to access
- element- the element to access; it must be present in the annotation
- expectedType- the type of the element and the return value
- Returns:
- the value of the element with the given name
 
- 
getElementValuepublic static <T> @Nullable T getElementValue(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, T defaultValue) Get the given element of the annotationanno. The result has typeexpectedType.If the return type is primitive, use getElementValueInt(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.ExecutableElement)orgetElementValueLong(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.- Type Parameters:
- T- the class of the type
- Parameters:
- anno- the annotation whose element to access
- element- the element to access
- expectedType- the type of the element and the return value
- defaultValue- the value to return if the element is not present
- Returns:
- the value of the element with the given name
 
- 
getElementValueBooleanpublic static boolean getElementValueBoolean(AnnotationMirror anno, ExecutableElement element, boolean defaultValue) Get the given boolean element of the annotationanno.- Parameters:
- anno- the annotation whose element to access
- element- the element to access
- defaultValue- the value to return if the element is not present
- Returns:
- the value of the element with the given name
 
- 
getElementValueIntGet the given integer element of the annotationanno.- Parameters:
- anno- the annotation whose element to access
- element- the element to access
- Returns:
- the value of the element with the given name
 
- 
getElementValueIntpublic static int getElementValueInt(AnnotationMirror anno, ExecutableElement element, int defaultValue) Get the given integer element of the annotationanno.- Parameters:
- anno- the annotation whose element to access
- element- the element to access
- defaultValue- the value to return if the element is not present
- Returns:
- the value of the element with the given name
 
- 
getElementValueLongpublic static long getElementValueLong(AnnotationMirror anno, ExecutableElement element, long defaultValue) Get the given long element of the annotationanno.- Parameters:
- anno- the annotation whose element to access
- element- the element to access
- defaultValue- the value to return if the element is not present
- Returns:
- the value of the element with the given name
 
- 
getElementValueEnumpublic static <T extends Enum<T>> T getElementValueEnum(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType) Get the element with the namenameof the annotationanno. The result is an enum of typeT.- Type Parameters:
- T- the class of the type
- Parameters:
- anno- the annotation to disassemble
- element- the element to access; it must be present in the annotation
- expectedType- the type of the element and the return value, an enum
- Returns:
- the value of the element with the given name
 
- 
getElementValueEnumpublic static <T extends Enum<T>> T getElementValueEnum(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, T defaultValue) Get the element with the namenameof the annotationanno. The result is an enum of typeT.- Type Parameters:
- T- the class of the type
- Parameters:
- anno- the annotation to disassemble
- element- the element to access
- expectedType- the type of the element and the return value, an enum
- defaultValue- the value to return if the element is not present
- Returns:
- the value of the element with the given name
 
- 
getElementValueEnumArraypublic static <T extends Enum<T>> T[] getElementValueEnumArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType) Get the element with the namenameof the annotationanno. The result is an array of typeT.- Type Parameters:
- T- the enum class of the component type
- Parameters:
- anno- the annotation to disassemble
- element- the element to access; it must be present in the annotation
- expectedType- the component type of the element and of the return value, an enum
- Returns:
- the value of the element with the given name
 
- 
getElementValueEnumArraypublic static <T extends Enum<T>> T[] getElementValueEnumArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, T[] defaultValue) Get the element with the namenameof the annotationanno. The result is an array of typeT.- Type Parameters:
- T- the enum class of the component type
- Parameters:
- anno- the annotation to disassemble
- element- the element to access
- expectedType- the component type of the element and of the return type
- defaultValue- the value to return if the annotation does not have the element
- Returns:
- the value of the element with the given name
 
- 
getElementValueArraypublic static <T> List<T> getElementValueArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType) Get the given element of the annotationanno, where the element has an array type. One element of the result has typeexpectedType.- Type Parameters:
- T- the class of the component type
- Parameters:
- anno- the annotation to disassemble
- element- the element to access; it must be present in the annotation
- expectedType- the component type of the element and of the return type
- Returns:
- the value of the element with the given name; it is a new list, so it is safe for clients to side-effect
 
- 
getElementValueArraypublic static <T> List<T> getElementValueArray(AnnotationMirror anno, ExecutableElement element, Class<T> expectedType, List<T> defaultValue) Get the given element of the annotationanno, where the element has an array type. One element of the result has typeexpectedType.- Type Parameters:
- T- the class of the component type
- Parameters:
- anno- the annotation to disassemble
- element- the element to access
- expectedType- the component type of the element and of the return type
- defaultValue- the value to return if the element is not present
- Returns:
- the value of the element with the given name; it is a new list, so it is safe for clients to side-effect
 
- 
annotationValueListToEnumArraypublic static <T extends Enum<T>> T[] annotationValueListToEnumArray(AnnotationValue avList, Class<T> expectedType) Converts a list of AnnotationValue to an array of enum.- Type Parameters:
- T- the element type of the enum array
- Parameters:
- avList- a list of AnnotationValue
- expectedType- the component type of the element and of the return type, an enum
- Returns:
- an array of enum, converted from the input list
 
- 
annotationValueListToEnumArraypublic static <T extends Enum<T>> T[] annotationValueListToEnumArray(List<AnnotationValue> la, Class<T> expectedType) Converts a list of AnnotationValue to an array of enum.- Type Parameters:
- T- the element type of the enum array
- Parameters:
- la- a list of AnnotationValue
- expectedType- the component type of the element and of the return type, an enum
- Returns:
- an array of enum, converted from the input list
 
- 
getElementValueClassNamepublic static @CanonicalName Name getElementValueClassName(AnnotationMirror anno, ExecutableElement element) Get the Name of the class that is referenced by elementelement.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();.- Parameters:
- anno- the annotation to disassemble
- element- the element to access; it must be present in the annotation
- Returns:
- the name of the class that is referenced by element with the given name; may be an empty name, for a local or anonymous class
 
- 
getElementValueClassNamespublic static List<@CanonicalName Name> getElementValueClassNames(AnnotationMirror anno, ExecutableElement element) Get the list of Names of the classes that are referenced by elementelement. It fails if the class wasn't found.- Parameters:
- anno- the annotation whose field to access; it must be present in the annotation
- element- the element/field of- annowhose content is a list of classes
- Returns:
- the names of classes in anno.annoElement
 
- 
sameElementValuesReturns true if the two annotations have the same elements (fields). The argumentsam1andam2must be the same type of annotation.- Parameters:
- am1- the first AnnotationMirror to compare
- am2- the second AnnotationMirror to compare
- Returns:
- true if the two annotations have the same elements (fields)
 
- 
sameAnnotationValueReturn true iff the two AnnotationValue objects are the same. Use this instead of CheckerFrameworkAnnotationValue.equals, which wouldn't get called if the receiver is some AnnotationValue other than CheckerFrameworkAnnotationValue.- Parameters:
- av1- the first AnnotationValue to compare
- av2- the second AnnotationValue to compare
- Returns:
- true if the two annotation values are the same
 
- 
annotationValueContainsReturns true if an AnnotationValue list contains the given value.Using this method is slightly cheaper than creating a new List<String>just for the purpose of testing containment within it.- Parameters:
- avList- an AnnotationValue that is null or a list of Strings
- s- a string
- Returns:
- true if avcontainss
 
- 
annotationValueContainsReturns true if an AnnotationValue list contains the given value.Using this method is slightly cheaper than creating a new List<String>just for the purpose of testing containment within it.- Parameters:
- avList- a list of Strings (as- AnnotationValues)
- s- a string
- Returns:
- true if avcontainss
 
- 
annotationValueContainsToStringReturns true if an AnnotationValue list contains a value whosetoString()is the given string.Using this method is slightly cheaper than creating a new Listjust for the purpose of testing containment within it.- Parameters:
- avList- an AnnotationValue that is null or a list
- s- a string
- Returns:
- true if avcontainss
 
- 
annotationValueContainsToStringpublic static boolean annotationValueContainsToString(List<? extends AnnotationValue> avList, String s) Returns true if an AnnotationValue list contains a value whosetoString()is the given string.Using this method is slightly cheaper than creating a new Listjust for the purpose of testing containment within it.- Parameters:
- avList- a list of Strings (as- AnnotationValues)
- s- a string
- Returns:
- true if avcontainss
 
- 
annotationValueToListConverts an annotation value to a list.To test containment, use annotationValueContains(AnnotationValue, String)orannotationValueContainsToString(AnnotationValue, String).- Type Parameters:
- T- the class of the type
- Parameters:
- avList- an AnnotationValue that is null or a list of Strings
- expectedType- the component type of the argument and of the return type, an enum
- Returns:
- the annotation value, converted to a list
 
- 
annotationValueToListpublic static <T> List<T> annotationValueToList(List<? extends AnnotationValue> avList, Class<T> expectedType) Converts an annotation value to a list.To test containment, use annotationValueContains(List, String)orannotationValueContainsToString(List, String).- Type Parameters:
- T- the class of the type
- Parameters:
- avList- a list of Strings (as- AnnotationValues)
- expectedType- the component type of the argument and of the return type, an enum
- Returns:
- the annotation value, converted to a list
 
- 
updateMappingToImmutableSetpublic static <T extends @NonNull Object> void updateMappingToImmutableSet(Map<T, AnnotationMirrorSet> map, T key, AnnotationMirrorSet newQual) Update a map, to addnewQualto the set thatkeymaps to. The mapped-to element is an unmodifiable set.See org.checkerframework.framework.type.QualifierHierarchy#updateMappingToMutableSet(QualifierHierarchy, Map, Object, AnnotationMirror). - Type Parameters:
- T- the key type
- Parameters:
- map- the map to update
- key- the key whose value to update
- newQual- the element to add to the given key's value
 
- 
getExplicitAnnotationsOnConstructorResultpublic static AnnotationMirrorSet getExplicitAnnotationsOnConstructorResult(MethodTree constructorDeclaration) Returns the annotations explicitly written on a constructor result. Callers should check thatconstructorDeclarationis in fact a declaration of a constructor.- Parameters:
- constructorDeclaration- declaration tree of constructor
- Returns:
- set of annotations explicit on the resulting type of the constructor
 
- 
isDeclarationAnnotationReturns true if anno is a declaration annotation. In other words, returns true if anno cannot be written on uses of types.- Parameters:
- anno- the AnnotationMirror
- Returns:
- true if anno is a declaration annotation
 
- 
hasTypeQualifierElementTypesReturns true if the given array containsElementType.TYPE_USE, false otherwise.- Parameters:
- elements- an array of- ElementTypevalues
- cls- the annotation class being tested; used for diagnostic messages only
- Returns:
- true iff the give array contains ElementType.TYPE_USE
- Throws:
- RuntimeException- if the array contains both- ElementType.TYPE_USEand something besides- ElementType.TYPE_PARAMETER
 
- 
toStringSimpleReturns a string representation of the annotation mirrors, using simple (not fully-qualified) names.- Parameters:
- annos- annotations to format
- Returns:
- the string representation, using simple (not fully-qualified) names
 
- 
annotationMirrorToClassConverts an AnnotationMirror to a Class. Throws an exception if it is not able to do so.- Parameters:
- am- an AnnotationMirror
- Returns:
- the Class corresponding to the given AnnotationMirror
 
 
- 
AnnotatedTypeFactory#areSameByClassorareSameByName(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)