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_VISITORThe defaultAnnotationValueVisitorstatic java.lang.annotation.ElementType[]EMPTY_ELEMENT_TYPE_ARRAYThe emptyElementTypearraystatic java.lang.StringVALUE_ATTRIBUTE_NAMEThe name of the attribute method : value()static booleanWITH_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 allAnnotationMirrorinstances 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 allAnnotationMirrorinstances 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 allAnnotationMirrorinstances 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 allAnnotationMirrorinstances from the givenTypeMirror, applying the specified annotation filters to narrow down the results.static javax.lang.model.element.AnnotationMirrorfindAnnotation(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)Retrieves the firstAnnotationMirrorof the specified annotation class name from the givenElement.static javax.lang.model.element.AnnotationMirrorfindAnnotation(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)Retrieves the firstAnnotationMirrorof the specified annotation class from the givenElement.static javax.lang.model.element.AnnotationMirrorfindAnnotation(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)Retrieves the firstAnnotationMirrorof the specified annotation class name from the givenTypeMirror.static javax.lang.model.element.AnnotationMirrorfindAnnotation(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)Retrieves the firstAnnotationMirrorof 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 allAnnotationMirrorinstances from the givenAnnotatedConstructthat match the provided annotation filters.static javax.lang.model.element.AnnotationMirrorfindMetaAnnotation(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.AnnotationMirrorfindMetaAnnotation(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 allAnnotationMirrorinstances 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 allAnnotationMirrorinstances from the givenElement.static java.util.List<javax.lang.model.element.AnnotationMirror>getAllAnnotations(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)Retrieves allAnnotationMirrorinstances 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 allAnnotationMirrorinstances 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 allAnnotationMirrorinstances from the givenTypeMirror.static java.util.List<javax.lang.model.element.AnnotationMirror>getAllAnnotations(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)Retrieves allAnnotationMirrorinstances 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 allAnnotationMirrorinstances of the specified annotation class from the givenTypeMirror.static javax.lang.model.element.AnnotationMirrorgetAnnotation(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)Retrieves the firstAnnotationMirrorof the specified annotation class name from the givenAnnotatedConstruct.static javax.lang.model.element.AnnotationMirrorgetAnnotation(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)Retrieves the firstAnnotationMirrorof the specified annotation class from the givenAnnotatedConstruct.static java.util.List<javax.lang.model.element.AnnotationMirror>getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct)Retrieves allAnnotationMirrorinstances from the givenAnnotatedConstruct.static java.util.List<javax.lang.model.element.AnnotationMirror>getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)Retrieves allAnnotationMirrorinstances 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 allAnnotationMirrorinstances of the specified annotation class from the givenAnnotatedConstruct.static <T> TgetAttribute(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> TgetAttribute(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName)Retrieves the value of the specified attribute from the given annotation.static <T> TgetAttribute(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.StringgetAttributeName(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 theElementTypearray from the specified annotation.static java.lang.annotation.ElementType[]getElementTypes(javax.lang.model.type.DeclaredType annotationType)Retrieves theElementTypearray from the specified annotation type by checking theTargetannotation 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 specifiedAnnotatedConstructand 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 specifiedAnnotatedConstructand 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> TgetValue(javax.lang.model.element.AnnotationMirror annotation)Retrieves the value of the specified annotation by accessing the default attribute method named"value".static booleanisAnnotationPresent(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 booleanisAnnotationPresent(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 booleanmatchesAnnotationType(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 booleanmatchesAnnotationTypeName(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 booleanmatchesAttributeMethod(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 booleanmatchesAttributeValue(javax.lang.model.element.AnnotationValue annotationValue, java.lang.Object attributeValue)Checks if the value of the givenAnnotationValuematches 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 emptyElementTypearray
-
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 firstAnnotationMirrorof 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 benullannotationClass- the annotation class to look for, may benull- Returns:
- the first matching
AnnotationMirror, ornullif none found
-
getAnnotation
static javax.lang.model.element.AnnotationMirror getAnnotation(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)Retrieves the firstAnnotationMirrorof 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 benullannotationClassName- the fully qualified class name of the annotation to look for, may benull- Returns:
- the first matching
AnnotationMirror, ornullif none found
-
getAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct)
Retrieves allAnnotationMirrorinstances 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
AnnotationMirrorinstances; 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 allAnnotationMirrorinstances 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 benullannotationClass- the annotation class to look for, may benull- Returns:
- a non-null immutable list of
AnnotationMirrorinstances; nevernull
-
getAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAnnotations(javax.lang.model.AnnotatedConstruct annotatedConstruct, java.lang.CharSequence annotationClassName)Retrieves allAnnotationMirrorinstances 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 benullannotationClassName- the fully qualified class name of the annotation to look for, may benull- Returns:
- a non-null immutable list of
AnnotationMirrorinstances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.type.TypeMirror type)
Retrieves allAnnotationMirrorinstances 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
AnnotationMirrorinstances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.element.Element element)
Retrieves allAnnotationMirrorinstances 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
AnnotationMirrorinstances; 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 allAnnotationMirrorinstances 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 benullannotationClass- the annotation class to look for, may benull- Returns:
- a non-null immutable list of
AnnotationMirrorinstances; 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 allAnnotationMirrorinstances 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 benullannotationClass- the annotation class to look for, may benull- Returns:
- a non-null immutable list of
AnnotationMirrorinstances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)Retrieves allAnnotationMirrorinstances 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 benullannotationClassName- the fully qualified class name of the annotation to look for, may benull- Returns:
- a non-null immutable list of
AnnotationMirrorinstances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)Retrieves allAnnotationMirrorinstances 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 benullannotationClassName- the fully qualified class name of the annotation to look for, may benull- Returns:
- a non-null immutable list of
AnnotationMirrorinstances; nevernull
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType)Retrieves allAnnotationMirrorinstances 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 benullannotatedType- the annotated type to search for annotations, may benull- Returns:
- a non-null immutable list of
AnnotationMirrorinstances; 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 firstAnnotationMirrorof 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 benullannotationClass- the annotation class to look for, may benull- Returns:
- the first matching
AnnotationMirror, ornullif none found
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)Retrieves the firstAnnotationMirrorof 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 benullannotationClassName- the fully qualified class name of the annotation to look for, may benull- Returns:
- the first matching
AnnotationMirror, ornullif 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 firstAnnotationMirrorof 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 benullannotationClass- the annotation class to look for, may benull- Returns:
- the first matching
AnnotationMirror, ornullif none found
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)Retrieves the firstAnnotationMirrorof 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 benullannotationClassName- the fully qualified class name of the annotation to look for, may benull- Returns:
- the first matching
AnnotationMirror, ornullif 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 benullmetaAnnotationClass- the annotation class to look for as a meta-annotation, may benull- Returns:
- the first matching meta-
AnnotationMirror, ornullif 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 benullmetaAnnotationClassName- the fully qualified class name of the meta-annotation to look for, may benull- Returns:
- the first matching meta-
AnnotationMirror, ornullif 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 benullannotationClass- the annotation class to look for; may benull- Returns:
trueif the annotation is present (either directly or as a meta-annotation),falseotherwise 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 benullannotationClassName- the fully qualified class name of the annotation to look for; may benull- Returns:
trueif the annotation is present (either directly or as a meta-annotation),falseotherwise 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 allAnnotationMirrorinstances from the givenAnnotatedConstructthat 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 benullannotationFilters- a varargs array of predicates used to filter annotations; may be empty ornull- Returns:
- a non-null immutable list of matching
AnnotationMirrorinstances; 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 allAnnotationMirrorinstances 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 theTypeMirrorto aTypeElementusing#ofTypeElement(TypeMirror).- Parameters:
type- the type mirror to search for annotations, may benullannotationFilters- a varargs array of predicates used to filter annotations; may be empty ornull- Returns:
- a non-null immutable list of matching
AnnotationMirrorinstances; 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 allAnnotationMirrorinstances 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 benullannotationFilters- a varargs array of predicates used to filter annotations; may be empty ornull- Returns:
- a non-null immutable list of matching
AnnotationMirrorinstances; 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 allAnnotationMirrorinstances 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
Typeto locate the corresponding annotations. It delegates to the overloaded method that accepts aCharSequencefor the type name.- Parameters:
processingEnv- the processing environment used to retrieve annotations, may benullannotatedType- the annotated type to search for annotations, may benullannotationFilters- a varargs array of predicates used to filter annotations; may be empty ornull- Returns:
- a non-null immutable list of
AnnotationMirrorinstances; 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 allAnnotationMirrorinstances 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 benullannotatedTypeName- the fully qualified class name of the annotation to look for, may benullannotationFilters- a varargs array of predicates used to filter annotations; may be empty ornull- Returns:
- a non-null immutable list of matching
AnnotationMirrorinstances; 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
falseif either parameter isnull.- Parameters:
annotationMirror- the annotation mirror to compare; may benullannotationType- the target type to match against; may benull- Returns:
trueif both parameters are non-null and their types match by name;falseotherwise
-
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
falseif either parameter isnull.- Parameters:
annotationMirror- the annotation mirror to compare; may benullannotationTypeName- the target annotation class name to match against; may benull- Returns:
trueif both parameters are non-null and their types match by name;falseotherwise
-
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
nullif 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 benullattributeName- the expected name of the attribute method, may benull- Returns:
trueif the method is not null and its name matches the given attribute name;falseotherwise
-
matchesAttributeValue
static boolean matchesAttributeValue(javax.lang.model.element.AnnotationValue annotationValue, java.lang.Object attributeValue)Checks if the value of the givenAnnotationValuematches the specified attribute value.This method compares the actual value extracted from the annotation value with the provided attribute value. Returns
falseif either parameter isnullor if the values do not match.- Parameters:
annotationValue- the annotation value to compare; may benullattributeValue- the target value to match against; may benull- Returns:
trueif both parameters are non-null and their values match;falseotherwise
-
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- theclassofannotation- 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- theclassofannotationwithDefault- 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 specifiedAnnotatedConstructand 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
nullor 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 benullannotationClass- 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 specifiedAnnotatedConstructand 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
nullor 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 benullannotationClass- the annotation class used to locate the annotation on the construct, must not benullwithDefault- 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 thewithDefaultflag 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 benullwithDefault- 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 andwithDefaultis 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 benullattributeName- 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 benullor emptyattributeName- the name of the attribute method to look for; may benullor blank- Returns:
- an entry containing the executable element (attribute method) and its corresponding annotation value;
returns
nullif 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 benullattributeName- 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
nullif 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
withDefaultflag 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 benullattributeName- the name of the attribute method to look for; may be blank ornullwithDefault- 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
nullif 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 defaultAnnotationValueVisitorto 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
nullif 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; returnsnullif the annotation isnullor the value cannot be resolved
-
getElementTypes
static java.lang.annotation.ElementType[] getElementTypes(javax.lang.model.element.AnnotationMirror annotation)
Retrieves theElementTypearray 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 theElementTypearray from the specified annotation type by checking theTargetannotation associated with it. If the annotation type does not have aTargetannotation, 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 noTargetannotation is present
-
-