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)
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)
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)
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)
static javax.lang.model.element.AnnotationMirror
findAnnotation(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
static javax.lang.model.element.AnnotationMirror
findAnnotation(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
static javax.lang.model.element.AnnotationMirror
findAnnotation(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)
static javax.lang.model.element.AnnotationMirror
findAnnotation(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
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)
static javax.lang.model.element.AnnotationMirror
findMetaAnnotation(javax.lang.model.element.Element annotatedConstruct, java.lang.CharSequence metaAnnotationClassName)
static javax.lang.model.element.AnnotationMirror
findMetaAnnotation(javax.lang.model.element.Element annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationClass)
static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType)
static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.lang.model.element.Element element)
static java.util.List<javax.lang.model.element.AnnotationMirror>
getAllAnnotations(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
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)
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)
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)
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)
static <T> T
getAttribute(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName)
static <T> T
getAttribute(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName, boolean withDefault)
static java.lang.String
getAttributeName(javax.lang.model.element.ExecutableElement attributeMethod)
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)
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 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)
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)
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)
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)
static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>
getElementValues(javax.lang.model.element.AnnotationMirror annotation)
static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue>
getElementValues(javax.lang.model.element.AnnotationMirror annotation, boolean withDefault)
static <T> T
getValue(javax.lang.model.element.AnnotationMirror annotation)
static boolean
isAnnotationPresent(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
static boolean
isAnnotationPresent(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
static boolean
matchesAnnotationType(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.reflect.Type annotationType)
static boolean
matchesAnnotationTypeName(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.CharSequence annotationTypeName)
static boolean
matchesAttributeMethod(javax.lang.model.element.ExecutableElement attributeMethod, java.lang.String attributeName)
static boolean
matchesAttributeValue(javax.lang.model.element.AnnotationValue annotationValue, java.lang.Object attributeValue)
-
-
-
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)
-
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)
-
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)
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
-
getAllAnnotations
static java.util.List<javax.lang.model.element.AnnotationMirror> getAllAnnotations(javax.annotation.processing.ProcessingEnvironment processingEnv, java.lang.reflect.Type annotatedType)
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.type.TypeMirror type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.type.TypeMirror type, java.lang.CharSequence annotationClassName)
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
-
findAnnotation
static javax.lang.model.element.AnnotationMirror findAnnotation(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
-
findMetaAnnotation
static javax.lang.model.element.AnnotationMirror findMetaAnnotation(javax.lang.model.element.Element annotatedConstruct, java.lang.Class<? extends java.lang.annotation.Annotation> metaAnnotationClass)
-
findMetaAnnotation
static javax.lang.model.element.AnnotationMirror findMetaAnnotation(javax.lang.model.element.Element annotatedConstruct, java.lang.CharSequence metaAnnotationClassName)
-
isAnnotationPresent
static boolean isAnnotationPresent(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
-
isAnnotationPresent
static boolean isAnnotationPresent(javax.lang.model.element.Element element, java.lang.CharSequence annotationClassName)
-
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)
-
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)
-
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)
-
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)
-
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)
-
matchesAnnotationType
static boolean matchesAnnotationType(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.reflect.Type annotationType)
-
matchesAnnotationTypeName
static boolean matchesAnnotationTypeName(javax.lang.model.element.AnnotationMirror annotationMirror, java.lang.CharSequence annotationTypeName)
-
getAttributeName
static java.lang.String getAttributeName(javax.lang.model.element.ExecutableElement attributeMethod)
-
matchesAttributeMethod
static boolean matchesAttributeMethod(javax.lang.model.element.ExecutableElement attributeMethod, java.lang.String attributeName)
-
matchesAttributeValue
static boolean matchesAttributeValue(javax.lang.model.element.AnnotationValue annotationValue, java.lang.Object attributeValue)
-
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)
-
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)
-
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)
-
getElementValues
static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getElementValues(javax.lang.model.element.AnnotationMirror annotation)
-
getElementValues
static java.util.Map<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> getElementValues(javax.lang.model.element.AnnotationMirror annotation, boolean withDefault)
-
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)
-
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)
-
getAttribute
static <T> T getAttribute(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName)
-
getAttribute
static <T> T getAttribute(javax.lang.model.element.AnnotationMirror annotation, java.lang.String attributeName, boolean withDefault)
-
getAttribute
static <T> T getAttribute(java.util.Map.Entry<javax.lang.model.element.ExecutableElement,javax.lang.model.element.AnnotationValue> elementValue)
-
getValue
static <T> T getValue(javax.lang.model.element.AnnotationMirror annotation)
-
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
-
-