Package org.apache.dubbo.common.utils
Interface AnnotationUtils
public interface AnnotationUtils
Commons Annotation Utilities class
- Since:
- 2.7.6
-
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic Predicate<Annotation> excludedType(Class<? extends Annotation> excludedAnnotationType) Build an instance ofPredicateto excluded annotation typefilterDefaultValues(Annotation annotation, Map<String, Object> attributes) Filter default value of Annotation typefilterDefaultValues(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 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 <T> TgetAttribute(Annotation annotation, String... attributeNames) Get the attribute from the specifiedannotationgetAttributes(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> 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
-
Method Details
-
resolveAnnotationType
static <A extends Annotation> Class<A> resolveAnnotationType(AnnotatedElement annotatedElement, String annotationClassName) Resolve the annotation type by the annotated element and resolved class name- Type Parameters:
A- the type of annotation- Parameters:
annotatedElement- the annotated elementannotationClassName- the class name of annotation- Returns:
- If resolved, return the type of annotation, or
null
-
isType
Is the specified type a generictype- Parameters:
annotatedElement- the annotated element- Returns:
- if
annotatedElementis theClass, returntrue, orfalse - See Also:
-
isSameType
Is the type of specified annotation same to the expected type?- Parameters:
annotation- the specifiedAnnotationannotationType- the expected annotation type- Returns:
- if same, return
true, orfalse
-
excludedType
Build an instance ofPredicateto excluded annotation type- Parameters:
excludedAnnotationType- excluded annotation type- Returns:
- non-null
-
getAttribute
static <T> T getAttribute(Annotation annotation, String attributeName) throws IllegalArgumentException Get the attribute from the specifiedannotation- Type Parameters:
T- the type of attribute- Parameters:
annotation- the specifiedannotationattributeName- the attribute name- Returns:
- the attribute value
- Throws:
IllegalArgumentException- If the attribute name can't be found
-
getValue
Get the "value" attribute from the specifiedannotation- Type Parameters:
T- the type of attribute- Parameters:
annotation- the specifiedannotation- Returns:
- the value of "value" attribute
- Throws:
IllegalArgumentException- If the attribute name can't be found
-
getAttribute
static <T> T getAttribute(Annotation annotation, String... attributeNames) throws IllegalArgumentException Get the attribute from the specifiedannotation- Type Parameters:
T- the type of attribute- Parameters:
annotation- the specifiedannotationattributeNames- the multiply attribute name arrays- Returns:
- the attribute value
- Throws:
IllegalArgumentException- If the attribute name can't be found
-
getAnnotation
static <A extends Annotation> A getAnnotation(AnnotatedElement annotatedElement, String annotationClassName) throws ClassCastException - Type Parameters:
A- The type ofAnnotation- Parameters:
annotatedElement-AnnotatedElementannotationClassName- the class name of annotation- Returns:
- the
Annotationif found - Throws:
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.- Parameters:
annotatedElement- the annotated elementannotationsToFilter- the annotations to filter- Returns:
- 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.- Parameters:
annotatedElement- the annotated elementannotationsToFilter- the annotations to filter- Returns:
- 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.- Parameters:
type- the specified typeannotationsToFilter- the annotations to filter- Returns:
- non-null read-only
List
-
getMetaAnnotations
static List<Annotation> getMetaAnnotations(Class<? extends Annotation> annotationType, Predicate<Annotation>... metaAnnotationsToFilter) - Parameters:
annotationType- theannotationtypemetaAnnotationsToFilter- the meta annotations to filter- Returns:
- non-null read-only
List
-
getAllMetaAnnotations
static List<Annotation> getAllMetaAnnotations(Class<? extends Annotation> annotationType, Predicate<Annotation>... annotationsToFilter) Get all meta annotations from the specifiedannotationtype- Parameters:
annotationType- theannotationtypeannotationsToFilter- the annotations to filter- Returns:
- 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- Type Parameters:
A- the required type of annotation- Parameters:
annotatedElement- the annotated elementannotationClassName- the class name of annotation- Returns:
- 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- Type Parameters:
A- the required type of annotation- Parameters:
annotatedElement- the annotated elementannotationType- the type of annotation- Returns:
- 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- Type Parameters:
A- the type of required annotation- Parameters:
annotationType- theannotationtypemetaAnnotationType- the meta annotation type- Returns:
- 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- Type Parameters:
A- the type of required annotation- Parameters:
annotatedElement- the annotated elementmetaAnnotationType- the meta annotation type- Returns:
- 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- Type Parameters:
A- the type of required annotation- Parameters:
annotatedElement- the annotated elementmetaAnnotationClassName- the class name of meta annotation- Returns:
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- Type Parameters:
A- the type of required annotation- Parameters:
annotationType- theannotationtypemetaAnnotationType- the meta annotation type- Returns:
- If found, return the
CollectionUtils.first(Collection)matched result, returnnull. If it requires more result, please consider to usefindMetaAnnotations(Class, Class) - See Also:
-
findMetaAnnotation
static <A extends Annotation> A findMetaAnnotation(AnnotatedElement annotatedElement, Class<A> metaAnnotationType) Find the meta annotation from the annotated element by meta annotation type- Type Parameters:
A- the type of required annotation- Parameters:
annotatedElement- the annotated elementmetaAnnotationType- the meta annotation type- Returns:
- If found, return the
CollectionUtils.first(Collection)matched result, returnnull. If it requires more result, please consider to usefindMetaAnnotations(AnnotatedElement, Class) - See Also:
-
isAnnotationPresent
static boolean isAnnotationPresent(Class<?> type, boolean matchAll, Class<? extends Annotation>... annotationTypes) Tests the annotated element is annotated the specified annotations or not- Parameters:
type- the annotated typematchAll- Iftrue, checking all annotation types are present or not, or match anyannotationTypes- the specified annotation types- Returns:
- If the specified annotation types are present, return
true, orfalse
-
isAnnotationPresent
Tests the annotated element is annotated the specified annotation or not- Parameters:
type- the annotated typeannotationType- the class of annotation- Returns:
- If the specified annotation type is present, return
true, orfalse
-
isAnnotationPresent
Tests the annotated element is present any specified annotation types- Parameters:
annotatedElement- the annotated elementannotationClassName- the class name of annotation- Returns:
- 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- Parameters:
annotatedElement- the annotated elementannotationType- the class of annotation- Returns:
- 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- Parameters:
type- the annotated typeannotationTypes- the specified annotation types- Returns:
- 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- Parameters:
type- the annotated typeannotationTypes- the specified annotation types- Returns:
- If any specified annotation types are present, return
true
-
getDefaultValue
Get the default value of attribute on the specified annotation- Type Parameters:
T- the type of value- Parameters:
annotation-AnnotationobjectattributeName- the name of attribute- Returns:
nullif not found- Since:
- 2.7.9
-
getDefaultValue
Get the default value of attribute on the specified annotation- Type Parameters:
T- the type of value- Parameters:
annotationType- the type ofAnnotationattributeName- the name of attribute- Returns:
nullif not found- Since:
- 2.7.9
-
filterDefaultValues
static Map<String,Object> filterDefaultValues(Class<? extends Annotation> annotationType, Map<String, Object> attributes) Filter default value of Annotation type- Parameters:
annotationType- annotation type fromAnnotation.annotationType()attributes-- Returns:
-
filterDefaultValues
Filter default value of Annotation type- Parameters:
annotation-attributes-- Returns:
-
getAttributes
Get attributes of annotation- Parameters:
annotation-- Returns:
-