public class HierarchicalAnnotatedElements extends Object implements AnnotatedElement, Iterable<AnnotatedElement>
表示一组处于在层级结构中具有关联关系的AnnotatedElement
,创建实例时,
将扫描指定AnnotatedElement
的层级结构中的所有AnnotatedElement
,
并将其包装为MetaAnnotatedElement
。
eg:
若存在元素A有对应父类与父接口B,C,
则根据A生成的HierarchicalAnnotatedElements
实例将同时包含A,B,C,
该实例同时支持对这三个实例上直接声明的注解,以及这些注解的元注解进行访问。
注解搜索范围
在当前实例中,针对带有和不带declared关键字的方法定义如下:
AnnotatedElement
上直接声明的注解;AnnotatedElement
上直接声明的注解,及这些注解的元注解;final
修饰的方法时,
则额外获取包括其声明类的所有父类和所有父接口中,与该方法具有相同方法签名的方法上的注解和元注解;
扫描顺序
当AnnotatedElement
具有层级结构式,会按照广度优先扫描其本身(元素是Class
)、
或其声明类(元素是Method
)的层级结构。
在该过程中,总是先扫描父类,再扫描父接口,
若存在多个父接口,则其扫描顺序遵循从Class.getInterfaces()
获得该接口的顺序。
Modifier and Type | Field and Description |
---|---|
protected BiFunction<Set<AnnotatedElement>,AnnotatedElement,AnnotatedElement> |
elementFactory
创建
AnnotatedElement 的工厂方法,当返回null 时将忽略该元素 |
protected AnnotatedElement |
source
被包装的
AnnotatedElement 对象 |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
protected final BiFunction<Set<AnnotatedElement>,AnnotatedElement,AnnotatedElement> elementFactory
AnnotatedElement
的工厂方法,当返回null
时将忽略该元素protected final AnnotatedElement source
AnnotatedElement
对象public static HierarchicalAnnotatedElements of(AnnotatedElement element)
element
- 被包装的元素,若元素已是HierarchicalAnnotatedElements
,则返回其本身HierarchicalAnnotatedElements
实例,
当element
也是一个HierarchicalAnnotatedElements
时,返回element
本身public static HierarchicalAnnotatedElements of(AnnotatedElement element, BiFunction<Set<AnnotatedElement>,AnnotatedElement,AnnotatedElement> elementFactory)
element
- 被包装的元素,若元素已是HierarchicalAnnotatedElements
,则返回其本身elementFactory
- 创建AnnotatedElement
的工厂方法,当返回null
时将忽略该元素HierarchicalAnnotatedElements
实例,
当element
也是一个HierarchicalAnnotatedElements
时,返回element
本身public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
AnnotatedElement
上的注解和元注解中存在isAnnotationPresent
in interface AnnotatedElement
annotationType
- 注解类型public Annotation[] getAnnotations()
AnnotatedElement
上的注解和元注解中获取指定类型的注解getAnnotations
in interface AnnotatedElement
public <A extends Annotation> A getAnnotation(Class<A> annotationType)
AnnotatedElement
上的注解和元注解中获取指定类型的注解getAnnotation
in interface AnnotatedElement
A
- 注解类型annotationType
- 注解类型public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType)
AnnotatedElement
上的注解和元注解中获取指定类型的注解getAnnotationsByType
in interface AnnotatedElement
A
- 注解类型annotationType
- 注解类型public Annotation[] getDeclaredAnnotations()
AnnotatedElement
上直接声明的注解getDeclaredAnnotations
in interface AnnotatedElement
public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationType)
AnnotatedElement
上直接声明的指定类型注解getDeclaredAnnotation
in interface AnnotatedElement
A
- 注解类型annotationType
- 注解类型public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationType)
AnnotatedElement
上直接声明的指定类型注解getDeclaredAnnotationsByType
in interface AnnotatedElement
A
- 注解类型annotationType
- 注解类型public Iterator<AnnotatedElement> iterator()
iterator
in interface Iterable<AnnotatedElement>
public AnnotatedElement getElement()
AnnotatedElement
对象public boolean equals(Object o)
public final Set<AnnotatedElement> getElementMappings()
Copyright © 2025. All rights reserved.