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()获得该接口的顺序。
| 限定符和类型 | 字段和说明 |
|---|---|
protected BiFunction<Set<AnnotatedElement>,AnnotatedElement,AnnotatedElement> |
elementFactory
创建
AnnotatedElement的工厂方法,当返回null时将忽略该元素 |
protected AnnotatedElement |
source
被包装的
AnnotatedElement对象 |
forEach, spliteratorprotected final BiFunction<Set<AnnotatedElement>,AnnotatedElement,AnnotatedElement> elementFactory
AnnotatedElement的工厂方法,当返回null时将忽略该元素protected final AnnotatedElement source
AnnotatedElement对象public static HierarchicalAnnotatedElements create(AnnotatedElement element)
element - 被包装的元素,若元素已是HierarchicalAnnotatedElements,则返回其本身HierarchicalAnnotatedElements实例,
当element也是一个HierarchicalAnnotatedElements时,返回element本身public static HierarchicalAnnotatedElements create(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 在接口中 AnnotatedElementannotationType - 注解类型public Annotation[] getAnnotations()
AnnotatedElement上的注解和元注解中获取指定类型的注解getAnnotations 在接口中 AnnotatedElementpublic <A extends Annotation> A getAnnotation(Class<A> annotationType)
AnnotatedElement上的注解和元注解中获取指定类型的注解getAnnotation 在接口中 AnnotatedElementA - 注解类型annotationType - 注解类型public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType)
AnnotatedElement上的注解和元注解中获取指定类型的注解getAnnotationsByType 在接口中 AnnotatedElementA - 注解类型annotationType - 注解类型public Annotation[] getDeclaredAnnotations()
AnnotatedElement上直接声明的注解getDeclaredAnnotations 在接口中 AnnotatedElementpublic <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationType)
AnnotatedElement上直接声明的指定类型注解getDeclaredAnnotation 在接口中 AnnotatedElementA - 注解类型annotationType - 注解类型public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationType)
AnnotatedElement上直接声明的指定类型注解getDeclaredAnnotationsByType 在接口中 AnnotatedElementA - 注解类型annotationType - 注解类型public Iterator<AnnotatedElement> iterator()
iterator 在接口中 Iterable<AnnotatedElement>public AnnotatedElement getElement()
AnnotatedElement对象protected final Set<AnnotatedElement> getElementMappings()
Copyright © 2023. All rights reserved.