类 AnnotatedElementUtils
- java.lang.Object
-
- cc.shacocloud.mirage.utils.annotation.AnnotatedElementUtils
-
public class AnnotatedElementUtils extends Object
注解工具类
-
-
构造器概要
构造器 构造器 说明 AnnotatedElementUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static @NotNull AnnotatedElementMetadatagetAnnotatedMetadata(AnnotatedElement annotationEle)将指定的被注解的元素转换为组合注解元素static <A extends Annotation>
AgetAnnotation(AnnotatedElement annotationEle, Class<A> annotationType)获取指定注解static @Nullable AnnotationAttributesgetAnnotationAttributes(AnnotatedElement annotationEle, Class<? extends Annotation> annotationType)获取指定注解中所有属性值static Annotation[]getAnnotations(AnnotatedElement annotationEle, boolean isToCombination)获取指定注解static Annotation[]getAnnotations(AnnotatedElement annotationEle, boolean isToCombination, java.util.function.Predicate<Annotation> predicate)获取指定注解static <T> Optional<T>getAnnotationValue(AnnotatedElement annotationEle, Class<? extends Annotation> annotationType, String attributeName, Class<T> type)获取指定注解属性的值
如果无指定的属性方法返回nullstatic RetentionPolicygetRetentionPolicy(@NotNull Class<? extends Annotation> annotationType)获取注解类的保留时间,可选值 SOURCE(源码时),CLASS(编译时),RUNTIME(运行时),默认为 CLASSstatic ElementType[]getTargetType(@NotNull Class<? extends Annotation> annotationType)获取注解类可以用来修饰哪些程序元素,如 TYPE, METHOD, CONSTRUCTOR, FIELD, PARAMETER 等static booleanhasAnnotation(AnnotatedElement annotationEle, Class<? extends Annotation> annotationType)检查是否包含指定注解指定注解static booleanisDocumented(@NotNull Class<? extends Annotation> annotationType)是否会保存到 Javadoc 文档中static booleanisInherited(@NotNull Class<? extends Annotation> annotationType)是否可以被继承,默认为 falsestatic booleanisJdkMetaAnnotation(Class<? extends Annotation> annotationType)是否为Jdk自带的元注解。static booleanisNotJdkMateAnnotation(Class<? extends Annotation> annotationType)是否不为Jdk自带的元注解。static voidsetValue(Annotation annotation, String annotationField, Object value)设置新的注解的属性(字段)值
-
-
-
方法详细资料
-
isJdkMetaAnnotation
public static boolean isJdkMetaAnnotation(Class<? extends Annotation> annotationType)
是否为Jdk自带的元注解。
包括:- 参数:
annotationType- 注解类型- 返回:
- 是否为Jdk自带的元注解
-
isNotJdkMateAnnotation
public static boolean isNotJdkMateAnnotation(Class<? extends Annotation> annotationType)
是否不为Jdk自带的元注解。
包括:- 参数:
annotationType- 注解类型- 返回:
- 是否为Jdk自带的元注解
-
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、ReflectPermissionisToCombination- 是否为转换为组合注解,组合注解可以递归获取注解的注解- 返回:
- 注解对象
-
getAnnotations
public static Annotation[] getAnnotations(AnnotatedElement annotationEle, boolean isToCombination, java.util.function.Predicate<Annotation> predicate)
获取指定注解- 参数:
annotationEle-AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermissionisToCombination- 是否为转换为组合注解,组合注解可以递归获取注解的注解predicate- 过滤器,Predicate.test(Object)返回true保留,否则不保留- 返回:
- 注解对象,如果提供的
AnnotatedElement为null,返回null
-
getAnnotation
@Nullable public static <A extends Annotation> A getAnnotation(AnnotatedElement annotationEle, Class<A> annotationType)
获取指定注解- 类型参数:
A- 注解类型- 参数:
annotationEle-AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermissionannotationType- 注解类型- 返回:
- 注解对象
-
hasAnnotation
public static boolean hasAnnotation(AnnotatedElement annotationEle, Class<? extends Annotation> annotationType)
检查是否包含指定注解指定注解- 参数:
annotationEle-AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermissionannotationType- 注解类型- 返回:
- 是否包含指定注解
-
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、ReflectPermissionannotationType- 注解类型attributeName- 属性名,例如注解中定义了name()方法,则 此处传入nametype- 属性类型- 返回:
- 注解对象
-
getAnnotationAttributes
@Nullable public static @Nullable AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotationEle, Class<? extends Annotation> annotationType)
获取指定注解中所有属性值如果无指定的属性方法返回null
- 参数:
annotationEle-AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermissionannotationType- 注解类型- 返回:
- 注解对象
-
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- 要更新的属性值
-
-