接口 AnnotationUtils


  • public interface AnnotationUtils
    Commons Annotation Utilities class
    从以下版本开始:
    2.7.6
    • 方法详细资料

      • resolveAnnotationType

        static <A extends AnnotationClass<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 element
        annotationClassName - 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 generic type
        参数:
        annotatedElement - the annotated element
        返回:
        if annotatedElement is the Class, return true, or false
        另请参阅:
        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 specified Annotation
        annotationType - the expected annotation type
        返回:
        if same, return true, or false
      • excludedType

        static Predicate<Annotation> excludedType​(Class<? extends Annotation> excludedAnnotationType)
        Build an instance of Predicate to excluded annotation type
        参数:
        excludedAnnotationType - excluded annotation type
        返回:
        non-null
      • 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 element
        annotationsToFilter - 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 element
        annotationsToFilter - 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 type
        annotationsToFilter - 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 element
        annotationClassName - the class name of annotation
        返回:
        If found, return first matched-type annotation, or null
      • 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 element
        annotationType - the type of annotation
        返回:
        If found, return first matched-type annotation, or null
      • findMetaAnnotations

        static <A extends AnnotationList<A> findMetaAnnotations​(Class<? extends Annotation> annotationType,
                                                                  Class<A> metaAnnotationType)
        Find the meta annotations from the the annotation type by meta annotation type
        类型参数:
        A - the type of required annotation
        参数:
        annotationType - the annotation type
        metaAnnotationType - the meta annotation type
        返回:
        if found, return all matched results, or get an empty list
      • findMetaAnnotations

        static <A extends AnnotationList<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 element
        metaAnnotationType - 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 element
        metaAnnotationClassName - the class name of meta annotation
        返回:
        findMetaAnnotation(Class, 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 type
        matchAll - If true, checking all annotation types are present or not, or match any
        annotationTypes - the specified annotation types
        返回:
        If the specified annotation types are present, return true, or false
      • isAnnotationPresent

        static boolean isAnnotationPresent​(Class<?> type,
                                           Class<? extends Annotation> annotationType)
        Tests the annotated element is annotated the specified annotation or not
        参数:
        type - the annotated type
        annotationType - the class of annotation
        返回:
        If the specified annotation type is present, return true, or false
      • isAnnotationPresent

        static boolean isAnnotationPresent​(AnnotatedElement annotatedElement,
                                           String annotationClassName)
        Tests the annotated element is present any specified annotation types
        参数:
        annotatedElement - the annotated element
        annotationClassName - 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 element
        annotationType - 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 type
        annotationTypes - the specified annotation types
        返回:
        If the specified annotation types are present, return true, or false
      • isAnyAnnotationPresent

        static boolean isAnyAnnotationPresent​(Class<?> type,
                                              Class<? extends Annotation>... annotationTypes)
        Tests the annotated element is present any specified annotation types
        参数:
        type - the annotated type
        annotationTypes - 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 object
        attributeName - 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 of Annotation
        attributeName - the name of attribute
        返回:
        null if not found
        从以下版本开始:
        2.7.9
      • 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 -
        返回: