public class ResolvedAnnotationMapping extends Object implements AnnotationMapping<Annotation>
注解映射,用于包装并增强一个普通注解对象,
包装后的可以通过getResolvedXXX
获得注解对象或属性值,
可以支持属性别名与属性覆写的属性解析机制。
父子注解
当实例创建时,可通过source
指定当前注解的子注解,多个实例通过该引用,
可以构成一条表示父子/元注解关系的单向链表。
当source
为null
时,认为当前注解即为根注解。
属性别名
注解内的属性可以通过Alias
互相关联,当解析时,
对绑定中的任意一个属性的赋值,会被同步给其他直接或者间接关联的属性。
eg: 若注解存在a <=> b <=> c
的属性别名关系,则对a赋值,此时b、c也会被一并赋值。
属性覆写
当实例中source
不为null
,即当前注解存在至少一个或者多个子注解时,
若在子注解中的同名、同类型的属性,则获取值时将优先获取子注解的值,若该属性存在别名,则别名属性也如此。
属性覆写遵循如下机制:
a <=> b <=> c
的属性别名关系,则覆写a,,属性b、c也会被覆写;
a => b => c
,
此时若c中存在属性可同时被a、b覆写,则优先选择a;
a => b => c
,
此时若b中存在属性被a覆写,而b中被a覆写的属性又覆写c中属性,
则等同于c中被覆写的属性直接被a覆写。
MetaAnnotatedElement
Modifier and Type | Field and Description |
---|---|
protected static int |
NOT_FOUND_INDEX
不存在的属性对应的默认下标
|
Modifier and Type | Method and Description |
---|---|
static ResolvedAnnotationMapping |
create(Annotation annotation,
boolean resolveAnnotationAttribute)
构建一个注解映射对象
|
static ResolvedAnnotationMapping |
create(ResolvedAnnotationMapping source,
Annotation annotation,
boolean resolveAnnotationAttribute)
构建一个注解映射对象,子注解及子注解的子注解们的属性会覆写注解对象的中的同名同名同类型属性,
当一个属性被多个子注解覆写时,优先选择离根注解最接近的注解中的属性用于覆写,
|
boolean |
equals(Object o)
比较两个实例是否相等
|
Annotation |
getAnnotation()
获取注解对象
|
Method |
getAttribute(int index)
根据下标获取注解属性
|
int |
getAttributeIndex(String attributeName,
Class<?> attributeType)
获取注解属性的下标
|
Method[] |
getAttributes()
获取注解属性
|
<R> R |
getAttributeValue(int index)
获取属性值
|
<R> R |
getAttributeValue(String attributeName,
Class<R> attributeType)
获取属性值
|
Annotation |
getResolvedAnnotation()
根据当前映射对象,通过动态代理生成一个类型与被包装注解对象一致的合成注解,该注解相对原生注解:
支持同注解内通过
Alias 构建的别名机制;
支持子注解对元注解的同名同类型属性覆盖机制;
当isResolved() 为false 时,则该方法返回被包装的原始注解对象。 |
<R> R |
getResolvedAttributeValue(int index)
获取解析后的属性值
|
<R> R |
getResolvedAttributeValue(String attributeName,
Class<R> attributeType)
获取解析后的属性值
|
ResolvedAnnotationMapping |
getRoot()
获取根注解
|
boolean |
hasAttribute(int index)
该属性下标是否在注解中存在对应属性
|
boolean |
hasAttribute(String attributeName,
Class<?> attributeType)
注解是否存在指定属性
|
int |
hashCode()
获取实例哈希值
|
boolean |
isResolved()
当前注解是否存在被解析的属性,当该值为
false 时,
通过getResolvedAttributeValue 获得的值皆为注解的原始属性值,
通过getResolvedAnnotation() 获得注解对象为原始的注解对象。 |
boolean |
isRoot()
当前注解是否为根注解
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
annotationType
toString
protected static final int NOT_FOUND_INDEX
public static ResolvedAnnotationMapping create(Annotation annotation, boolean resolveAnnotationAttribute)
annotation
- 注解对象resolveAnnotationAttribute
- 是否解析注解属性,为true
时获得的注解皆支持属性覆盖与属性别名机制public static ResolvedAnnotationMapping create(ResolvedAnnotationMapping source, Annotation annotation, boolean resolveAnnotationAttribute)
source
- 子注解annotation
- 注解对象resolveAnnotationAttribute
- 是否解析注解属性,为true
时获得的注解皆支持属性覆盖与属性别名机制public boolean isRoot()
isRoot
in interface AnnotationMapping<Annotation>
public ResolvedAnnotationMapping getRoot()
public Method[] getAttributes()
getAttributes
in interface AnnotationMapping<Annotation>
public Annotation getAnnotation()
getAnnotation
in interface AnnotationMapping<Annotation>
public boolean isResolved()
false
时,
通过getResolvedAttributeValue
获得的值皆为注解的原始属性值,
通过getResolvedAnnotation()
获得注解对象为原始的注解对象。isResolved
in interface AnnotationMapping<Annotation>
public Annotation getResolvedAnnotation()
Alias
构建的别名机制;isResolved()
为false
时,则该方法返回被包装的原始注解对象。getResolvedAnnotation
in interface AnnotationMapping<Annotation>
isResolved()
为false
则返回的是原始的注解对象public boolean hasAttribute(String attributeName, Class<?> attributeType)
attributeName
- 属性名称attributeType
- 属性类型public boolean hasAttribute(int index)
index
- 属性下标public int getAttributeIndex(String attributeName, Class<?> attributeType)
attributeName
- 属性名称attributeType
- 属性类型public Method getAttribute(int index)
index
- 属性下标public <R> R getAttributeValue(String attributeName, Class<R> attributeType)
getAttributeValue
in interface AnnotationMapping<Annotation>
R
- 返回值类型attributeName
- 属性名称attributeType
- 属性类型public <R> R getAttributeValue(int index)
R
- 返回值类型index
- 属性下标public <R> R getResolvedAttributeValue(String attributeName, Class<R> attributeType)
getResolvedAttributeValue
in interface AnnotationMapping<Annotation>
R
- 返回值类型attributeName
- 属性名称attributeType
- 属性类型public <R> R getResolvedAttributeValue(int index)
R
- 返回值类型index
- 属性下标public boolean equals(Object o)
equals
in interface Annotation
equals
in class Object
o
- 对象public int hashCode()
hashCode
in interface Annotation
hashCode
in class Object
Copyright © 2025. All rights reserved.