This commit is contained in:
Looly 2022-07-17 22:13:55 +08:00
parent 89dfeb5a76
commit ca10c8e7b9
6 changed files with 58 additions and 37 deletions

View File

@ -98,9 +98,10 @@ public abstract class AbstractLinkAnnotationPostProcessor implements Synthesized
*
* @param annotation {@link Link}注解
* @param synthesizer 注解合成器
* @param defaultType 默认类型
* @return {@link SynthesizedAnnotation}
*/
protected SynthesizedAnnotation getLinkedAnnotation(
Link annotation, AnnotationSynthesizer synthesizer, Class<? extends Annotation> defaultType) {
protected SynthesizedAnnotation getLinkedAnnotation(Link annotation, AnnotationSynthesizer synthesizer, Class<? extends Annotation> defaultType) {
final Class<?> targetAnnotationType = getLinkedAnnotationType(annotation, defaultType);
return synthesizer.getSynthesizedAnnotation(targetAnnotationType);
}

View File

@ -22,12 +22,16 @@ public @interface AliasFor {
/**
* 产生关联的注解类型当不指定时默认指注释的属性所在的类
*
* @return 注解类型
*/
@Link(annotation = Link.class, attribute = "annotation", type = RelationType.FORCE_ALIAS_FOR)
Class<? extends Annotation> annotation() default Annotation.class;
/**
* {@link #annotation()}指定注解中关联的属性
*
* @return 关联属性
*/
@Link(annotation = Link.class, attribute = "attribute", type = RelationType.FORCE_ALIAS_FOR)
String attribute() default "";

View File

@ -19,12 +19,16 @@ public @interface ForceAliasFor {
/**
* 产生关联的注解类型当不指定时默认指注释的属性所在的类
*
* @return 关联注解类型
*/
@Link(annotation = Link.class, attribute = "annotation", type = RelationType.FORCE_ALIAS_FOR)
Class<? extends Annotation> annotation() default Annotation.class;
/**
* {@link #annotation()}指定注解中关联的属性
*
* @return 关联的属性
*/
@Link(annotation = Link.class, attribute = "attribute", type = RelationType.FORCE_ALIAS_FOR)
String attribute() default "";

View File

@ -4,7 +4,7 @@ import java.lang.annotation.*;
/**
* <p>用于在同一注解中或具有一定关联的不同注解的属性中表明这些属性之间具有特定的关联关系
* 在通过{@link SynthesizedAggregateAnnotation}获取合成注解后合成注解获取属性值时会根据该注解进行调整<br />
* 在通过{@link SynthesizedAggregateAnnotation}获取合成注解后合成注解获取属性值时会根据该注解进行调整<br>
*
* <p>该注解存在三个字注解{@link MirrorFor}{@link ForceAliasFor}{@link AliasFor}
* 使用三个子注解等同于{@link Link}但是需要注意的是
@ -27,16 +27,22 @@ public @interface Link {
/**
* 产生关联的注解类型当不指定时默认指注释的属性所在的类
*
* @return 关联的注解类型
*/
Class<? extends Annotation> annotation() default Annotation.class;
/**
* {@link #annotation()}指定注解中关联的属性
*
* @return 属性名
*/
String attribute() default "";
/**
* {@link #attribute()}指定属性与当前注解的属性建的关联关系类型
*
* @return 关系类型
*/
RelationType type() default RelationType.MIRROR_FOR;

View File

@ -25,12 +25,16 @@ public @interface MirrorFor {
/**
* 产生关联的注解类型当不指定时默认指注释的属性所在的类
*
* @return 关联的注解类型
*/
@Link(annotation = Link.class, attribute = "annotation", type = RelationType.FORCE_ALIAS_FOR)
Class<? extends Annotation> annotation() default Annotation.class;
/**
* {@link #annotation()}指定注解中关联的属性
*
* @return 属性名
*/
@Link(annotation = Link.class, attribute = "attribute", type = RelationType.FORCE_ALIAS_FOR)
String attribute() default "";

View File

@ -34,6 +34,7 @@ public class SynthesizedAnnotationProxy implements InvocationHandler {
/**
* 创建一个代理注解生成的代理对象将是{@link SyntheticProxyAnnotation}与指定的注解类的子类
*
* @param <T> 注解类型
* @param annotationType 注解类型
* @param annotationAttributeValueProvider 注解属性值获取器
* @param annotation 合成注解
@ -61,6 +62,7 @@ public class SynthesizedAnnotationProxy implements InvocationHandler {
/**
* 创建一个代理注解生成的代理对象将是{@link SyntheticProxyAnnotation}与指定的注解类的子类
*
* @param <T> 注解类型
* @param annotationType 注解类型
* @param annotation 合成注解
* @return 代理注解
@ -71,7 +73,7 @@ public class SynthesizedAnnotationProxy implements InvocationHandler {
}
/**
* 该类是否为通过{@link SynthesizedAnnotationProxy}生成的代理类
* 该类是否为通过{@code SynthesizedAnnotationProxy}生成的代理类
*
* @param annotationType 注解类型
* @return 是否
@ -105,12 +107,12 @@ public class SynthesizedAnnotationProxy implements InvocationHandler {
methods.put("getRoot", (method, args) -> annotation.getRoot());
methods.put("getVerticalDistance", (method, args) -> annotation.getVerticalDistance());
methods.put("getHorizontalDistance", (method, args) -> annotation.getHorizontalDistance());
methods.put("hasAttribute", (method, args) -> annotation.hasAttribute((String)args[0], (Class<?>)args[1]));
methods.put("hasAttribute", (method, args) -> annotation.hasAttribute((String) args[0], (Class<?>) args[1]));
methods.put("getAttributes", (method, args) -> annotation.getAttributes());
methods.put("setAttribute", (method, args) -> {
throw new UnsupportedOperationException("proxied annotation can not reset attributes");
});
methods.put("getAttributeValue", (method, args) -> annotation.getAttributeValue((String)args[0]));
methods.put("getAttributeValue", (method, args) -> annotation.getAttributeValue((String) args[0]));
methods.put("annotationType", (method, args) -> annotation.annotationType());
for (final Method declaredMethod : ClassUtil.getDeclaredMethods(annotation.getAnnotation().annotationType())) {
methods.put(declaredMethod.getName(), (method, args) -> proxyAttributeValue(method));