public class GenericAnnotationSynthesizer extends Object implements AnnotationSynthesizer
AnnotationSynthesizer的基本实现,用于根据注册到实例中的注解,
根据一些规则“合成”具有与原始属性不一样的值的合成注解。
一个可用的注解处理器通常需要经过下述过程完成初始化:
HierarchySelector与注解解析器SyntheticAnnotationResolver;accept(int, int, Annotation)或accept(HierarchicalAnnotation)方法向实例注册注解对象;HierarchySelector的筛选,保留唯一一个有效的注解,
并注册到synthesizedAnnotationMap中,该集合一种注解类型有且仅有一个对应的注解对象;
SyntheticAnnotationResolver对注册了的注解对象进行解析,这个过程通常用于完成注解的各种别名属性的处理;完成上述初始化后,即可通过synthesize(Class)获取指定类型的合成注解。
该操作将以被注册且被处理后的对应类型HierarchicalAnnotation为原料,通过AnnotationProxyFactory生成一个代理注解。
生成的代理注解类型与原始类型一致,但是获取属性值时,会获取到经过处理后的合成注解中的属性值,
它们可能会根据指定的规则返回与原始属性不一样的值。
SyntheticAnnotationResolver| 构造器和说明 |
|---|
GenericAnnotationSynthesizer(Collection<SyntheticAnnotationResolver> resolvers,
HierarchySelector<HierarchicalAnnotation<Annotation>> selector)
创建一个注解合成器
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
accept(HierarchicalAnnotation<Annotation> hierarchicalAnnotation)
向当前实例注册注解,若该类型的注解已经在
synthesizedAnnotationMap中存在,
则使用selector两注解进行选择,并仅保留最终有效的注解 注意:注解注册的先后顺序将会影响到属性的“合并” |
void |
accept(int verticalIndex,
int horizontalIndex,
Annotation annotation)
向当前实例注册注解,若该类型的注解已经在
synthesizedAnnotationMap中存在,
则使用selector两注解进行选择,并仅保留最终有效的注解 注意:注解注册的先后顺序将会影响到属性的“合并” |
Collection<HierarchicalAnnotation<Annotation>> |
getAllAnnotation()
获取全部待合成的注解
|
HierarchicalAnnotation<Annotation> |
getAnnotation(Class<?> annotationType)
获取待合成的注解
|
void |
resolve()
完成解析
|
boolean |
support(Class<? extends Annotation> annotationType)
是否支持合成指定注解
|
<T extends Annotation> |
synthesize(Class<T> annotationType)
基于一组具有一定关系的注解,对其进行“合成”,并最终返回一个指定类型的合成注解
调用该方法前,需要保证至少调用过一次 resolve() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitinterruptedpublic GenericAnnotationSynthesizer(Collection<SyntheticAnnotationResolver> resolvers, HierarchySelector<HierarchicalAnnotation<Annotation>> selector)
resolvers - 注解解析器selector - 注解选择器public void accept(int verticalIndex,
int horizontalIndex,
Annotation annotation)
synthesizedAnnotationMap中存在,
则使用selector两注解进行选择,并仅保留最终有效的注解 accept 在接口中 AnnotationProcessorverticalIndex - 垂直索引。一般表示与扫描器扫描的AnnotatedElement相隔的层级层次。默认从1开始horizontalIndex - 水平索引,一般用于衡量两个注解对象之间被扫描到的先后顺序。默认从1开始annotation - 被扫描到的注解对象public void accept(HierarchicalAnnotation<Annotation> hierarchicalAnnotation)
synthesizedAnnotationMap中存在,
则使用selector两注解进行选择,并仅保留最终有效的注解 accept 在接口中 AnnotationSynthesizerhierarchicalAnnotation - 注解public void resolve()
public HierarchicalAnnotation<Annotation> getAnnotation(Class<?> annotationType)
getAnnotation 在接口中 AnnotationSynthesizerannotationType - 注解类型public boolean support(Class<? extends Annotation> annotationType)
support 在接口中 AnnotationSynthesizerannotationType - 注解类型public Collection<HierarchicalAnnotation<Annotation>> getAllAnnotation()
getAllAnnotation 在接口中 AnnotationSynthesizerpublic <T extends Annotation> T synthesize(Class<T> annotationType)
resolve()synthesize 在接口中 AnnotationSynthesizerT - 注解类型annotationType - 注解类型Copyright © 2022. All rights reserved.