public class AnnotationUtil extends Object
| Constructor and Description |
|---|
AnnotationUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <A extends Annotation> |
getAnnotation(AnnotatedElement annotationEle,
Class<A> annotationType)
获取指定注解
|
static Annotation[] |
getAnnotations(AnnotatedElement annotationEle,
boolean isToCombination)
获取指定注解
|
static <T> T |
getAnnotationValue(AnnotatedElement annotationEle,
Class<? extends Annotation> annotationType)
获取指定注解默认值
如果无指定的属性方法返回null |
static <T> T |
getAnnotationValue(AnnotatedElement annotationEle,
Class<? extends Annotation> annotationType,
String propertyName)
获取指定注解属性的值
如果无指定的属性方法返回null |
static Map<String,Object> |
getAnnotationValueMap(AnnotatedElement annotationEle,
Class<? extends Annotation> annotationType)
获取指定注解中所有属性值
如果无指定的属性方法返回null |
static RetentionPolicy |
getRetentionPolicy(Class<? extends Annotation> annotationType)
获取注解类的保留时间,可选值 SOURCE(源码时),CLASS(编译时),RUNTIME(运行时),默认为 CLASS
|
static ElementType[] |
getTargetType(Class<? extends Annotation> annotationType)
获取注解类可以用来修饰哪些程序元素,如 TYPE, METHOD, CONSTRUCTOR, FIELD, PARAMETER 等
|
static boolean |
isDocumented(Class<? extends Annotation> annotationType)
是否会保存到 Javadoc 文档中
|
static boolean |
isInherited(Class<? extends Annotation> annotationType)
是否可以被继承,默认为 false
|
static CombinationAnnotationElement |
toCombination(AnnotatedElement annotationEle)
将指定的被注解的元素转换为组合注解元素
|
public static CombinationAnnotationElement toCombination(AnnotatedElement annotationEle)
annotationEle - 注解元素public static Annotation[] getAnnotations(AnnotatedElement annotationEle, boolean isToCombination)
annotationEle - AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermissionisToCombination - 是否为转换为组合注解public static <A extends Annotation> A getAnnotation(AnnotatedElement annotationEle, Class<A> annotationType)
A - 注解类型annotationEle - AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermissionannotationType - 注解类型public static <T> T getAnnotationValue(AnnotatedElement annotationEle, Class<? extends Annotation> annotationType) throws UtilException
T - 注解值类型annotationEle - AccessibleObject,可以是Class、Method、Field、Constructor、ReflectPermissionannotationType - 注解类型UtilException - 调用注解中的方法时执行异常public static <T> T getAnnotationValue(AnnotatedElement annotationEle, Class<? extends Annotation> annotationType, String propertyName) throws UtilException
T - 注解值类型annotationEle - AccessibleObject,可以是Class、Method、Field、Constructor、ReflectPermissionannotationType - 注解类型propertyName - 属性名,例如注解中定义了name()方法,则 此处传入nameUtilException - 调用注解中的方法时执行异常public static Map<String,Object> getAnnotationValueMap(AnnotatedElement annotationEle, Class<? extends Annotation> annotationType) throws UtilException
annotationEle - AnnotatedElement,可以是Class、Method、Field、Constructor、ReflectPermissionannotationType - 注解类型UtilException - 调用注解中的方法时执行异常public static RetentionPolicy getRetentionPolicy(Class<? extends Annotation> annotationType)
annotationType - 注解类public static ElementType[] getTargetType(Class<? extends Annotation> annotationType)
annotationType - 注解类public static boolean isDocumented(Class<? extends Annotation> annotationType)
annotationType - 注解类public static boolean isInherited(Class<? extends Annotation> annotationType)
annotationType - 注解类Copyright © 2021. All rights reserved.