Class HierarchicalAnnotatedElements
java.lang.Object
org.miaixz.bus.core.lang.annotation.resolve.elements.HierarchicalAnnotatedElements
- All Implemented Interfaces:
Iterable<AnnotatedElement>,AnnotatedElement
public class HierarchicalAnnotatedElements
extends Object
implements AnnotatedElement, Iterable<AnnotatedElement>
表示一组处于在层级结构中具有关联关系的AnnotatedElement,创建实例时,
将扫描指定AnnotatedElement的层级结构中的所有AnnotatedElement,
并将其包装为MetaAnnotatedElement。
eg:
若存在元素A有对应父类与父接口B,C,
则根据A生成的HierarchicalAnnotatedElements实例将同时包含A,B,C,
该实例同时支持对这三个实例上直接声明的注解,以及这些注解的元注解进行访问。
注解搜索范围
在当前实例中,针对带有和不带declared关键字的方法定义如下:
- 当方法带有declared关键字时,查找范围仅限被保存的所有
AnnotatedElement上直接声明的注解; -
当方法不带declared关键字时,查找范围包括:
- 被保存的所有
AnnotatedElement上直接声明的注解,及这些注解的元注解; - 若是类,则包括其所有父类和所有父接口上声明的注解和元注解;
-
若是方法,且不是静态/私有/被
final修饰的方法时, 则额外获取包括其声明类的所有父类和所有父接口中,与该方法具有相同方法签名的方法上的注解和元注解;
- 被保存的所有
扫描顺序
当AnnotatedElement具有层级结构式,会按照广度优先扫描其本身(元素是Class)、
或其声明类(元素是Method)的层级结构。
在该过程中,总是先扫描父类,再扫描父接口,
若存在多个父接口,则其扫描顺序遵循从Class.getInterfaces()获得该接口的顺序。
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BiFunction<Set<AnnotatedElement>, AnnotatedElement, AnnotatedElement> 创建AnnotatedElement的工厂方法,当返回null时将忽略该元素protected final AnnotatedElement被包装的AnnotatedElement对象 -
Method Summary
Modifier and TypeMethodDescriptionboolean比较两个实例是否相等<A extends Annotation>
AgetAnnotation(Class<A> annotationType) 从层级结构中所有AnnotatedElement上的注解和元注解中获取指定类型的注解从层级结构中所有AnnotatedElement上的注解和元注解中获取指定类型的注解<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上直接声明的指定类型注解获取被包装的原始AnnotatedElement对象final Set<AnnotatedElement> 获取当前元素及层级结构中的关联元素的映射对象,结果只读inthashCode()获取实例的哈希值booleanisAnnotationPresent(Class<? extends Annotation> annotationType) 注解是否在层级结构中所有AnnotatedElement上的注解和元注解中存在protected booleanisMatchMethod(Method source, Method target) 检验方法的签名是否与原始方法匹配iterator()获取注解元素映射集合的迭代器of(AnnotatedElement element) 创建一个分层注解元素of(AnnotatedElement element, BiFunction<Set<AnnotatedElement>, AnnotatedElement, AnnotatedElement> elementFactory) 创建一个分层注解元素Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
elementFactory
创建AnnotatedElement的工厂方法,当返回null时将忽略该元素 -
source
被包装的AnnotatedElement对象
-
-
Method Details
-
of
创建一个分层注解元素- Parameters:
element- 被包装的元素,若元素已是HierarchicalAnnotatedElements,则返回其本身- Returns:
HierarchicalAnnotatedElements实例, 当element也是一个HierarchicalAnnotatedElements时,返回element本身
-
of
public static HierarchicalAnnotatedElements of(AnnotatedElement element, BiFunction<Set<AnnotatedElement>, AnnotatedElement, AnnotatedElement> elementFactory) 创建一个分层注解元素- Parameters:
element- 被包装的元素,若元素已是HierarchicalAnnotatedElements,则返回其本身elementFactory- 创建AnnotatedElement的工厂方法,当返回null时将忽略该元素- Returns:
HierarchicalAnnotatedElements实例, 当element也是一个HierarchicalAnnotatedElements时,返回element本身
-
isAnnotationPresent
注解是否在层级结构中所有AnnotatedElement上的注解和元注解中存在- Specified by:
isAnnotationPresentin interfaceAnnotatedElement- Parameters:
annotationType- 注解类型- Returns:
- 是否
-
getAnnotations
从层级结构中所有AnnotatedElement上的注解和元注解中获取指定类型的注解- Specified by:
getAnnotationsin interfaceAnnotatedElement- Returns:
- 注解对象
-
getAnnotation
从层级结构中所有AnnotatedElement上的注解和元注解中获取指定类型的注解- Specified by:
getAnnotationin interfaceAnnotatedElement- Type Parameters:
A- 注解类型- Parameters:
annotationType- 注解类型- Returns:
- 注解对象
-
getAnnotationsByType
从层级结构中所有AnnotatedElement上的注解和元注解中获取指定类型的注解- Specified by:
getAnnotationsByTypein interfaceAnnotatedElement- Type Parameters:
A- 注解类型- Parameters:
annotationType- 注解类型- Returns:
- 注解对象
-
getDeclaredAnnotations
获取层级结构中所有AnnotatedElement上直接声明的注解- Specified by:
getDeclaredAnnotationsin interfaceAnnotatedElement- Returns:
- 注解对象
-
getDeclaredAnnotation
获取层级结构中所有AnnotatedElement上直接声明的指定类型注解- Specified by:
getDeclaredAnnotationin interfaceAnnotatedElement- Type Parameters:
A- 注解类型- Parameters:
annotationType- 注解类型- Returns:
- 注解对象
-
getDeclaredAnnotationsByType
获取层级结构中所有AnnotatedElement上直接声明的指定类型注解- Specified by:
getDeclaredAnnotationsByTypein interfaceAnnotatedElement- Type Parameters:
A- 注解类型- Parameters:
annotationType- 注解类型- Returns:
- 注解对象
-
iterator
获取注解元素映射集合的迭代器- Specified by:
iteratorin interfaceIterable<AnnotatedElement>- Returns:
- 迭代器
-
getElement
获取被包装的原始AnnotatedElement对象- Returns:
- 注解对象
-
equals
比较两个实例是否相等 -
hashCode
public int hashCode()获取实例的哈希值 -
getElementMappings
获取当前元素及层级结构中的关联元素的映射对象,结果只读- Returns:
- 元素映射对象
-
isMatchMethod
检验方法的签名是否与原始方法匹配- Parameters:
source- 原始的方法target- 比较的方法- Returns:
- 是否
-