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.Selector
annotationScanner, annotationSelector, postProcessors, source, synthesizedAnnotationMap
DEFAULT_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, synthesize
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
annotationType
equals, hashCode, toString
compareTo
getAllSynthesizedAnnotation, getAnnotationPostProcessors, getAnnotationSelector, getSource, getSynthesizedAnnotation, synthesize
public 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 Hierarchical
public int getVerticalDistance()
getVerticalDistance
in interface Hierarchical
getVerticalDistance
in interface SynthesizedAggregateAnnotation
public int getHorizontalDistance()
getHorizontalDistance
in interface Hierarchical
getHorizontalDistance
in interface SynthesizedAggregateAnnotation
protected Map<Class<? extends Annotation>,SynthesizedAnnotation> loadAnnotations()
AbstractAnnotationSynthesizer.source
上的元注解loadAnnotations
in class AbstractAnnotationSynthesizer<List<Annotation>>
public SynthesizedAnnotationAttributeProcessor getAnnotationAttributeProcessor()
getAnnotationAttributeProcessor
in interface SynthesizedAggregateAnnotation
public Object getAttributeValue(String attributeName, Class<?> attributeType)
getAttributeValue
in interface AnnotationAttributeValueProvider
getAttributeValue
in interface SynthesizedAggregateAnnotation
attributeName
- 属性名attributeType
- 属性类型public <T extends Annotation> T getAnnotation(Class<T> annotationType)
getAnnotation
in interface SynthesizedAggregateAnnotation
T
- 注解类型annotationType
- 注解类型public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
isAnnotationPresent
in interface AggregateAnnotation
annotationType
- 注解类型public Annotation[] getAnnotations()
getAnnotations
in interface AggregateAnnotation
public <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 © 2024. All rights reserved.