Package io.microsphere.util
Class AnnotationUtils
- java.lang.Object
-
- io.microsphere.util.AnnotationUtils
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Class<? extends java.lang.annotation.Annotation>CALLER_SENSITIVE_ANNOTATION_CLASSThe annotationClassof jdk.internal.reflect.CallerSensitive that may benullstatic java.lang.StringCALLER_SENSITIVE_ANNOTATION_CLASS_NAMEThe annotation class name of jdk.internal.reflect.CallerSensitivestatic java.lang.annotation.Annotation[]EMPTY_ANNOTATION_ARRAYAn empty immutableAnnotationarraystatic java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>>NATIVE_ANNOTATION_TYPES
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanexists(java.lang.annotation.Annotation[] annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)static booleanexists(java.lang.Iterable<java.lang.annotation.Annotation> annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)static booleanexists(java.util.Collection<java.lang.annotation.Annotation> annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)static java.util.List<java.lang.annotation.Annotation>filterAnnotations(java.lang.annotation.Annotation[] annotations, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)static java.util.List<java.lang.annotation.Annotation>filterAnnotations(java.util.List<java.lang.annotation.Annotation> annotations, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)static java.util.List<java.lang.annotation.Annotation>findAllDeclaredAnnotations(java.lang.Class<?> type, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)Get all directly declared annotations of the specified type and those all hierarchical types, not including meta annotations.static java.util.List<java.lang.annotation.Annotation>findAllDeclaredAnnotations(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)Find all directly declared annotations of the annotated element with filters, not including meta annotations.static <A extends java.lang.annotation.Annotation>
AfindAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType)Find the annotation that is annotated on the specified element may be a meta-annotationstatic <A extends java.lang.annotation.Annotation>
AfindAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationFilters)Find the annotation that is annotated on the specified element may be a meta-annotationstatic java.util.Map<java.lang.String,java.lang.Object>findAttributesMap(java.lang.annotation.Annotation annotation, java.lang.String... attributeNamesToFilter)Find the attributes map from the specified annotation by the attribute namesstatic java.util.Map<java.lang.String,java.lang.Object>findAttributesMap(java.lang.annotation.Annotation annotation, java.util.function.Predicate<? super java.lang.reflect.Method>... attributesToFilter)Find the attributes map from the specified annotation by theattribute methodstatic <T> TfindAttributeValue(java.lang.annotation.Annotation[] annotations, java.lang.String attributeName)Find the attribute value from the specified annotationsstatic java.util.List<java.lang.annotation.Annotation>findDeclaredAnnotations(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)Find the declared annotations that are directly present on this element with filters.static java.util.List<java.lang.annotation.Annotation>getAllDeclaredAnnotations(java.lang.reflect.AnnotatedElement annotatedElement)Get all directly declared annotations of the annotated element, not including meta annotations.static java.util.Map<java.lang.String,java.lang.Object>getAttributesMap(java.lang.annotation.Annotation annotation)Get the attributes map from the specified annotationstatic <T> TgetAttributeValue(java.lang.annotation.Annotation annotation, java.lang.String attributeName)Get the attribute value of the annotationstatic java.util.List<java.lang.annotation.Annotation>getDeclaredAnnotations(java.lang.reflect.AnnotatedElement annotatedElement)Get the declared annotations that are directly present on this element.static booleanisAnnotationInterfaceMethod(java.lang.reflect.Method attributeMethod)Is the specified method declared by theAnnotationinterface or notstatic booleanisAnnotationPresent(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)static booleanisAnnotationPresent(java.lang.annotation.Annotation annotation, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)static booleanisAnnotationPresent(java.lang.reflect.AnnotatedElement[] annotatedElements, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)static booleanisAnnotationPresent(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)static booleanisAnnotationPresent(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)static booleanisCallerSensitivePresent()Is jdk.internal.reflect.CallerSensitive class present or notstatic booleanisMetaAnnotation(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)static booleanisMetaAnnotation(java.lang.annotation.Annotation annotation, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)static booleanisMetaAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)static booleanisMetaAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)
-
-
-
Field Detail
-
NATIVE_ANNOTATION_TYPES
public static final java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> NATIVE_ANNOTATION_TYPES
-
CALLER_SENSITIVE_ANNOTATION_CLASS_NAME
public static final java.lang.String CALLER_SENSITIVE_ANNOTATION_CLASS_NAME
The annotation class name of jdk.internal.reflect.CallerSensitive- See Also:
- Constant Field Values
-
CALLER_SENSITIVE_ANNOTATION_CLASS
public static final java.lang.Class<? extends java.lang.annotation.Annotation> CALLER_SENSITIVE_ANNOTATION_CLASS
The annotationClassof jdk.internal.reflect.CallerSensitive that may benull
-
EMPTY_ANNOTATION_ARRAY
public static final java.lang.annotation.Annotation[] EMPTY_ANNOTATION_ARRAY
An empty immutableAnnotationarray
-
-
Method Detail
-
findAnnotation
public static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.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
-
findAnnotation
public static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationFilters)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 elementannotationFilters- the filters of annotations- Returns:
- If found, return first matched-type
annotation, ornull
-
isMetaAnnotation
public static boolean isMetaAnnotation(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)
-
isMetaAnnotation
public static boolean isMetaAnnotation(java.lang.annotation.Annotation annotation, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)
-
isMetaAnnotation
public static boolean isMetaAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation>... metaAnnotationTypes)
-
isMetaAnnotation
public static boolean isMetaAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> metaAnnotationTypes)
-
getAllDeclaredAnnotations
public static java.util.List<java.lang.annotation.Annotation> getAllDeclaredAnnotations(java.lang.reflect.AnnotatedElement annotatedElement)
Get all directly declared annotations of the annotated element, not including meta annotations.- Parameters:
annotatedElement- the annotated element- Returns:
- non-null read-only
List
-
getDeclaredAnnotations
public static java.util.List<java.lang.annotation.Annotation> getDeclaredAnnotations(java.lang.reflect.AnnotatedElement annotatedElement)
Get the declared annotations that are directly present on this element. This method ignores inherited annotations.- Parameters:
annotatedElement- the annotated element- Returns:
- non-null read-only
List
-
findAllDeclaredAnnotations
public static java.util.List<java.lang.annotation.Annotation> findAllDeclaredAnnotations(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)Find all directly declared annotations of the annotated element with filters, not including meta annotations.- Parameters:
annotatedElement- the annotated elementannotationsToFilter- the annotations to filter- Returns:
- non-null read-only
List
-
findAllDeclaredAnnotations
public static java.util.List<java.lang.annotation.Annotation> findAllDeclaredAnnotations(java.lang.Class<?> type, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)Get all directly declared annotations of the specified type and those all hierarchical types, not including meta annotations.- Parameters:
type- the specified typeannotationsToFilter- the annotations to filter- Returns:
- non-null read-only
List
-
findDeclaredAnnotations
public static java.util.List<java.lang.annotation.Annotation> findDeclaredAnnotations(java.lang.reflect.AnnotatedElement annotatedElement, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)Find the declared annotations that are directly present on this element with filters. This method ignores inherited annotations.- Parameters:
annotatedElement- the annotated elementannotationsToFilter- the annotations to filter- Returns:
- non-null read-only
List
-
filterAnnotations
public static java.util.List<java.lang.annotation.Annotation> filterAnnotations(java.lang.annotation.Annotation[] annotations, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
-
filterAnnotations
public static java.util.List<java.lang.annotation.Annotation> filterAnnotations(java.util.List<java.lang.annotation.Annotation> annotations, java.util.function.Predicate<? super java.lang.annotation.Annotation>... annotationsToFilter)
-
findAttributeValue
public static <T> T findAttributeValue(java.lang.annotation.Annotation[] annotations, java.lang.String attributeName)Find the attribute value from the specified annotations- Type Parameters:
T- attribute value type- Parameters:
annotations- the annotations to be foundattributeName- attribute name- Returns:
- attribute value if found, otherwise
null
-
getAttributeValue
public static <T> T getAttributeValue(java.lang.annotation.Annotation annotation, java.lang.String attributeName)Get the attribute value of the annotation- Type Parameters:
T- attribute value type- Parameters:
annotation- annotationattributeName- attribute name- Returns:
- attribute value if found, otherwise
null
-
getAttributesMap
public static java.util.Map<java.lang.String,java.lang.Object> getAttributesMap(java.lang.annotation.Annotation annotation)
Get the attributes map from the specified annotation- Parameters:
annotation- the specified annotation- Returns:
- non-null read-only
Map
-
findAttributesMap
public static java.util.Map<java.lang.String,java.lang.Object> findAttributesMap(java.lang.annotation.Annotation annotation, java.lang.String... attributeNamesToFilter)Find the attributes map from the specified annotation by the attribute names- Parameters:
annotation- the specified annotationattributeNamesToFilter- the attribute names to filter- Returns:
- non-null read-only
Map
-
findAttributesMap
public static java.util.Map<java.lang.String,java.lang.Object> findAttributesMap(java.lang.annotation.Annotation annotation, java.util.function.Predicate<? super java.lang.reflect.Method>... attributesToFilter)Find the attributes map from the specified annotation by theattribute method- Parameters:
annotation- the specified annotationattributesToFilter- the attribute methods to filter- Returns:
- non-null read-only
Map
-
exists
public static boolean exists(java.lang.annotation.Annotation[] annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
exists
public static boolean exists(java.util.Collection<java.lang.annotation.Annotation> annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
exists
public static boolean exists(java.lang.Iterable<java.lang.annotation.Annotation> annotations, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
isAnnotationPresent
public static boolean isAnnotationPresent(java.lang.reflect.AnnotatedElement[] annotatedElements, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
isAnnotationPresent
public static boolean isAnnotationPresent(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
isAnnotationPresent
public static boolean isAnnotationPresent(java.lang.annotation.Annotation annotation, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
isAnnotationPresent
public static boolean isAnnotationPresent(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
-
isAnnotationPresent
public static boolean isAnnotationPresent(java.lang.annotation.Annotation annotation, java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
-
isAnnotationInterfaceMethod
public static boolean isAnnotationInterfaceMethod(java.lang.reflect.Method attributeMethod)
Is the specified method declared by theAnnotationinterface or not- Parameters:
attributeMethod- the attribute method- Returns:
trueif the specified method declared by theAnnotationinterface
-
isCallerSensitivePresent
public static boolean isCallerSensitivePresent()
Is jdk.internal.reflect.CallerSensitive class present or not- Returns:
trueif jdk.internal.reflect.CallerSensitive presents- See Also:
CALLER_SENSITIVE_ANNOTATION_CLASS
-
-