接口 AnnotationUtils
-
public interface AnnotationUtils
Commons Annotation Utilities class- 从以下版本开始:
- 2.7.6
-
-
方法概要
静态方法 修饰符和类型 方法 说明 static Predicate<Annotation>
excludedType(Class<? extends Annotation> excludedAnnotationType)
Build an instance ofPredicate
to excluded annotation typestatic Map<String,Object>
filterDefaultValues(Annotation annotation, Map<String,Object> attributes)
Filter default value of Annotation typestatic Map<String,Object>
filterDefaultValues(Class<? extends Annotation> annotationType, Map<String,Object> attributes)
Filter default value of Annotation typestatic <A extends Annotation>
AfindAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType)
Find the annotation that is annotated on the specified element may be a meta-annotationstatic <A extends Annotation>
AfindAnnotation(AnnotatedElement annotatedElement, String annotationClassName)
Find the annotation that is annotated on the specified element may be a meta-annotationstatic <A extends Annotation>
AfindMetaAnnotation(Class<? extends Annotation> annotationType, Class<A> metaAnnotationType)
Find the meta annotation from the annotation type by meta annotation typestatic <A extends Annotation>
AfindMetaAnnotation(AnnotatedElement annotatedElement, Class<A> metaAnnotationType)
Find the meta annotation from the annotated element by meta annotation typestatic <A extends Annotation>
AfindMetaAnnotation(AnnotatedElement annotatedElement, String metaAnnotationClassName)
Find the meta annotation from the annotated element by meta annotation typestatic <A extends Annotation>
List<A>findMetaAnnotations(Class<? extends Annotation> annotationType, Class<A> metaAnnotationType)
Find the meta annotations from the theannotation
type by meta annotation typestatic <A extends Annotation>
List<A>findMetaAnnotations(AnnotatedElement annotatedElement, Class<A> metaAnnotationType)
Find the meta annotations from the the the annotated element by meta annotation typestatic List<Annotation>
getAllDeclaredAnnotations(Class<?> type, Predicate<Annotation>... annotationsToFilter)
Get all directly declared annotations of the specified type and its' all hierarchical types, not including meta annotations.static List<Annotation>
getAllDeclaredAnnotations(AnnotatedElement annotatedElement, Predicate<Annotation>... annotationsToFilter)
Get all directly declared annotations of the the annotated element, not including meta annotations.static List<Annotation>
getAllMetaAnnotations(Class<? extends Annotation> annotationType, Predicate<Annotation>... annotationsToFilter)
Get all meta annotations from the specifiedannotation
typestatic <A extends Annotation>
AgetAnnotation(AnnotatedElement annotatedElement, String annotationClassName)
static <T> T
getAttribute(Annotation annotation, String attributeName)
Get the attribute from the specifiedannotation
static Map<String,Object>
getAttributes(Annotation annotation, boolean filterDefaultValue)
Get attributes of annotationstatic List<Annotation>
getDeclaredAnnotations(AnnotatedElement annotatedElement, Predicate<Annotation>... annotationsToFilter)
Get annotations that are directly present on this element.static <T> T
getDefaultValue(Annotation annotation, String attributeName)
Get the default value of attribute on the specified annotationstatic <T> T
getDefaultValue(Class<? extends Annotation> annotationType, String attributeName)
Get the default value of attribute on the specified annotationstatic List<Annotation>
getMetaAnnotations(Class<? extends Annotation> annotationType, Predicate<Annotation>... metaAnnotationsToFilter)
static <T> T
getValue(Annotation annotation)
Get the "value" attribute from the specifiedannotation
static boolean
isAllAnnotationPresent(Class<?> type, Class<? extends Annotation>... annotationTypes)
Tests the annotated element is annotated all specified annotations or notstatic boolean
isAnnotationPresent(Class<?> type, boolean matchAll, Class<? extends Annotation>... annotationTypes)
Tests the annotated element is annotated the specified annotations or notstatic boolean
isAnnotationPresent(Class<?> type, Class<? extends Annotation> annotationType)
Tests the annotated element is annotated the specified annotation or notstatic boolean
isAnnotationPresent(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType)
Tests the annotated element is present any specified annotation typesstatic boolean
isAnnotationPresent(AnnotatedElement annotatedElement, String annotationClassName)
Tests the annotated element is present any specified annotation typesstatic boolean
isAnyAnnotationPresent(Class<?> type, Class<? extends Annotation>... annotationTypes)
Tests the annotated element is present any specified annotation typesstatic boolean
isSameType(Annotation annotation, Class<? extends Annotation> annotationType)
Is the type of specified annotation same to the expected type?static boolean
isType(AnnotatedElement annotatedElement)
Is the specified type a generictype
static <A extends Annotation>
Class<A>resolveAnnotationType(AnnotatedElement annotatedElement, String annotationClassName)
Resolve the annotation type by the annotated element and resolved class name
-
-
-
方法详细资料
-
resolveAnnotationType
static <A extends Annotation> Class<A> resolveAnnotationType(AnnotatedElement annotatedElement, String annotationClassName)
Resolve the annotation type by the annotated element and resolved class name- 类型参数:
A
- the type of annotation- 参数:
annotatedElement
- the annotated elementannotationClassName
- the class name of annotation- 返回:
- If resolved, return the type of annotation, or
null
-
isType
static boolean isType(AnnotatedElement annotatedElement)
Is the specified type a generictype
- 参数:
annotatedElement
- the annotated element- 返回:
- if
annotatedElement
is theClass
, returntrue
, orfalse
- 另请参阅:
ElementType.TYPE
-
isSameType
static boolean isSameType(Annotation annotation, Class<? extends Annotation> annotationType)
Is the type of specified annotation same to the expected type?- 参数:
annotation
- the specifiedAnnotation
annotationType
- the expected annotation type- 返回:
- if same, return
true
, orfalse
-
excludedType
static Predicate<Annotation> excludedType(Class<? extends Annotation> excludedAnnotationType)
Build an instance ofPredicate
to excluded annotation type- 参数:
excludedAnnotationType
- excluded annotation type- 返回:
- non-null
-
getAttribute
static <T> T getAttribute(Annotation annotation, String attributeName) throws IllegalArgumentException
Get the attribute from the specifiedannotation
- 类型参数:
T
- the type of attribute- 参数:
annotation
- the specifiedannotation
attributeName
- the attribute name- 返回:
- the attribute value
- 抛出:
IllegalArgumentException
- If the attribute name can't be found
-
getValue
static <T> T getValue(Annotation annotation) throws IllegalArgumentException
Get the "value" attribute from the specifiedannotation
- 类型参数:
T
- the type of attribute- 参数:
annotation
- the specifiedannotation
- 返回:
- the value of "value" attribute
- 抛出:
IllegalArgumentException
- If the attribute name can't be found
-
getAnnotation
static <A extends Annotation> A getAnnotation(AnnotatedElement annotatedElement, String annotationClassName) throws ClassCastException
- 类型参数:
A
- The type ofAnnotation
- 参数:
annotatedElement
-AnnotatedElement
annotationClassName
- the class name of annotation- 返回:
- the
Annotation
if found - 抛出:
ClassCastException
- If theannotation
type that client requires can't match actual type
-
getDeclaredAnnotations
static List<Annotation> getDeclaredAnnotations(AnnotatedElement annotatedElement, Predicate<Annotation>... annotationsToFilter)
Get annotations that are directly present on this element. This method ignores inherited annotations.- 参数:
annotatedElement
- the annotated elementannotationsToFilter
- the annotations to filter- 返回:
- non-null read-only
List
-
getAllDeclaredAnnotations
static List<Annotation> getAllDeclaredAnnotations(AnnotatedElement annotatedElement, Predicate<Annotation>... annotationsToFilter)
Get all directly declared annotations of the the annotated element, not including meta annotations.- 参数:
annotatedElement
- the annotated elementannotationsToFilter
- the annotations to filter- 返回:
- non-null read-only
List
-
getAllDeclaredAnnotations
static List<Annotation> getAllDeclaredAnnotations(Class<?> type, Predicate<Annotation>... annotationsToFilter)
Get all directly declared annotations of the specified type and its' all hierarchical types, not including meta annotations.- 参数:
type
- the specified typeannotationsToFilter
- the annotations to filter- 返回:
- non-null read-only
List
-
getMetaAnnotations
static List<Annotation> getMetaAnnotations(Class<? extends Annotation> annotationType, Predicate<Annotation>... metaAnnotationsToFilter)
- 参数:
annotationType
- theannotation
typemetaAnnotationsToFilter
- the meta annotations to filter- 返回:
- non-null read-only
List
-
getAllMetaAnnotations
static List<Annotation> getAllMetaAnnotations(Class<? extends Annotation> annotationType, Predicate<Annotation>... annotationsToFilter)
Get all meta annotations from the specifiedannotation
type- 参数:
annotationType
- theannotation
typeannotationsToFilter
- the annotations to filter- 返回:
- non-null read-only
List
-
findAnnotation
static <A extends Annotation> A findAnnotation(AnnotatedElement annotatedElement, String annotationClassName)
Find the annotation that is annotated on the specified element may be a meta-annotation- 类型参数:
A
- the required type of annotation- 参数:
annotatedElement
- the annotated elementannotationClassName
- the class name of annotation- 返回:
- If found, return first matched-type
annotation
, ornull
-
findAnnotation
static <A extends Annotation> A findAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType)
Find the annotation that is annotated on the specified element may be a meta-annotation- 类型参数:
A
- the required type of annotation- 参数:
annotatedElement
- the annotated elementannotationType
- the type of annotation- 返回:
- If found, return first matched-type
annotation
, ornull
-
findMetaAnnotations
static <A extends Annotation> List<A> findMetaAnnotations(Class<? extends Annotation> annotationType, Class<A> metaAnnotationType)
Find the meta annotations from the theannotation
type by meta annotation type- 类型参数:
A
- the type of required annotation- 参数:
annotationType
- theannotation
typemetaAnnotationType
- the meta annotation type- 返回:
- if found, return all matched results, or get an
empty list
-
findMetaAnnotations
static <A extends Annotation> List<A> findMetaAnnotations(AnnotatedElement annotatedElement, Class<A> metaAnnotationType)
Find the meta annotations from the the the annotated element by meta annotation type- 类型参数:
A
- the type of required annotation- 参数:
annotatedElement
- the annotated elementmetaAnnotationType
- the meta annotation type- 返回:
- if found, return all matched results, or get an
empty list
-
findMetaAnnotation
static <A extends Annotation> A findMetaAnnotation(AnnotatedElement annotatedElement, String metaAnnotationClassName)
Find the meta annotation from the annotated element by meta annotation type- 类型参数:
A
- the type of required annotation- 参数:
annotatedElement
- the annotated elementmetaAnnotationClassName
- the class name of meta annotation- 返回:
findMetaAnnotation(Class, Class)
-
findMetaAnnotation
static <A extends Annotation> A findMetaAnnotation(Class<? extends Annotation> annotationType, Class<A> metaAnnotationType)
Find the meta annotation from the annotation type by meta annotation type- 类型参数:
A
- the type of required annotation- 参数:
annotationType
- theannotation
typemetaAnnotationType
- the meta annotation type- 返回:
- If found, return the
CollectionUtils.first(Collection)
matched result, returnnull
. If it requires more result, please consider to usefindMetaAnnotations(Class, Class)
- 另请参阅:
findMetaAnnotations(Class, Class)
-
findMetaAnnotation
static <A extends Annotation> A findMetaAnnotation(AnnotatedElement annotatedElement, Class<A> metaAnnotationType)
Find the meta annotation from the annotated element by meta annotation type- 类型参数:
A
- the type of required annotation- 参数:
annotatedElement
- the annotated elementmetaAnnotationType
- the meta annotation type- 返回:
- If found, return the
CollectionUtils.first(Collection)
matched result, returnnull
. If it requires more result, please consider to usefindMetaAnnotations(AnnotatedElement, Class)
- 另请参阅:
findMetaAnnotations(AnnotatedElement, Class)
-
isAnnotationPresent
static boolean isAnnotationPresent(Class<?> type, boolean matchAll, Class<? extends Annotation>... annotationTypes)
Tests the annotated element is annotated the specified annotations or not- 参数:
type
- the annotated typematchAll
- Iftrue
, checking all annotation types are present or not, or match anyannotationTypes
- the specified annotation types- 返回:
- If the specified annotation types are present, return
true
, orfalse
-
isAnnotationPresent
static boolean isAnnotationPresent(Class<?> type, Class<? extends Annotation> annotationType)
Tests the annotated element is annotated the specified annotation or not- 参数:
type
- the annotated typeannotationType
- the class of annotation- 返回:
- If the specified annotation type is present, return
true
, orfalse
-
isAnnotationPresent
static boolean isAnnotationPresent(AnnotatedElement annotatedElement, String annotationClassName)
Tests the annotated element is present any specified annotation types- 参数:
annotatedElement
- the annotated elementannotationClassName
- the class name of annotation- 返回:
- If any specified annotation types are present, return
true
-
isAnnotationPresent
static boolean isAnnotationPresent(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType)
Tests the annotated element is present any specified annotation types- 参数:
annotatedElement
- the annotated elementannotationType
- the class of annotation- 返回:
- If any specified annotation types are present, return
true
-
isAllAnnotationPresent
static boolean isAllAnnotationPresent(Class<?> type, Class<? extends Annotation>... annotationTypes)
Tests the annotated element is annotated all specified annotations or not- 参数:
type
- the annotated typeannotationTypes
- the specified annotation types- 返回:
- If the specified annotation types are present, return
true
, orfalse
-
isAnyAnnotationPresent
static boolean isAnyAnnotationPresent(Class<?> type, Class<? extends Annotation>... annotationTypes)
Tests the annotated element is present any specified annotation types- 参数:
type
- the annotated typeannotationTypes
- the specified annotation types- 返回:
- If any specified annotation types are present, return
true
-
getDefaultValue
static <T> T getDefaultValue(Annotation annotation, String attributeName)
Get the default value of attribute on the specified annotation- 类型参数:
T
- the type of value- 参数:
annotation
-Annotation
objectattributeName
- the name of attribute- 返回:
null
if not found- 从以下版本开始:
- 2.7.9
-
getDefaultValue
static <T> T getDefaultValue(Class<? extends Annotation> annotationType, String attributeName)
Get the default value of attribute on the specified annotation- 类型参数:
T
- the type of value- 参数:
annotationType
- the type ofAnnotation
attributeName
- the name of attribute- 返回:
null
if not found- 从以下版本开始:
- 2.7.9
-
filterDefaultValues
static Map<String,Object> filterDefaultValues(Class<? extends Annotation> annotationType, Map<String,Object> attributes)
Filter default value of Annotation type- 参数:
annotationType
- annotation type fromAnnotation.annotationType()
attributes
-- 返回:
-
filterDefaultValues
static Map<String,Object> filterDefaultValues(Annotation annotation, Map<String,Object> attributes)
Filter default value of Annotation type- 参数:
annotation
-attributes
-- 返回:
-
getAttributes
static Map<String,Object> getAttributes(Annotation annotation, boolean filterDefaultValue)
Get attributes of annotation- 参数:
annotation
-- 返回:
-
-