Interface AnnotationUtils
-
-
Field Summary
Fields Modifier and Type Field Description static javax.lang.model.element.AnnotationValueVisitor<java.lang.Object,javax.lang.model.element.ExecutableElement>
DEFAULT_ANNOTATION_VALUE_VISITOR
The defaultAnnotationValueVisitor
static java.lang.annotation.ElementType[]
EMPTY_ELEMENT_TYPE_ARRAY
The emptyElementType
arraystatic java.lang.String
VALUE_ATTRIBUTE_NAME
The name of the attribute method : value()static boolean
WITH_DEFAULT
-
Method Summary
Static Methods Modifier and Type Method Description static java.util.List<javax.lang.model.element.AnnotationMirror>
findAllAnnotations(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.CharSequence annotatedTypeName, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances of the specified annotated type name from the givenProcessingEnvironment
.static java.util.List<javax.lang.model.element.AnnotationMirror>
findAllAnnotations(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances of the specified annotated type from the givenProcessingEnvironment
.static java.util.List<javax.lang.model.element.AnnotationMirror>
findAllAnnotations(javax.lang.model.element.Element element, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances from the givenElement
, applying the specified annotation filters to narrow down the results.static java.util.List<javax.lang.model.element.AnnotationMirror>
findAllAnnotations(javax.lang.model.element.TypeElement element, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
static java.util.List<javax.lang.model.element.AnnotationMirror>
findAllAnnotations(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances from the givenTypeMirror
, applying the specified annotation filters to narrow down the results.static javax.lang.model.element.AnnotationMirror
findAnnotation(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
Retrieves the firstAnnotationMirror
of the specified annotation class name from the givenElement
.static javax.lang.model.element.AnnotationMirror
findAnnotation(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves the firstAnnotationMirror
of the specified annotation class from the givenElement
.static javax.lang.model.element.AnnotationMirror
findAnnotation(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)
Retrieves the firstAnnotationMirror
of the specified annotation class name from the givenTypeMirror
.static javax.lang.model.element.AnnotationMirror
findAnnotation(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves the firstAnnotationMirror
of the specified annotation class from the givenTypeMirror
.static java.util.List<javax.lang.model.element.AnnotationMirror>
findAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances from the givenAnnotatedConstruct
that match the provided annotation filters.static javax.lang.model.element.AnnotationMirror
findMetaAnnotation(javax.lang.model.element.Element annotatedConstruct, java.lang.CharSequence metaAnnotationClassName)
Retrieves the first meta-annotation of the specified meta-annotation class name from the given annotated element.static javax.lang.model.element.AnnotationMirror
findMetaAnnotation(javax.lang.model.element.Element annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationClass)
Retrieves the first meta-annotation of the specified annotation class from the given annotated element.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType)
Retrieves allAnnotationMirror
instances of the specified annotated type from the givenProcessingEnvironment
.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.lang.model.element.Element element)
Retrieves allAnnotationMirror
instances from the givenElement
.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
Retrieves allAnnotationMirror
instances of the specified annotation class name from the givenElement
.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves allAnnotationMirror
instances of the specified annotation class from the givenElement
.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.lang.model.type.TypeMirror type)
Retrieves allAnnotationMirror
instances from the givenTypeMirror
.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)
Retrieves allAnnotationMirror
instances of the specified annotation class name from the givenTypeMirror
.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves allAnnotationMirror
instances of the specified annotation class from the givenTypeMirror
.static javax.lang.model.element.AnnotationMirror
getAnnotation(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)
Retrieves the firstAnnotationMirror
of the specified annotation class name from the givenAnnotatedConstruct
.static javax.lang.model.element.AnnotationMirror
getAnnotation(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves the firstAnnotationMirror
of the specified annotation class from the givenAnnotatedConstruct
.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct)
Retrieves allAnnotationMirror
instances from the givenAnnotatedConstruct
.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)
Retrieves allAnnotationMirror
instances of the specified annotation class name from the givenAnnotatedConstruct
.static java.util.List<javax.lang.model.element.AnnotationMirror>
getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves allAnnotationMirror
instances of the specified annotation class from the givenAnnotatedConstruct
.static <T> T
getAttribute(java.util.Map.Entry<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> elementValue)
Retrieves the value of the specified attribute from the provided entry containing the attribute method and its corresponding annotation value.static <T> T
getAttribute(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName)
Retrieves the value of the specified attribute from the given annotation.static <T> T
getAttribute(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName, boolean withDefault)
Retrieves the value of the specified attribute from the given annotation, optionally including the default value.static java.lang.String
getAttributeName(javax.lang.model.element.ExecutableElement attributeMethod)
Retrieves the name of the attribute method from the givenExecutableElement
.static java.util.Map<java.lang.String,java.lang.Object>
getAttributesMap(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Get the attributes map from the specified annotationstatic java.util.Map<java.lang.String,java.lang.Object>
getAttributesMap(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, boolean withDefault)
Get the attributes map from the specified annotationstatic java.util.Map<java.lang.String,java.lang.Object>
getAttributesMap(javax.lang.model.element.AnnotationMirror annotation)
Get the attributes map from the specified annotationstatic java.util.Map<java.lang.String,java.lang.Object>
getAttributesMap(javax.lang.model.element.AnnotationMirror annotation, boolean withDefault)
Get the attributes map from the specified annotationstatic java.lang.annotation.ElementType[]
getElementTypes(javax.lang.model.element.AnnotationMirror annotation)
Retrieves theElementType
array from the specified annotation.static java.lang.annotation.ElementType[]
getElementTypes(javax.lang.model.type.DeclaredType annotationType)
Retrieves theElementType
array from the specified annotation type by checking theTarget
annotation associated with it.static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>
getElementValue(java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> elementValues, java.lang.String attributeName)
Retrieves the attribute method and its corresponding annotation value from the specified element values map based on the given attribute name.static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>
getElementValue(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName, boolean withDefault)
Retrieves the attribute method and its corresponding annotation value from the specified annotation based on the given attribute name.static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>
getElementValues(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves the map of annotation attribute methods to their corresponding values from the specifiedAnnotatedConstruct
and annotation class.static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>
getElementValues(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, boolean withDefault)
Retrieves the map of annotation attribute methods to their corresponding values from the specifiedAnnotatedConstruct
and annotation class.static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>
getElementValues(javax.lang.model.element.AnnotationMirror annotation)
Retrieves a map of annotation attribute methods to their corresponding values from the specifiedAnnotationMirror
.static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>
getElementValues(javax.lang.model.element.AnnotationMirror annotation, boolean withDefault)
Retrieves a map of annotation attribute methods to their corresponding values from the specifiedAnnotationMirror
.static <T> T
getValue(javax.lang.model.element.AnnotationMirror annotation)
Retrieves the value of the specified annotation by accessing the default attribute method named"value"
.static boolean
isAnnotationPresent(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
Checks if the specified annotation (by class name) is present on the given element, either directly or as a meta-annotation.static boolean
isAnnotationPresent(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Checks if the specified annotation is present on the given element, either directly or as a meta-annotation.static boolean
matchesAnnotationType(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.reflect.Type annotationType)
Checks if the given annotation mirror has the same type as the specifiedType
.static boolean
matchesAnnotationTypeName(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.CharSequence annotationTypeName)
Checks if the given annotation mirror has the same type as the specified annotation class name.static boolean
matchesAttributeMethod(javax.lang.model.element.ExecutableElement attributeMethod, java.lang.String attributeName)
Checks if the provided executable element represents an annotation attribute method with the specified name.static boolean
matchesAttributeValue(javax.lang.model.element.AnnotationValue annotationValue, java.lang.Object attributeValue)
Checks if the value of the givenAnnotationValue
matches the specified attribute value.
-
-
-
Field Detail
-
VALUE_ATTRIBUTE_NAME
static final java.lang.String VALUE_ATTRIBUTE_NAME
The name of the attribute method : value()- See Also:
- Constant Field Values
-
DEFAULT_ANNOTATION_VALUE_VISITOR
static final javax.lang.model.element.AnnotationValueVisitor<java.lang.Object,javax.lang.model.element.ExecutableElement> DEFAULT_ANNOTATION_VALUE_VISITOR
The defaultAnnotationValueVisitor
-
EMPTY_ELEMENT_TYPE_ARRAY
static final java.lang.annotation.ElementType[] EMPTY_ELEMENT_TYPE_ARRAY
The emptyElementType
array
-
WITH_DEFAULT
static final boolean WITH_DEFAULT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getAnnotation
static javax.lang.model.element.AnnotationMirror getAnnotation(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves the firstAnnotationMirror
of the specified annotation class from the givenAnnotatedConstruct
. If either the construct or the annotation class isnull
, this method returnsnull
.- Parameters:
annotatedConstruct
- the annotated construct to search for annotations, may benull
annotationClass
- the annotation class to look for, may benull
- Returns:
- the first matching
AnnotationMirror
, ornull
if none found
-
getAnnotation
static javax.lang.model.element.AnnotationMirror getAnnotation(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)
Retrieves the firstAnnotationMirror
of the specified annotation class name from the givenAnnotatedConstruct
. If either the construct or the annotation class name isnull
, this method returnsnull
.- Parameters:
annotatedConstruct
- the annotated construct to search for annotations, may benull
annotationClassName
- the fully qualified class name of the annotation to look for, may benull
- Returns:
- the first matching
AnnotationMirror
, ornull
if none found
-
getAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct)
Retrieves allAnnotationMirror
instances from the givenAnnotatedConstruct
. If the annotated construct isnull
, this method returns an empty list.- Parameters:
annotatedConstruct
- the annotated construct to search for annotations, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
getAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves allAnnotationMirror
instances of the specified annotation class from the givenAnnotatedConstruct
. If either the construct or the annotation class isnull
, this method returns an empty list.- Parameters:
annotatedConstruct
- the annotated construct to search for annotations, may benull
annotationClass
- the annotation class to look for, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
getAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)
Retrieves allAnnotationMirror
instances of the specified annotation class name from the givenAnnotatedConstruct
. If either the construct or the annotation class name isnull
, this method returns an empty list.- Parameters:
annotatedConstruct
- the annotated construct to search for annotations, may benull
annotationClassName
- the fully qualified class name of the annotation to look for, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.type.TypeMirror type)
Retrieves allAnnotationMirror
instances from the givenTypeMirror
. If the type mirror isnull
, this method returns an empty list.- Parameters:
type
- the type mirror to search for annotations, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.element.Element element)
Retrieves allAnnotationMirror
instances from the givenElement
. If the element isnull
, this method returns an empty list.This method is designed to provide a consistent way of retrieving annotations across different constructs in the annotation processing framework.
- Parameters:
element
- the annotated element to search for annotations, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves allAnnotationMirror
instances of the specified annotation class from the givenTypeMirror
. If either the type or the annotation class isnull
, this method returns an empty list.- Parameters:
type
- the type mirror to search for annotations, may benull
annotationClass
- the annotation class to look for, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves allAnnotationMirror
instances of the specified annotation class from the givenElement
. If either the element or the annotation class isnull
, this method returns an empty list.- Parameters:
element
- the annotated element to search for annotations, may benull
annotationClass
- the annotation class to look for, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)
Retrieves allAnnotationMirror
instances of the specified annotation class name from the givenTypeMirror
. If either the type or the annotation class name isnull
, this method returns an empty list.- Parameters:
type
- the type mirror to search for annotations, may benull
annotationClassName
- the fully qualified class name of the annotation to look for, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
Retrieves allAnnotationMirror
instances of the specified annotation class name from the givenElement
. If either the element or the annotation class name isnull
, this method returns an empty list.- Parameters:
element
- the annotated element to search for annotations, may benull
annotationClassName
- the fully qualified class name of the annotation to look for, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType)
Retrieves allAnnotationMirror
instances of the specified annotated type from the givenProcessingEnvironment
. If either the processing environment or the annotated type isnull
, this method returns an empty list.- Parameters:
processingEnv
- the processing environment used to retrieve annotations, may benull
annotatedType
- the annotated type to search for annotations, may benull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves the firstAnnotationMirror
of the specified annotation class from the givenTypeMirror
. If either the type or the annotation class isnull
, this method returnsnull
.- Parameters:
type
- the type mirror to search for annotations, may benull
annotationClass
- the annotation class to look for, may benull
- Returns:
- the first matching
AnnotationMirror
, ornull
if none found
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)
Retrieves the firstAnnotationMirror
of the specified annotation class name from the givenTypeMirror
. If either the type or the annotation class name isnull
, this method returnsnull
.- Parameters:
type
- the type mirror to search for annotations, may benull
annotationClassName
- the fully qualified class name of the annotation to look for, may benull
- Returns:
- the first matching
AnnotationMirror
, ornull
if none found
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves the firstAnnotationMirror
of the specified annotation class from the givenElement
. If either the element or the annotation class isnull
, this method returnsnull
.- Parameters:
element
- the annotated element to search for annotations, may benull
annotationClass
- the annotation class to look for, may benull
- Returns:
- the first matching
AnnotationMirror
, ornull
if none found
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
Retrieves the firstAnnotationMirror
of the specified annotation class name from the givenElement
. If either the element or the annotation class name isnull
, this method returnsnull
.- Parameters:
element
- the annotated element to search for annotations, may benull
annotationClassName
- the fully qualified class name of the annotation to look for, may benull
- Returns:
- the first matching
AnnotationMirror
, ornull
if none found
-
findMetaAnnotation
static javax.lang.model.element.AnnotationMirror findMetaAnnotation(javax.lang.model.element.Element annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationClass)
Retrieves the first meta-annotation of the specified annotation class from the given annotated element. A meta-annotation is an annotation that is present on another annotation. If either the annotated element or the meta-annotation class isnull
, this method returnsnull
.- Parameters:
annotatedConstruct
- the annotated element to search for meta-annotations, may benull
metaAnnotationClass
- the annotation class to look for as a meta-annotation, may benull
- Returns:
- the first matching meta-
AnnotationMirror
, ornull
if none found
-
findMetaAnnotation
static javax.lang.model.element.AnnotationMirror findMetaAnnotation(javax.lang.model.element.Element annotatedConstruct, java.lang.CharSequence metaAnnotationClassName)
Retrieves the first meta-annotation of the specified meta-annotation class name from the given annotated element. A meta-annotation is an annotation that is present on another annotation. If either the annotated element or the meta-annotation class name isnull
, this method returnsnull
.- Parameters:
annotatedConstruct
- the annotated element to search for meta-annotations, may benull
metaAnnotationClassName
- the fully qualified class name of the meta-annotation to look for, may benull
- Returns:
- the first matching meta-
AnnotationMirror
, ornull
if none found
-
isAnnotationPresent
static boolean isAnnotationPresent(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Checks if the specified annotation is present on the given element, either directly or as a meta-annotation.- Parameters:
element
- the element to check for the presence of the annotation; may benull
annotationClass
- the annotation class to look for; may benull
- Returns:
true
if the annotation is present (either directly or as a meta-annotation),false
otherwise or if either parameter isnull
-
isAnnotationPresent
static boolean isAnnotationPresent(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
Checks if the specified annotation (by class name) is present on the given element, either directly or as a meta-annotation.- Parameters:
element
- the element to check for the presence of the annotation; may benull
annotationClassName
- the fully qualified class name of the annotation to look for; may benull
- Returns:
true
if the annotation is present (either directly or as a meta-annotation),false
otherwise or if either parameter isnull
-
findAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> findAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances from the givenAnnotatedConstruct
that match the provided annotation filters.If the annotated construct is
null
, this method returns an empty list. If no annotation filters are provided, all annotations present on the construct are returned. Otherwise, only annotations that satisfy all the provided predicates are included in the result.- Parameters:
annotatedConstruct
- the annotated construct to search for annotations, may benull
annotationFilters
- a varargs array of predicates used to filter annotations; may be empty ornull
- Returns:
- a non-null immutable list of matching
AnnotationMirror
instances; nevernull
-
findAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations(javax.lang.model.type.TypeMirror type, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances from the givenTypeMirror
, applying the specified annotation filters to narrow down the results. If the type mirror isnull
, this method returns an empty list.This method delegates to
findAllAnnotations(TypeElement, Predicate[])
after converting theTypeMirror
to aTypeElement
using#ofTypeElement(TypeMirror)
.- Parameters:
type
- the type mirror to search for annotations, may benull
annotationFilters
- a varargs array of predicates used to filter annotations; may be empty ornull
- Returns:
- a non-null immutable list of matching
AnnotationMirror
instances; nevernull
-
findAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations(javax.lang.model.element.TypeElement element, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
-
findAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations(javax.lang.model.element.Element element, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances from the givenElement
, applying the specified annotation filters to narrow down the results. If the element isnull
, this method returns an empty list.This method attempts to resolve the element into a
TypeElement
. If successful, it delegates tofindAllAnnotations(TypeElement, Predicate[])
to retrieve annotations from the type hierarchy. Otherwise, it falls back to usingfindAnnotations(AnnotatedConstruct, Predicate[])
directly on the element.- Parameters:
element
- the annotated element to search for annotations, may benull
annotationFilters
- a varargs array of predicates used to filter annotations; may be empty ornull
- Returns:
- a non-null immutable list of matching
AnnotationMirror
instances; nevernull
-
findAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances of the specified annotated type from the givenProcessingEnvironment
. If either the processing environment or the annotated type isnull
, this method returns an empty list.This method uses the fully qualified type name of the provided
Type
to locate the corresponding annotations. It delegates to the overloaded method that accepts aCharSequence
for the type name.- Parameters:
processingEnv
- the processing environment used to retrieve annotations, may benull
annotatedType
- the annotated type to search for annotations, may benull
annotationFilters
- a varargs array of predicates used to filter annotations; may be empty ornull
- Returns:
- a non-null immutable list of
AnnotationMirror
instances; nevernull
-
findAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> findAllAnnotations(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.CharSequence annotatedTypeName, java.util.function.Predicate<? super javax.lang.model.element.AnnotationMirror>... annotationFilters)
Retrieves allAnnotationMirror
instances of the specified annotated type name from the givenProcessingEnvironment
. If either the processing environment or the annotated type name isnull
, this method returns an empty list.This method resolves the annotated type by delegating to
#getTypeElement(ProcessingEnvironment, CharSequence)
, and then uses the resolved type to find annotations with the provided filters.- Parameters:
processingEnv
- the processing environment used to retrieve annotations, may benull
annotatedTypeName
- the fully qualified class name of the annotation to look for, may benull
annotationFilters
- a varargs array of predicates used to filter annotations; may be empty ornull
- Returns:
- a non-null immutable list of matching
AnnotationMirror
instances; nevernull
-
matchesAnnotationType
static boolean matchesAnnotationType(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.reflect.Type annotationType)
Checks if the given annotation mirror has the same type as the specifiedType
.This method compares the fully qualified name of the annotation mirror's type with the provided type's name. Returns
false
if either parameter isnull
.- Parameters:
annotationMirror
- the annotation mirror to compare; may benull
annotationType
- the target type to match against; may benull
- Returns:
true
if both parameters are non-null and their types match by name;false
otherwise
-
matchesAnnotationTypeName
static boolean matchesAnnotationTypeName(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.CharSequence annotationTypeName)
Checks if the given annotation mirror has the same type as the specified annotation class name.This method compares the fully qualified name of the annotation mirror's type with the provided annotation class name. Returns
false
if either parameter isnull
.- Parameters:
annotationMirror
- the annotation mirror to compare; may benull
annotationTypeName
- the target annotation class name to match against; may benull
- Returns:
true
if both parameters are non-null and their types match by name;false
otherwise
-
getAttributeName
static java.lang.String getAttributeName(javax.lang.model.element.ExecutableElement attributeMethod)
Retrieves the name of the attribute method from the givenExecutableElement
.This method is typically used to extract the attribute name from an annotation method declaration. The returned name corresponds to the method's simple name as defined in the annotation interface.
- Parameters:
attributeMethod
- the executable element representing the annotation attribute method, may benull
- Returns:
- the name of the attribute method, or
null
if the provided element isnull
-
matchesAttributeMethod
static boolean matchesAttributeMethod(javax.lang.model.element.ExecutableElement attributeMethod, java.lang.String attributeName)
Checks if the provided executable element represents an annotation attribute method with the specified name.- Parameters:
attributeMethod
- the executable element to check, may benull
attributeName
- the expected name of the attribute method, may benull
- Returns:
true
if the method is not null and its name matches the given attribute name;false
otherwise
-
matchesAttributeValue
static boolean matchesAttributeValue(javax.lang.model.element.AnnotationValue annotationValue, java.lang.Object attributeValue)
Checks if the value of the givenAnnotationValue
matches the specified attribute value.This method compares the actual value extracted from the annotation value with the provided attribute value. Returns
false
if either parameter isnull
or if the values do not match.- Parameters:
annotationValue
- the annotation value to compare; may benull
attributeValue
- the target value to match against; may benull
- Returns:
true
if both parameters are non-null and their values match;false
otherwise
-
getAttributesMap
static java.util.Map<java.lang.String,java.lang.Object> getAttributesMap(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Get the attributes map from the specified annotation- Parameters:
annotatedConstruct
- the annotated constructannotationClass
- theclass
ofannotation
- Returns:
- non-null read-only
Map
-
getAttributesMap
static java.util.Map<java.lang.String,java.lang.Object> getAttributesMap(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, boolean withDefault)
Get the attributes map from the specified annotation- Parameters:
annotatedConstruct
- the annotated constructannotationClass
- theclass
ofannotation
withDefault
- with default attribute value- Returns:
- non-null read-only
Map
-
getAttributesMap
static java.util.Map<java.lang.String,java.lang.Object> getAttributesMap(javax.lang.model.element.AnnotationMirror annotation)
Get the attributes map from the specified annotation- Parameters:
annotation
- the specified annotation- Returns:
- non-null read-only
Map
-
getAttributesMap
static java.util.Map<java.lang.String,java.lang.Object> getAttributesMap(javax.lang.model.element.AnnotationMirror annotation, boolean withDefault)
Get the attributes map from the specified annotation- Parameters:
annotation
- the specified annotationwithDefault
- with default attribute value- Returns:
- non-null read-only
Map
-
getElementValues
static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getElementValues(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Retrieves the map of annotation attribute methods to their corresponding values from the specifiedAnnotatedConstruct
and annotation class. This method finds the first matching annotation on the construct and returns all its declared attribute values, including default values if enabled.If the annotated construct is
null
or the annotation class is not present, an empty map is returned.- Parameters:
annotatedConstruct
- the annotated construct (e.g., a class, method, or field) that may contain the annotation, may benull
annotationClass
- the annotation class used to locate the annotation on the construct, must not benull
- Returns:
- a non-null immutable map of executable elements (attribute methods) to their annotation values; never
null
, returns an empty map if no annotation is found or if the construct isnull
-
getElementValues
static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getElementValues(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, boolean withDefault)
Retrieves the map of annotation attribute methods to their corresponding values from the specifiedAnnotatedConstruct
and annotation class. This method finds the first matching annotation on the construct and returns all its declared attribute values, including default values if enabled.If the annotated construct is
null
or the annotation class is not present, an empty map is returned.- Parameters:
annotatedConstruct
- the annotated construct (e.g., a class, method, or field) that may contain the annotation, may benull
annotationClass
- the annotation class used to locate the annotation on the construct, must not benull
withDefault
- flag indicating whether to include default values for attributes that are not explicitly set; iftrue
, default values will be included where applicable- Returns:
- a non-null immutable map of executable elements (attribute methods) to their annotation values; never
null
, returns an empty map if no annotation is found or if the construct isnull
-
getElementValues
static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getElementValues(javax.lang.model.element.AnnotationMirror annotation)
Retrieves a map of annotation attribute methods to their corresponding values from the specifiedAnnotationMirror
. This method includes both explicitly set values and default values for attributes.If the provided annotation is
null
, an empty map is returned.- Parameters:
annotation
- the annotation mirror to extract attribute values from, may benull
- Returns:
- a non-null immutable map of executable elements (attribute methods) to their annotation values;
never
null
, returns an empty map if the annotation isnull
-
getElementValues
static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getElementValues(javax.lang.model.element.AnnotationMirror annotation, boolean withDefault)
Retrieves a map of annotation attribute methods to their corresponding values from the specifiedAnnotationMirror
. This method includes both explicitly set values and default values for attributes if thewithDefault
flag is set totrue
.If the provided annotation is
null
, an empty map is returned.- Parameters:
annotation
- the annotation mirror to extract attribute values from, may benull
withDefault
- flag indicating whether to include default values for attributes that are not explicitly set; iftrue
, default values will be included where applicable- Returns:
- a non-null immutable map of executable elements (attribute methods) to their annotation values;
never
null
, returns an empty map if the annotation isnull
-
getElementValue
static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getElementValue(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName, boolean withDefault)
Retrieves the attribute method and its corresponding annotation value from the specified annotation based on the given attribute name. If no explicit value is found andwithDefault
is true, it attempts to find and return the default value for the attribute.If the provided annotation is null or the attribute name is blank, this method returns null.
- Parameters:
annotation
- the annotation mirror to extract the attribute value from, may benull
attributeName
- the name of the attribute method to look for, may be blankwithDefault
- flag indicating whether to include the default value if the attribute is not explicitly set; if true, the method will attempt to find and return the default value- Returns:
- an entry containing the executable element (attribute method) and its corresponding annotation value; returns null if the annotation is null, the attribute name is blank, or the attribute method cannot be found
-
getElementValue
static java.util.Map.Entry<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getElementValue(java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> elementValues, java.lang.String attributeName)
Retrieves the attribute method and its corresponding annotation value from the specified element values map based on the given attribute name.This method searches through the provided map of executable elements (attribute methods) to their annotation values to find a matching attribute by name. If no match is found, it returns
null
.- Parameters:
elementValues
- the map of executable elements (attribute methods) to their annotation values; may benull
or emptyattributeName
- the name of the attribute method to look for; may benull
or blank- Returns:
- an entry containing the executable element (attribute method) and its corresponding annotation value;
returns
null
if the element values map is empty, the attribute name is blank, or no matching attribute is found
-
getAttribute
static <T> T getAttribute(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName)
Retrieves the value of the specified attribute from the given annotation.This method attempts to find the attribute by name in the provided annotation. If the attribute is not explicitly set, it will attempt to retrieve the default value associated with that attribute, depending on the implementation's behavior.
- Type Parameters:
T
- the type of the attribute value to return- Parameters:
annotation
- the annotation mirror to extract the attribute value from; may benull
attributeName
- the name of the attribute method to look for; may be blank ornull
- Returns:
- the value of the specified attribute if found, or the default value if available;
returns
null
if the annotation isnull
, the attribute name is blank, or the attribute cannot be resolved
-
getAttribute
static <T> T getAttribute(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName, boolean withDefault)
Retrieves the value of the specified attribute from the given annotation, optionally including the default value.This method attempts to find the attribute by name in the provided annotation. If the attribute is not explicitly set, and the
withDefault
flag is set totrue
, it will attempt to retrieve the default value associated with that attribute. If the attribute cannot be resolved or no value is found, this method returnsnull
.- Type Parameters:
T
- the type of the attribute value to return- Parameters:
annotation
- the annotation mirror to extract the attribute value from; may benull
attributeName
- the name of the attribute method to look for; may be blank ornull
withDefault
- flag indicating whether to include the default value if the attribute is not explicitly set; iftrue
, the method will attempt to find and return the default value- Returns:
- the value of the specified attribute if found, or the default value if available;
returns
null
if the annotation isnull
, the attribute name is blank, or the attribute cannot be resolved
-
getAttribute
static <T> T getAttribute(java.util.Map.Entry<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> elementValue)
Retrieves the value of the specified attribute from the provided entry containing the attribute method and its corresponding annotation value.If the entry is null or either the attribute method or annotation value is unresolved, this method returns
null
. Otherwise, it delegates to the defaultAnnotationValueVisitor
to extract the attribute value.- Type Parameters:
T
- the expected type of the attribute value- Parameters:
elementValue
- an entry containing the attribute method and its corresponding annotation value; may benull
- Returns:
- the resolved value of the attribute if found; returns
null
if the entry is null, or if either the attribute method or annotation value is unresolved
-
getValue
static <T> T getValue(javax.lang.model.element.AnnotationMirror annotation)
Retrieves the value of the specified annotation by accessing the default attribute method named"value"
.This method delegates to
getAttribute(AnnotationMirror, String)
to obtain the value of the annotation'svalue()
method. If the annotation is null or the value cannot be resolved, this method returns null.- Type Parameters:
T
- the expected type of the attribute value- Parameters:
annotation
- the annotation mirror to extract the value from; may benull
- Returns:
- the resolved value of the annotation's
value()
method if found; returnsnull
if the annotation isnull
or the value cannot be resolved
-
getElementTypes
static java.lang.annotation.ElementType[] getElementTypes(javax.lang.model.element.AnnotationMirror annotation)
Retrieves theElementType
array from the specified annotation.- Parameters:
annotation
- the specified annotation, may benull
- Returns:
- a non-null array of
ElementType
; nevernull
, returns an empty array if the annotation isnull
-
getElementTypes
static java.lang.annotation.ElementType[] getElementTypes(javax.lang.model.type.DeclaredType annotationType)
Retrieves theElementType
array from the specified annotation type by checking theTarget
annotation associated with it. If the annotation type does not have aTarget
annotation, an empty array is returned.- Parameters:
annotationType
- the declared type of the annotation- Returns:
- a non-null array of
ElementType
; nevernull
, returns an empty array if noTarget
annotation is present
-
-