public class GenericSynthesizedAggregateAnnotation extends AbstractAnnotationSynthesizer<List<Annotation>> implements SynthesizedAggregateAnnotation
SynthesizedAggregateAnnotation的基本实现,表示基于多个注解对象,
或多个根注解对象与他们的多层元注解对象的聚合得到的注解。
假设现有注解A,若指定的AbstractAnnotationSynthesizer.annotationScanner支持扫描注解A的元注解,
且A上存在元注解B,B上存在元注解C,则对注解A进行解析,将得到包含根注解A,以及其元注解B、C在内的合成元注解聚合GenericSynthesizedAggregateAnnotation。
从AnnotatedElement的角度来说,得到的合成注解是一个同时承载有ABC三个注解对象的被注解元素,
因此通过调用AnnotatedElement的相关方法将返回对应符合语义的注解对象。
在扫描指定根注解及其元注解时,若在不同的层级出现了类型相同的注解实例,
将会根据实例化时指定的SynthesizedAnnotationSelector选择最优的注解,
完成对根注解及其元注解的扫描后,合成注解中每种类型的注解对象都将有且仅有一个。
默认情况下,将使用SynthesizedAnnotationSelector.NEAREST_AND_OLDEST_PRIORITY作为选择器,
此时若出现扫描时得到了多个同类型的注解对象,有且仅有最接近根注解的注解对象会被作为有效注解。
当扫描的注解对象经过SynthesizedAnnotationSelector处理后,
将会被转为GenericSynthesizedAggregateAnnotation.MetaAnnotation,并使用在实例化时指定的AliasAnnotationPostProcessor
进行后置处理。
默认情况下,将注册以下后置处理器以对Alias与Link和其扩展注解提供支持:
GenericSynthesizedAggregateAnnotation支持通过getAttributeValue(String, Class),
或通过AbstractAnnotationSynthesizer.synthesize(Class)获得注解代理对象后获取指定类型的注解属性值,
返回的属性值将根据合成注解中对应原始注解属性上的Alias与Link注解而有所变化。
通过当前实例获取属性值时,将经过SynthesizedAnnotationAttributeProcessor的处理。
默认情况下,实例将会注册CacheableSynthesizedAnnotationAttributeProcessor,
该处理器将令元注解中与子注解类型与名称皆一致的属性被子注解的属性覆盖,并且缓存最终获取到的属性值。
AnnotationUtil,
SynthesizedAnnotationProxy,
SynthesizedAnnotationSelector,
SynthesizedAnnotationAttributeProcessor,
SynthesizedAnnotationPostProcessor,
AnnotationSynthesizer,
AnnotationScanner| Modifier and Type | Class and Description |
|---|---|
static class |
GenericSynthesizedAggregateAnnotation.MetaAnnotation
注解包装类,表示
AbstractAnnotationSynthesizer.source以及AbstractAnnotationSynthesizer.source所属层级结构中的全部关联注解对象 |
Hierarchical.SelectorannotationScanner, annotationSelector, postProcessors, source, synthesizedAnnotationMapDEFAULT_HIERARCHICAL_COMPARATOR| Constructor and Description |
|---|
GenericSynthesizedAggregateAnnotation(Annotation... source)
基于指定根注解,为其与其元注解的层级结构中的全部注解构造一个合成注解。
|
GenericSynthesizedAggregateAnnotation(List<Annotation> source,
AnnotationScanner annotationScanner)
基于指定根注解,为其层级结构中的全部注解构造一个合成注解。
|
GenericSynthesizedAggregateAnnotation(List<Annotation> source,
SynthesizedAnnotationSelector annotationSelector,
SynthesizedAnnotationAttributeProcessor attributeProcessor,
Collection<SynthesizedAnnotationPostProcessor> annotationPostProcessors,
AnnotationScanner annotationScanner)
基于指定根注解,为其层级结构中的全部注解构造一个合成注解
|
| Modifier and Type | Method and Description |
|---|---|
<T extends Annotation> |
getAnnotation(Class<T> annotationType)
获取合成注解中包含的指定注解
|
SynthesizedAnnotationAttributeProcessor |
getAnnotationAttributeProcessor()
获取合成注解属性处理器
|
Annotation[] |
getAnnotations()
获取合成注解中包含的全部注解
|
Object |
getAttributeValue(String attributeName,
Class<?> attributeType)
根据指定的属性名与属性类型获取对应的属性值,若存在
Alias则获取Alias.value()指定的别名属性的值
当不同层级的注解之间存在同名同类型属性时,将优先获取更接近根注解的属性 |
int |
getHorizontalDistance()
获取与根对象的水平距离
|
Object |
getRoot()
获取根对象
|
int |
getVerticalDistance()
获取与根对象的垂直距离
|
boolean |
isAnnotationPresent(Class<? extends Annotation> annotationType)
当前合成注解中是否存在指定元注解
|
protected Map<Class<? extends Annotation>,SynthesizedAnnotation> |
loadAnnotations()
按广度优先扫描
AbstractAnnotationSynthesizer.source上的元注解 |
<T extends Annotation> |
synthesize(Class<T> annotationType,
SynthesizedAnnotation annotation)
若合成注解在存在指定元注解,则使用动态代理生成一个对应的注解实例
|
getAllSynthesizedAnnotation, getAnnotationPostProcessors, getAnnotationSelector, getSource, getSynthesizedAnnotation, synthesizeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitannotationTypeequals, hashCode, toStringcompareTogetAllSynthesizedAnnotation, getAnnotationPostProcessors, getAnnotationSelector, getSource, getSynthesizedAnnotation, synthesizepublic GenericSynthesizedAggregateAnnotation(Annotation... source)
source - 源注解public GenericSynthesizedAggregateAnnotation(List<Annotation> source, AnnotationScanner annotationScanner)
source - 源注解annotationScanner - 注解扫描器,该扫描器必须支持扫描注解类public GenericSynthesizedAggregateAnnotation(List<Annotation> source, SynthesizedAnnotationSelector annotationSelector, SynthesizedAnnotationAttributeProcessor attributeProcessor, Collection<SynthesizedAnnotationPostProcessor> annotationPostProcessors, AnnotationScanner annotationScanner)
source - 当前查找的注解对象annotationSelector - 合成注解选择器attributeProcessor - 注解属性处理器annotationPostProcessors - 注解后置处理器annotationScanner - 注解扫描器,该扫描器必须支持扫描注解类public Object getRoot()
getRoot in interface Hierarchicalpublic int getVerticalDistance()
getVerticalDistance in interface HierarchicalgetVerticalDistance in interface SynthesizedAggregateAnnotationpublic int getHorizontalDistance()
getHorizontalDistance in interface HierarchicalgetHorizontalDistance in interface SynthesizedAggregateAnnotationprotected Map<Class<? extends Annotation>,SynthesizedAnnotation> loadAnnotations()
AbstractAnnotationSynthesizer.source上的元注解loadAnnotations in class AbstractAnnotationSynthesizer<List<Annotation>>public SynthesizedAnnotationAttributeProcessor getAnnotationAttributeProcessor()
getAnnotationAttributeProcessor in interface SynthesizedAggregateAnnotationpublic Object getAttributeValue(String attributeName, Class<?> attributeType)
getAttributeValue in interface AnnotationAttributeValueProvidergetAttributeValue in interface SynthesizedAggregateAnnotationattributeName - 属性名attributeType - 属性类型public <T extends Annotation> T getAnnotation(Class<T> annotationType)
getAnnotation in interface SynthesizedAggregateAnnotationT - 注解类型annotationType - 注解类型public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
isAnnotationPresent in interface AggregateAnnotationannotationType - 注解类型public Annotation[] getAnnotations()
getAnnotations in interface AggregateAnnotationpublic <T extends Annotation> T synthesize(Class<T> annotationType, SynthesizedAnnotation annotation)
synthesize in class AbstractAnnotationSynthesizer<List<Annotation>>T - 注解类型annotationType - 注解类型annotation - 合成注解对象SynthesizedAnnotationProxy.create(Class, AnnotationAttributeValueProvider, SynthesizedAnnotation)Copyright © 2025. All rights reserved.