接口 AnnotationUtils
-
public interface AnnotationUtilsCommons Annotation Utilities class- 从以下版本开始:
- 2.7.6
-
-
方法概要
静态方法 修饰符和类型 方法 说明 static Predicate<Annotation>excludedType(Class<? extends Annotation> excludedAnnotationType)Build an instance ofPredicateto excluded 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 theannotationtype 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 specifiedannotationtypestatic <A extends Annotation>
AgetAnnotation(AnnotatedElement annotatedElement, String annotationClassName)static <T> TgetAttribute(Annotation annotation, String attributeName)Get the attribute from the specifiedannotationstatic List<Annotation>getDeclaredAnnotations(AnnotatedElement annotatedElement, Predicate<Annotation>... annotationsToFilter)Get annotations that are directly present on this element.static <T> TgetDefaultValue(Annotation annotation, String attributeName)Get the default value of attribute on the specified annotationstatic <T> TgetDefaultValue(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> TgetValue(Annotation annotation)Get the "value" attribute from the specifiedannotationstatic booleanisAllAnnotationPresent(Class<?> type, Class<? extends Annotation>... annotationTypes)Tests the annotated element is annotated all specified annotations or notstatic booleanisAnnotationPresent(Class<?> type, boolean matchAll, Class<? extends Annotation>... annotationTypes)Tests the annotated element is annotated the specified annotations or notstatic booleanisAnnotationPresent(Class<?> type, Class<? extends Annotation> annotationType)Tests the annotated element is annotated the specified annotation or notstatic booleanisAnnotationPresent(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType)Tests the annotated element is present any specified annotation typesstatic booleanisAnnotationPresent(AnnotatedElement annotatedElement, String annotationClassName)Tests the annotated element is present any specified annotation typesstatic booleanisAnyAnnotationPresent(Class<?> type, Class<? extends Annotation>... annotationTypes)Tests the annotated element is present any specified annotation typesstatic booleanisSameType(Annotation annotation, Class<? extends Annotation> annotationType)Is the type of specified annotation same to the expected type?static booleanisType(AnnotatedElement annotatedElement)Is the specified type a generictypestatic <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
annotatedElementis 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 specifiedAnnotationannotationType- the expected annotation type- 返回:
- if same, return
true, orfalse
-
excludedType
static Predicate<Annotation> excludedType(Class<? extends Annotation> excludedAnnotationType)
Build an instance ofPredicateto 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 specifiedannotationattributeName- 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-AnnotatedElementannotationClassName- the class name of annotation- 返回:
- the
Annotationif found - 抛出:
ClassCastException- If theannotationtype 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- theannotationtypemetaAnnotationsToFilter- 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 specifiedannotationtype- 参数:
annotationType- theannotationtypeannotationsToFilter- 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 theannotationtype by meta annotation type- 类型参数:
A- the type of required annotation- 参数:
annotationType- theannotationtypemetaAnnotationType- 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- theannotationtypemetaAnnotationType- 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-AnnotationobjectattributeName- the name of attribute- 返回:
nullif 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 ofAnnotationattributeName- the name of attribute- 返回:
nullif not found- 从以下版本开始:
- 2.7.9
-
-