T
- AnnotationMapping类型public class MetaAnnotatedElement<T extends AnnotationMapping<Annotation>> extends Object implements AnnotatedElement, Iterable<T>
注解元素映射,用于包装一个AnnotatedElement
,然后将被包装的元素上,
直接声明的注解以及这些注解的元组全部解析为ResolvedAnnotationMapping
。
从而用于支持对元注解的访问操作。
默认情况下,总是不扫描java.lang
包下的注解,
并且在当前实例中,Inherited
注解将不生效,
即通过directly方法将无法获得父类上带有Inherited
的注解。
在一个MetaAnnotatedElement
中,
AnnotatedElement
上同类型的注解或元注解只会被保留一个,
即当出现两个根注解都具有相同元注解时,仅有第一个根注解上的元注解会被保留,
因此当通过getAnnotationsByType(Class)
或getDeclaredAnnotationsByType(Class)
方法用于只能获得一个注解对象。
ResolvedAnnotationMapping
Constructor and Description |
---|
MetaAnnotatedElement(AnnotatedElement element,
BiFunction<T,Annotation,T> mappingFactory)
解析注解属性
|
Modifier and Type | Method and Description |
---|---|
static <A extends AnnotationMapping<Annotation>> |
create(AnnotatedElement element,
BiFunction<A,Annotation,A> mappingFactory)
获取
AnnotatedElement 上的注解结构,该方法会针对相同的AnnotatedElement 缓存映射对象 |
boolean |
equals(Object o)
比较两个实例是否相等
|
<A extends Annotation> |
getAnnotation(Class<A> annotationType)
从
AnnotatedElement 直接声明的注解的层级结构中获得注解对象 |
protected Map<Class<? extends Annotation>,T> |
getAnnotationMappings()
获取注解映射,若当前实例未完成初始化则先进行初始化
|
Annotation[] |
getAnnotations()
获取所有注解
|
<A extends Annotation> |
getAnnotationsByType(Class<A> annotationType)
获取
AnnotatedElement 直接的指定类型注解 |
<A extends Annotation> |
getDeclaredAnnotation(Class<A> annotationType)
从
AnnotatedElement 直接声明的注解中获得注解对象 |
Annotation[] |
getDeclaredAnnotations()
获取
AnnotatedElement 直接声明的注解的映射对象 |
<A extends Annotation> |
getDeclaredAnnotationsByType(Class<A> annotationType)
获取
AnnotatedElement 直接声明的指定类型注解 |
Optional<T> |
getDeclaredMapping(Class<? extends Annotation> annotationType)
从
AnnotatedElement 直接声明的注解中获得注解映射对象 |
AnnotatedElement |
getElement()
获取被包装的
AnnotatedElement |
Optional<T> |
getMapping(Class<? extends Annotation> annotationType)
从
AnnotatedElement 直接声明的注解的层级结构中获得注解映射对象 |
int |
hashCode()
获取实例的哈希值
|
boolean |
isAnnotationPresent(Class<? extends Annotation> annotationType)
注解是否是
AnnotatedElement 直接声明的注解,或者在这些注解的层级结构中存在 |
protected boolean |
isNeedMapping(Map<Class<? extends Annotation>,T> mappings,
Annotation annotation)
该注解是否需要映射
默认情况下,已经处理过、或在 java.lang 包下的注解不会被处理 |
Iterator<T> |
iterator()
获取注解映射对象集合的迭代器
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public MetaAnnotatedElement(AnnotatedElement element, BiFunction<T,Annotation,T> mappingFactory)
element
- 被注解元素mappingFactory
- 创建AnnotationMapping
的工厂方法,返回值为null
时将忽略该注解public static <A extends AnnotationMapping<Annotation>> MetaAnnotatedElement<A> create(AnnotatedElement element, BiFunction<A,Annotation,A> mappingFactory)
AnnotatedElement
上的注解结构,该方法会针对相同的AnnotatedElement
缓存映射对象A
- AnnotationMapping
类型element
- 被注解元素mappingFactory
- 创建AnnotationMapping
的工厂方法,返回值为null
时将忽略该注解AnnotatedElement
上的注解结构public Optional<T> getMapping(Class<? extends Annotation> annotationType)
AnnotatedElement
直接声明的注解的层级结构中获得注解映射对象annotationType
- 注解类型public AnnotatedElement getElement()
AnnotatedElement
AnnotatedElement
public Optional<T> getDeclaredMapping(Class<? extends Annotation> annotationType)
AnnotatedElement
直接声明的注解中获得注解映射对象annotationType
- 注解类型public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
AnnotatedElement
直接声明的注解,或者在这些注解的层级结构中存在isAnnotationPresent
in interface AnnotatedElement
annotationType
- 注解元素public <A extends Annotation> A getAnnotation(Class<A> annotationType)
AnnotatedElement
直接声明的注解的层级结构中获得注解对象getAnnotation
in interface AnnotatedElement
A
- 注解类型annotationType
- 注解类型public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationType)
AnnotatedElement
直接声明的注解中获得注解对象getDeclaredAnnotation
in interface AnnotatedElement
A
- 注解类型annotationType
- 注解类型public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType)
AnnotatedElement
直接的指定类型注解getAnnotationsByType
in interface AnnotatedElement
A
- 注解类型annotationType
- 注解类型AnnotatedElement
直接声明的指定类型注解public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationType)
AnnotatedElement
直接声明的指定类型注解getDeclaredAnnotationsByType
in interface AnnotatedElement
A
- 注解类型annotationType
- 注解类型AnnotatedElement
直接声明的指定类型注解public Annotation[] getDeclaredAnnotations()
AnnotatedElement
直接声明的注解的映射对象getDeclaredAnnotations
in interface AnnotatedElement
AnnotatedElement
直接声明的注解的映射对象public Annotation[] getAnnotations()
getAnnotations
in interface AnnotatedElement
public Iterator<T> iterator()
iterator
in interface Iterable<T extends AnnotationMapping<Annotation>>
public boolean equals(Object o)
protected final Map<Class<? extends Annotation>,T> getAnnotationMappings()
protected boolean isNeedMapping(Map<Class<? extends Annotation>,T> mappings, Annotation annotation)
java.lang
包下的注解不会被处理mappings
- 当前已处理的注解annotation
- 注解对象Copyright © 2025. All rights reserved.