Class MetaAnnotatedElement<T extends AnnotationMapping<Annotation>>
java.lang.Object
org.miaixz.bus.core.lang.annotation.resolve.elements.MetaAnnotatedElement<T>
- Type Parameters:
T- AnnotationMapping类型
- All Implemented Interfaces:
Iterable<T>,AnnotatedElement
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)方法用于只能获得一个注解对象。
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMetaAnnotatedElement(AnnotatedElement element, BiFunction<T, Annotation, T> mappingFactory) 解析注解属性 -
Method Summary
Modifier and TypeMethodDescriptionstatic <A extends AnnotationMapping<Annotation>>
MetaAnnotatedElement<A> create(AnnotatedElement element, BiFunction<A, Annotation, A> mappingFactory) 获取AnnotatedElement上的注解结构,该方法会针对相同的AnnotatedElement缓存映射对象boolean比较两个实例是否相等<A extends Annotation>
AgetAnnotation(Class<A> annotationType) 从AnnotatedElement直接声明的注解的层级结构中获得注解对象protected final Map<Class<? extends Annotation>, T> 获取注解映射,若当前实例未完成初始化则先进行初始化获取所有注解<A extends Annotation>
A[]getAnnotationsByType(Class<A> annotationType) 获取AnnotatedElement直接的指定类型注解<A extends Annotation>
AgetDeclaredAnnotation(Class<A> annotationType) 从AnnotatedElement直接声明的注解中获得注解对象获取AnnotatedElement直接声明的注解的映射对象<A extends Annotation>
A[]getDeclaredAnnotationsByType(Class<A> annotationType) 获取AnnotatedElement直接声明的指定类型注解getDeclaredMapping(Class<? extends Annotation> annotationType) 从AnnotatedElement直接声明的注解中获得注解映射对象获取被包装的AnnotatedElementgetMapping(Class<? extends Annotation> annotationType) 从AnnotatedElement直接声明的注解的层级结构中获得注解映射对象inthashCode()获取实例的哈希值booleanisAnnotationPresent(Class<? extends Annotation> annotationType) 注解是否是AnnotatedElement直接声明的注解,或者在这些注解的层级结构中存在protected booleanisNeedMapping(Map<Class<? extends Annotation>, T> mappings, Annotation annotation) 该注解是否需要映射 默认情况下,已经处理过、或在java.lang包下的注解不会被处理iterator()获取注解映射对象集合的迭代器Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
MetaAnnotatedElement
解析注解属性- Parameters:
element- 被注解元素mappingFactory- 创建AnnotationMapping的工厂方法,返回值为null时将忽略该注解
-
-
Method Details
-
create
public static <A extends AnnotationMapping<Annotation>> MetaAnnotatedElement<A> create(AnnotatedElement element, BiFunction<A, Annotation, A> mappingFactory) 获取AnnotatedElement上的注解结构,该方法会针对相同的AnnotatedElement缓存映射对象- Type Parameters:
A-AnnotationMapping类型- Parameters:
element- 被注解元素mappingFactory- 创建AnnotationMapping的工厂方法,返回值为null时将忽略该注解- Returns:
AnnotatedElement上的注解结构
-
getMapping
从AnnotatedElement直接声明的注解的层级结构中获得注解映射对象- Parameters:
annotationType- 注解类型- Returns:
- 注解映射对象
-
getElement
获取被包装的AnnotatedElement- Returns:
- 被包装的
AnnotatedElements
-
getDeclaredMapping
从AnnotatedElement直接声明的注解中获得注解映射对象- Parameters:
annotationType- 注解类型- Returns:
- 注解映射对象
-
isAnnotationPresent
注解是否是AnnotatedElement直接声明的注解,或者在这些注解的层级结构中存在- Specified by:
isAnnotationPresentin interfaceAnnotatedElement- Parameters:
annotationType- 注解元素- Returns:
- 是否
-
getAnnotation
从AnnotatedElement直接声明的注解的层级结构中获得注解对象- Specified by:
getAnnotationin interfaceAnnotatedElement- Type Parameters:
A- 注解类型- Parameters:
annotationType- 注解类型- Returns:
- 注解对象
-
getDeclaredAnnotation
从AnnotatedElement直接声明的注解中获得注解对象- Specified by:
getDeclaredAnnotationin interfaceAnnotatedElement- Type Parameters:
A- 注解类型- Parameters:
annotationType- 注解类型- Returns:
- 注解对象
-
getAnnotationsByType
获取AnnotatedElement直接的指定类型注解- Specified by:
getAnnotationsByTypein interfaceAnnotatedElement- Type Parameters:
A- 注解类型- Parameters:
annotationType- 注解类型- Returns:
AnnotatedElement直接声明的指定类型注解
-
getDeclaredAnnotationsByType
获取AnnotatedElement直接声明的指定类型注解- Specified by:
getDeclaredAnnotationsByTypein interfaceAnnotatedElement- Type Parameters:
A- 注解类型- Parameters:
annotationType- 注解类型- Returns:
AnnotatedElement直接声明的指定类型注解
-
getDeclaredAnnotations
获取AnnotatedElement直接声明的注解的映射对象- Specified by:
getDeclaredAnnotationsin interfaceAnnotatedElement- Returns:
AnnotatedElement直接声明的注解的映射对象
-
getAnnotations
获取所有注解- Specified by:
getAnnotationsin interfaceAnnotatedElement- Returns:
- 所有注解
-
iterator
获取注解映射对象集合的迭代器- Specified by:
iteratorin interfaceIterable<T extends AnnotationMapping<Annotation>>- Returns:
- 迭代器
-
equals
比较两个实例是否相等 -
hashCode
public int hashCode()获取实例的哈希值 -
getAnnotationMappings
获取注解映射,若当前实例未完成初始化则先进行初始化- Returns:
- 不可变的注解映射集合
-
isNeedMapping
该注解是否需要映射 默认情况下,已经处理过、或在java.lang包下的注解不会被处理- Parameters:
mappings- 当前已处理的注解annotation- 注解对象- Returns:
- 是否
-