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, waitforEach, spliteratorprotected 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 AnnotatedElementannotationType - 注解类型public Annotation[] getAnnotations()
AnnotatedElement上的注解和元注解中获取指定类型的注解getAnnotations in interface AnnotatedElementpublic <A extends Annotation> A getAnnotation(Class<A> annotationType)
AnnotatedElement上的注解和元注解中获取指定类型的注解getAnnotation in interface AnnotatedElementA - 注解类型annotationType - 注解类型public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType)
AnnotatedElement上的注解和元注解中获取指定类型的注解getAnnotationsByType in interface AnnotatedElementA - 注解类型annotationType - 注解类型public Annotation[] getDeclaredAnnotations()
AnnotatedElement上直接声明的注解getDeclaredAnnotations in interface AnnotatedElementpublic <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationType)
AnnotatedElement上直接声明的指定类型注解getDeclaredAnnotation in interface AnnotatedElementA - 注解类型annotationType - 注解类型public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationType)
AnnotatedElement上直接声明的指定类型注解getDeclaredAnnotationsByType in interface AnnotatedElementA - 注解类型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.