public class AnnotationUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static @Interned java.lang.String |
annotationName(javax.lang.model.element.AnnotationMirror annotation) |
static java.util.Comparator<javax.lang.model.element.AnnotationMirror> |
annotationOrdering()
provide ordering for
AnnotationMirror based on their fully qualified name. |
static java.lang.String |
annotationSimpleName(javax.lang.model.element.AnnotationMirror annotation)
Deprecated.
|
static boolean |
areSame(@Nullable javax.lang.model.element.AnnotationMirror a1,
@Nullable javax.lang.model.element.AnnotationMirror a2)
Checks if both annotations are the same.
|
static boolean |
areSame(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c1,
java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c2)
Checks that two collections contain the same annotations.
|
static boolean |
areSameByClass(javax.lang.model.element.AnnotationMirror am,
java.lang.Class<? extends java.lang.annotation.Annotation> anno)
Checks that the annotation
am has the name of anno. |
static boolean |
areSameByName(javax.lang.model.element.AnnotationMirror am,
@Interned java.lang.String aname)
Checks that the annotation
am has the name aname. |
static boolean |
areSameIgnoringValues(javax.lang.model.element.AnnotationMirror a1,
javax.lang.model.element.AnnotationMirror a2) |
static void |
clear() |
static boolean |
containsSame(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
javax.lang.model.element.AnnotationMirror anno)
Checks that the collection contains the annotation.
|
static boolean |
containsSameByClass(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
java.lang.Class<? extends java.lang.annotation.Annotation> anno)
Checks that the collection contains the annotation.
|
static boolean |
containsSameByName(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
@Interned java.lang.String anno)
Checks that the collection contains the annotation.
|
static boolean |
containsSameIgnoringValues(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
javax.lang.model.element.AnnotationMirror anno)
Checks that the collection contains the annotation ignoring values.
|
static <V> java.util.Map<javax.lang.model.element.AnnotationMirror,V> |
createAnnotationMap()
Create a map suitable for storing
AnnotationMirror as keys. |
static java.util.Set<javax.lang.model.element.AnnotationMirror> |
createAnnotationSet()
Constructs a
Set suitable for storing AnnotationMirrors. |
static javax.lang.model.element.AnnotationMirror |
fromClass(javax.lang.model.util.Elements elements,
java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Deprecated.
use
AnnotationBuilder.fromClass(Elements,Class) instead. |
static javax.lang.model.element.AnnotationMirror |
fromName(javax.lang.model.util.Elements elements,
java.lang.CharSequence name)
Deprecated.
use
AnnotationBuilder.fromName(Elements,CharSequence) instead. |
static javax.lang.model.element.AnnotationMirror |
getAnnotationByClass(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
java.lang.Class<? extends java.lang.annotation.Annotation> anno)
Returns the AnnotationMirror in
c that has the same class as anno. |
static javax.lang.model.element.AnnotationMirror |
getAnnotationByName(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
@Interned java.lang.String anno)
Returns the AnnotationMirror in
c that has the same name as anno. |
static <T> T |
getElementValue(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
java.lang.Class<T> expectedType,
boolean useDefaults)
Get the attribute with the name
name of the annotation anno. |
static <T> java.util.List<T> |
getElementValueArray(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
java.lang.Class<T> expectedType,
boolean useDefaults)
Get the attribute with the name
name of the annotation anno, where the
attribute has an array type. |
static java.lang.Class<?> |
getElementValueClass(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
boolean useDefaults)
Get the Class that is referenced by attribute
name. |
static javax.lang.model.element.Name |
getElementValueClassName(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
boolean useDefaults)
Get the Name of the class that is referenced by attribute
name. |
static java.util.List<javax.lang.model.element.Name> |
getElementValueClassNames(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
boolean useDefaults)
Get the list of Names of the classes that are referenced by attribute
name. |
static <T extends java.lang.Enum<T>> |
getElementValueEnum(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
java.lang.Class<T> t,
boolean useDefaults)
Version that is suitable for Enum elements.
|
static <T extends java.lang.Enum<T>> |
getElementValueEnumArray(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
java.lang.Class<T> t,
boolean useDefaults)
Get the attribute with the name
name of the annotation anno, or the default
value if no attribute is present explicitly, where the attribute has an array type and the
elements are Enums. |
static java.util.Map<? extends javax.lang.model.element.ExecutableElement,? extends javax.lang.model.element.AnnotationValue> |
getElementValuesWithDefaults(javax.lang.model.element.AnnotationMirror ad)
Returns the values of an annotation's attributes, including defaults.
|
static java.util.Set<javax.lang.model.element.AnnotationMirror> |
getExplicitAnnotationsOnConstructorResult(com.sun.source.tree.MethodTree constructorDeclaration)
Returns the annotations explicitly written on a constructor result.
|
static javax.lang.model.element.AnnotationMirror |
getSame(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
javax.lang.model.element.AnnotationMirror anno)
Returns the AnnotationMirror in
c that is the same annotation as anno. |
static javax.lang.model.element.AnnotationMirror |
getSameIgnoringValues(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
javax.lang.model.element.AnnotationMirror anno)
Returns the AnnotationMirror in
c that is the same annotation as anno
ignoring values. |
static <T> boolean |
hasElementValue(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name)
Verify whether the attribute with the name
name exists in the annotation anno. |
static boolean |
hasInheritedMeta(javax.lang.model.element.AnnotationMirror anno)
Returns true if the given annotation has a @Inherited meta-annotation.
|
static <T> void |
updateMappingToImmutableSet(java.util.Map<T,java.util.Set<javax.lang.model.element.AnnotationMirror>> map,
T key,
java.util.Set<javax.lang.model.element.AnnotationMirror> newQual)
See checkers.types.QualifierHierarchy#updateMappingToMutableSet(QualifierHierarchy, Map,
Object, AnnotationMirror) (Not linked because it is in an independent project.
|
public static void clear()
public static final @Interned java.lang.String annotationName(javax.lang.model.element.AnnotationMirror annotation)
@Deprecated public static java.lang.String annotationSimpleName(javax.lang.model.element.AnnotationMirror annotation)
public static boolean areSame(@Nullable javax.lang.model.element.AnnotationMirror a1, @Nullable javax.lang.model.element.AnnotationMirror a2)
Returns 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).
public static boolean areSameIgnoringValues(javax.lang.model.element.AnnotationMirror a1,
javax.lang.model.element.AnnotationMirror a2)
areSame(AnnotationMirror, AnnotationMirror)public static boolean areSameByName(javax.lang.model.element.AnnotationMirror am,
@Interned java.lang.String aname)
am has the name aname. Values are ignored.public static boolean areSameByClass(javax.lang.model.element.AnnotationMirror am,
java.lang.Class<? extends java.lang.annotation.Annotation> anno)
am has the name of anno. Values are ignored.public static boolean areSame(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c1,
java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c2)
public static boolean containsSame(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
javax.lang.model.element.AnnotationMirror anno)
public static javax.lang.model.element.AnnotationMirror getSame(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
javax.lang.model.element.AnnotationMirror anno)
c that is the same annotation as anno.anno iff c contains anno, according
to areSame; otherwise, nullpublic static boolean containsSameByClass(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
java.lang.Class<? extends java.lang.annotation.Annotation> anno)
public static javax.lang.model.element.AnnotationMirror getAnnotationByClass(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
java.lang.Class<? extends java.lang.annotation.Annotation> anno)
c that has the same class as anno.anno iff c contains anno, according
to areSameByClass; otherwise, nullpublic static boolean containsSameByName(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
@Interned java.lang.String anno)
public static javax.lang.model.element.AnnotationMirror getAnnotationByName(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
@Interned java.lang.String anno)
c that has the same name as anno.anno iff c contains anno, according to
areSameByName; otherwise, nullpublic static boolean containsSameIgnoringValues(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
javax.lang.model.element.AnnotationMirror anno)
public static javax.lang.model.element.AnnotationMirror getSameIgnoringValues(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> c,
javax.lang.model.element.AnnotationMirror anno)
c that is the same annotation as anno
ignoring values.anno iff c contains anno, according
to areSameIgnoringValues; otherwise, nullpublic static java.util.Comparator<javax.lang.model.element.AnnotationMirror> annotationOrdering()
AnnotationMirror based on their fully qualified name. The
ordering ignores annotation values when ordering.
The ordering is meant to be used as TreeSet or TreeMap ordering. A Set should not contain two annotations that only differ in values.
public static <V> java.util.Map<javax.lang.model.element.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 java.util.Set<javax.lang.model.element.AnnotationMirror> createAnnotationSet()
Set suitable 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 boolean hasInheritedMeta(javax.lang.model.element.AnnotationMirror anno)
public static java.util.Map<? extends javax.lang.model.element.ExecutableElement,? extends javax.lang.model.element.AnnotationValue> getElementValuesWithDefaults(javax.lang.model.element.AnnotationMirror ad)
ad - annotation to examineAnnotationMirror.getElementValues(),
JavacElements.getElementValuesWithDefaults(AnnotationMirror)public static <T> boolean hasElementValue(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name)
name exists in the annotation anno.anno - the annotation to examinename - the name of the attributepublic static <T> T getElementValue(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
java.lang.Class<T> expectedType,
boolean useDefaults)
name of the annotation anno. The result is
expected to have type expectedType.
Note 1: The method does not work well for attributes of an array type (as it
would return a list of AnnotationValues). Use getElementValueArray instead.
Note 2: The method does not work for attributes of an enum type, as the
AnnotationValue is a VarSymbol and would be cast to the enum type, which doesn't work. Use
getElementValueEnum instead.
anno - the annotation to disassemblename - the name of the attribute to accessexpectedType - the expected type used to cast the return typeuseDefaults - whether to apply default values to the attributepublic static <T extends java.lang.Enum<T>> T getElementValueEnum(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
java.lang.Class<T> t,
boolean useDefaults)
public static <T> java.util.List<T> getElementValueArray(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
java.lang.Class<T> expectedType,
boolean useDefaults)
name of the annotation anno, where the
attribute has an array type. One element of the result is expected to have 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.
anno - the annotation to disassemblename - the name of the attribute to accessexpectedType - the expected type used to cast the return typeuseDefaults - whether to apply default values to the attributepublic static <T extends java.lang.Enum<T>> java.util.List<T> getElementValueEnumArray(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
java.lang.Class<T> t,
boolean useDefaults)
name of the annotation anno, or the default
value if no attribute is present explicitly, where the attribute has an array type and the
elements are Enums. One element of the result is expected to have type expectedType.public static javax.lang.model.element.Name getElementValueClassName(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
boolean useDefaults)
name.
This is a convenience method for the most common use-case. Like getElementValue(anno, name, ClassType.class).getQualifiedName(), but this method ensures consistent use of the qualified name.
public static java.util.List<javax.lang.model.element.Name> getElementValueClassNames(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
boolean useDefaults)
name.public static java.lang.Class<?> getElementValueClass(javax.lang.model.element.AnnotationMirror anno,
java.lang.CharSequence name,
boolean useDefaults)
name. This method uses Class.forName to
load the class. It returns null if the class wasn't found.public static <T> void updateMappingToImmutableSet(java.util.Map<T,java.util.Set<javax.lang.model.element.AnnotationMirror>> map,
T key,
java.util.Set<javax.lang.model.element.AnnotationMirror> newQual)
public static java.util.Set<javax.lang.model.element.AnnotationMirror> getExplicitAnnotationsOnConstructorResult(com.sun.source.tree.MethodTree constructorDeclaration)
constructorDeclaration is in fact a declaration of a constructor.constructorDeclaration - declaration tree of constructor@Deprecated
public static javax.lang.model.element.AnnotationMirror fromName(javax.lang.model.util.Elements elements,
java.lang.CharSequence name)
AnnotationBuilder.fromName(Elements,CharSequence) instead.@Deprecated
public static javax.lang.model.element.AnnotationMirror fromClass(javax.lang.model.util.Elements elements,
java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
AnnotationBuilder.fromClass(Elements,Class) instead.