| Modifier and Type | Class and Description |
|---|---|
static class |
AnnotationUtils.AnnotationBuilder
Builds an annotation mirror that may have some values.
|
| Modifier and Type | Method and Description |
|---|---|
static @Nullable Name |
annotationName(@Nullable AnnotationMirror annotation) |
static Comparator<@Nullable AnnotationMirror> |
annotationOrdering()
provide ordering for
AnnotationMirror based on their fully
qualified name. |
static boolean |
areSame(@Nullable AnnotationMirror a1,
@Nullable AnnotationMirror a2)
Checks if both annotations are the same.
|
static boolean |
areSame(Collection<@Nullable AnnotationMirror> c1,
Collection<@Nullable AnnotationMirror> c2)
Checks that two collections contain the same annotations.
|
static boolean |
areSameIgnoringValues(@Nullable AnnotationMirror a1,
@Nullable AnnotationMirror a2) |
static boolean |
containsSame(Collection<@Nullable AnnotationMirror> c,
@Nullable AnnotationMirror anno)
Checks that the collection contains the annotation.
|
static boolean |
containsSameIgnoringValues(Collection<@Nullable AnnotationMirror> c,
@Nullable AnnotationMirror anno)
Checks that the collection contains the annotation ignoring values.
|
static <V extends @NonNull Object> |
createAnnotationMap()
Create a map suitable for storing
AnnotationMirror as keys. |
static Set<@Nullable AnnotationMirror> |
createAnnotationSet()
Constructs a
Set suitable for storing AnnotationMirrors. |
static <T extends @NonNull Object> |
elementValue(@Nullable AnnotationMirror anno,
CharSequence name,
Class<T> expectedType)
Get the attribute with the name
name of the annotation
anno. |
static <T extends @NonNull Object> |
elementValueArray(@Nullable AnnotationMirror anno,
CharSequence name)
Get the attribute with the name
name of the annotation
anno, where the attribute has an array type. |
static <T extends @NonNull Object> |
elementValueArrayWithDefaults(@Nullable AnnotationMirror anno,
CharSequence name)
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. |
static @ReadOnly String |
elementValueClassName(@Nullable AnnotationMirror anno,
CharSequence name)
name is an annotation field of type Class, and this gives its name.
|
static <T extends Enum<T>> |
elementValueEnumArrayWithDefaults(@Nullable AnnotationMirror anno,
CharSequence name,
Class<T> t)
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 <T extends @NonNull Object> |
elementValueWithDefaults(@Nullable AnnotationMirror anno,
CharSequence name,
Class<T> expectedType)
Get the attribute with the name
name of the annotation
anno, or the default value if no attribute is present explicitly. |
Map<TypeElement,Set<DefaultLocation>> |
findDefaultLocations(@Nullable Element elt)
Finds default annotations starting at the given element, inspecting the
element and its enclosing method and class declarations for
DefaultQualifier annotations. |
Map<TypeElement,Set<DefaultLocation>> |
findDefaultLocations(@Nullable TreePath path)
Finds default annotations starting at the leaf of the given tree path by
inspecting enclosing variable, method, and class declarations for
DefaultQualifier annotations. |
@Nullable AnnotationMirror |
fromClass(Class<? extends Annotation> clazz)
Creates an
AnnotationMirror given by a particular annotation
class. |
@Nullable AnnotationMirror |
fromName(CharSequence name)
Creates an
AnnotationMirror given by a particular
fully-qualified name. |
@Nullable AnnotationMirror |
fromName(@ReadOnly String name)
Creates an
AnnotationMirror given by a particular
fully-qualified name. |
static Map<? extends @NonNull ExecutableElement,? extends AnnotationValue> |
getElementValuesWithDefaults(@Nullable AnnotationMirror ad)
Returns the values of an annotation's elements, including defaults.
|
static AnnotationUtils |
getInstance(ProcessingEnvironment env) |
static boolean |
hasInheritedMeta(@Nullable AnnotationMirror anno)
Returns true if the given annotation has a @Inherited meta-annotation.
|
static <R extends Enum<R>> |
parseEnumConstantArrayValue(@Nullable AnnotationMirror ad,
@ReadOnly String field,
Class<R> enumType) |
static <@Nullable R extends Enum<@Nullable R>> |
parseEnumConstantValue(@Nullable AnnotationMirror ad,
@ReadOnly String field,
Class<@Nullable R> enumType) |
static @Nullable List<@ReadOnly String> |
parseStringArrayValue(@Nullable AnnotationMirror ad,
@ReadOnly String field) |
static @ReadOnly String |
parseStringValue(@Nullable AnnotationMirror ad,
@ReadOnly String field) |
static @Nullable Class<?> |
parseTypeValue(@Nullable AnnotationMirror ad,
@ReadOnly String field) |
static <T extends @NonNull Object> |
updateMappingToImmutableSet(Map<T,Set<@Nullable AnnotationMirror>> map,
T key,
Set<@Nullable AnnotationMirror> newQual) |
static <T extends @NonNull Object> |
updateMappingToMutableSet(QualifierHierarchy qualHierarchy,
Map<T,Set<@Nullable AnnotationMirror>> map,
T key,
@Nullable AnnotationMirror newQual)
Update a mapping from some key to a set of AnnotationMirrors.
|
public static AnnotationUtils getInstance(ProcessingEnvironment env)
public @Nullable AnnotationMirror fromName(CharSequence name)
AnnotationMirror given by a particular
fully-qualified name.name - the name of the annotation to createAnnotationMirror of type namepublic @Nullable AnnotationMirror fromName(@ReadOnly String name)
AnnotationMirror given by a particular
fully-qualified name. getElementValues on the result returns an
empty map.name - the name of the annotation to createAnnotationMirror of type namepublic @Nullable AnnotationMirror fromClass(Class<? extends Annotation> clazz)
AnnotationMirror given by a particular annotation
class.clazz - the annotation classAnnotationMirror of type given typepublic Map<TypeElement,Set<DefaultLocation>> findDefaultLocations(@Nullable TreePath path)
DefaultQualifier annotations.path - the tree path from which to start searchingTypeElements) to the
DefaultLocations for those annotationsfindDefaultLocations(Element)public Map<TypeElement,Set<DefaultLocation>> findDefaultLocations(@Nullable Element elt)
DefaultQualifier annotations.elt - the element from which to start searchingTypeElements) to the
DefaultLocations for those annotationsfindDefaultLocations(TreePath)public static Map<? extends @NonNull ExecutableElement,? extends AnnotationValue> getElementValuesWithDefaults(@Nullable AnnotationMirror ad)
ad - annotation to examineAnnotationMirror.getElementValues()public static <@Nullable R extends Enum<@Nullable R>> @Nullable R parseEnumConstantValue(@Nullable AnnotationMirror ad, @ReadOnly String field, Class<@Nullable R> enumType)
R - the enum typead - the annotation for which a value will be parsedfield - the name of the field to parseenumType - the type of the enumpublic static <R extends Enum<R>> @Nullable Set<R> parseEnumConstantArrayValue(@Nullable AnnotationMirror ad, @ReadOnly String field, Class<R> enumType)
R - the enum typead - the annotation for which a value will be parsedfield - the name of the field to parseenumType - the type of the enumpublic static @ReadOnly String parseStringValue(@Nullable AnnotationMirror ad, @ReadOnly String field)
ad - the annotation for which a value will be parsedfield - the name of the field to parsepublic static @Nullable List<@ReadOnly String> parseStringArrayValue(@Nullable AnnotationMirror ad, @ReadOnly String field)
ad - the annotation for which a value will be parsedfield - the name of the field to parsepublic static @Nullable Class<?> parseTypeValue(@Nullable AnnotationMirror ad, @ReadOnly String field)
ad - the annotation for which a value will be parsedfield - the name of the field to parsepublic static final @Nullable Name annotationName(@Nullable AnnotationMirror annotation)
public static boolean areSame(@Nullable AnnotationMirror a1, @Nullable AnnotationMirror a2)
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(@Nullable AnnotationMirror a1, @Nullable AnnotationMirror a2)
areSame(AnnotationMirror, AnnotationMirror)public static boolean areSame(Collection<@Nullable AnnotationMirror> c1, Collection<@Nullable AnnotationMirror> c2)
public static boolean containsSame(Collection<@Nullable AnnotationMirror> c, @Nullable AnnotationMirror anno)
public static boolean containsSameIgnoringValues(Collection<@Nullable AnnotationMirror> c, @Nullable AnnotationMirror anno)
public static Comparator<@Nullable 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 extends @NonNull Object> Map<@Nullable 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 Set<@Nullable 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 <T extends @NonNull Object> T elementValue(@Nullable AnnotationMirror anno, CharSequence name, Class<T> expectedType)
name of the annotation
anno. The result is expected to have type expectedType.
Note 1: The method only returns attribute values that are
explicitly present on anno. Default values are ignored. If
default values should be applied, use elementValueWithDefaults
instead.
Note 2: The method does not work well for attributes of an array
type (as it would return a list of AnnotationValues). Use
elementValueArray instead. instead.
public static <T extends @NonNull Object> T elementValueWithDefaults(@Nullable AnnotationMirror anno, CharSequence name, Class<T> expectedType)
name of the annotation
anno, or the default value if no attribute is present explicitly.
The result is expected to have type expectedType.
Note: The method does not work well for attributes of an array
type (as it would return a list of AnnotationValues). Use
elementValueArray instead. instead.
public static <T extends @NonNull Object> List<T> elementValueArray(@Nullable AnnotationMirror anno, CharSequence name)
name of the annotation
anno, where the attribute has an array type. One element of the
result is expected to have type expectedType.
Note: The method only returns attribute values that are
explicitly present on anno. Default values are ignored. If
default values should be applied, use
elementValueArrayWithDefaults instead.
public static <T extends @NonNull Object> List<T> elementValueArrayWithDefaults(@Nullable AnnotationMirror anno, CharSequence name)
name of the annotation
anno, or the default value if no attribute is present explicitly,
where the attribute has an array type. One element of the result is
expected to have type expectedType.public static <T extends Enum<T>> List<T> elementValueEnumArrayWithDefaults(@Nullable AnnotationMirror anno, CharSequence name, Class<T> t)
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 @ReadOnly String elementValueClassName(@Nullable AnnotationMirror anno, CharSequence name)
public static boolean hasInheritedMeta(@Nullable AnnotationMirror anno)
public static <T extends @NonNull Object> boolean updateMappingToMutableSet(QualifierHierarchy qualHierarchy, Map<T,Set<@Nullable AnnotationMirror>> map, T key, @Nullable AnnotationMirror newQual)
map - The mapping to modify.key - The key to update.newQual - The value to add.public static <T extends @NonNull Object> void updateMappingToImmutableSet(Map<T,Set<@Nullable AnnotationMirror>> map, T key, Set<@Nullable AnnotationMirror> newQual)