类 AnnotatedElementUtils


  • public class AnnotatedElementUtils
    extends Object
    注解工具类
    • 构造器详细资料

      • AnnotatedElementUtils

        public AnnotatedElementUtils()
    • 方法详细资料

      • getAnnotatedMetadata

        @Contract("null -> new")
        @NotNull
        public static @NotNull AnnotatedElementMetadata getAnnotatedMetadata​(AnnotatedElement annotationEle)
        将指定的被注解的元素转换为组合注解元素
        参数:
        annotationEle - 注解元素
        返回:
        组合注解元素
      • getAnnotations

        public static Annotation[] getAnnotations​(AnnotatedElement annotationEle,
                                                  boolean isToCombination)
        获取指定注解
        参数:
        annotationEle - AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermission
        isToCombination - 是否为转换为组合注解,组合注解可以递归获取注解的注解
        返回:
        注解对象
      • getAnnotations

        public static Annotation[] getAnnotations​(AnnotatedElement annotationEle,
                                                  boolean isToCombination,
                                                  java.util.function.Predicate<Annotation> predicate)
        获取指定注解
        参数:
        annotationEle - AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermission
        isToCombination - 是否为转换为组合注解,组合注解可以递归获取注解的注解
        predicate - 过滤器,Predicate.test(Object)返回true保留,否则不保留
        返回:
        注解对象,如果提供的AnnotatedElementnull,返回null
      • getAnnotation

        @Nullable
        public static <A extends Annotation> A getAnnotation​(AnnotatedElement annotationEle,
                                                             Class<A> annotationType)
        获取指定注解
        类型参数:
        A - 注解类型
        参数:
        annotationEle - AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermission
        annotationType - 注解类型
        返回:
        注解对象
      • hasAnnotation

        public static boolean hasAnnotation​(AnnotatedElement annotationEle,
                                            Class<? extends Annotation> annotationType)
        检查是否包含指定注解指定注解
        参数:
        annotationEle - AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermission
        annotationType - 注解类型
        返回:
        是否包含指定注解
      • getAnnotationValue

        public static <T> Optional<T> getAnnotationValue​(AnnotatedElement annotationEle,
                                                         Class<? extends Annotation> annotationType,
                                                         String attributeName,
                                                         Class<T> type)
        获取指定注解属性的值
        如果无指定的属性方法返回null
        类型参数:
        T - 注解值类型
        参数:
        annotationEle - AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermission
        annotationType - 注解类型
        attributeName - 属性名,例如注解中定义了name()方法,则 此处传入name
        type - 属性类型
        返回:
        注解对象
      • getAnnotationAttributes

        @Nullable
        public static @Nullable AnnotationAttributes getAnnotationAttributes​(AnnotatedElement annotationEle,
                                                                             Class<? extends Annotation> annotationType)
        获取指定注解中所有属性值

        如果无指定的属性方法返回null

        参数:
        annotationEle - AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermission
        annotationType - 注解类型
        返回:
        注解对象
      • getRetentionPolicy

        public static RetentionPolicy getRetentionPolicy​(@NotNull
                                                         @NotNull Class<? extends Annotation> annotationType)
        获取注解类的保留时间,可选值 SOURCE(源码时),CLASS(编译时),RUNTIME(运行时),默认为 CLASS
        参数:
        annotationType - 注解类
        返回:
        保留时间枚举
      • getTargetType

        public static ElementType[] getTargetType​(@NotNull
                                                  @NotNull Class<? extends Annotation> annotationType)
        获取注解类可以用来修饰哪些程序元素,如 TYPE, METHOD, CONSTRUCTOR, FIELD, PARAMETER 等
        参数:
        annotationType - 注解类
        返回:
        注解修饰的程序元素数组
      • isDocumented

        @Contract(pure=true)
        public static boolean isDocumented​(@NotNull
                                           @NotNull Class<? extends Annotation> annotationType)
        是否会保存到 Javadoc 文档中
        参数:
        annotationType - 注解类
        返回:
        是否会保存到 Javadoc 文档中
      • isInherited

        @Contract(pure=true)
        public static boolean isInherited​(@NotNull
                                          @NotNull Class<? extends Annotation> annotationType)
        是否可以被继承,默认为 false
        参数:
        annotationType - 注解类
        返回:
        是否会保存到 Javadoc 文档中
      • setValue

        public static void setValue​(Annotation annotation,
                                    String annotationField,
                                    Object value)
        设置新的注解的属性(字段)值
        参数:
        annotation - 注解对象
        annotationField - 注解属性(字段)名称
        value - 要更新的属性值