diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotation.java b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotation.java index 8d81701b0..62a3dc91a 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotation.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotation.java @@ -3,23 +3,24 @@ package cn.hutool.core.annotation; import java.lang.annotation.Annotation; /** - * 表示一个处于合成状态的注解对象 + * 用于在{@link SyntheticAnnotation}中表示一个处于合成状态的注解对象 * * @author huangchengxing + * @see SyntheticAnnotation */ public interface SynthesizedAnnotation extends Annotation { /** * 获取该合成注解对应的根节点 * - * @return 数据源 + * @return 合成注解对应的根节点 */ Object getRoot(); /** * 该合成注解是为根对象 * - * @return 对象 + * @return 根对象 */ default boolean isRoot() { return getRoot() == this; diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationAttributeProcessor.java b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationAttributeProcessor.java index 83f7c274b..ad0464f5b 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationAttributeProcessor.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationAttributeProcessor.java @@ -3,7 +3,7 @@ package cn.hutool.core.annotation; import java.util.Collection; /** - * 合成注解属性选择器。用于中合成注解中从指定类型的注解里获取到对应的属性值 + * 合成注解属性选择器。用于在{@link SyntheticAnnotation}中从指定类型的合成注解里获取到对应的属性值 * * @author huangchengxing */ @@ -13,8 +13,8 @@ public interface SynthesizedAnnotationAttributeProcessor { /** * 从一批被合成注解中,获取指定名称与类型的属性值 * - * @param attributeName 属性名称 - * @param attributeType 属性类型 + * @param attributeName 属性名称 + * @param attributeType 属性类型 * @param synthesizedAnnotations 被合成的注解 * @param 属性类型 * @return 属性值 diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotation.java b/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotation.java index 420e0f5c9..55c0c44eb 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotation.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotation.java @@ -4,9 +4,27 @@ import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; /** - * 表示基于特定规则聚合的一组注解 + * 表示基于特定规则聚合的一组注解对象 + * + *

合成注解一般被用于处理类层级结果中具有直接或间接关联的注解对象, + * 当实例被创建时,会获取到这些注解对象,并使用{@link SynthesizedAnnotationSelector}对类型相同的注解进行过滤, + * 并最终得到类型不重复的有效注解对象。这些有效注解将被包装为{@link SynthesizedAnnotation}, + * 然后最终用于“合成”一个{@link SynthesizedAnnotation}。 + * + *

合成注解可以作为一个特殊的{@link Annotation}或者{@link AnnotatedElement}, + * 当调用{@link Annotation}的方法时,应当返回当前实例本身的有效信息, + * 而当调用{@link AnnotatedElement}的方法时,应当返回用于合成该对象的相关注解的信息。 + * + *

合成注解允许通过{@link #syntheticAnnotation(Class)}合成一个指定的注解对象, + * 该方法返回的注解对象可能是原始的注解对象,也有可能通过动态代理的方式生成, + * 该对象实例的属性不一定来自对象本身,而是来自于经过{@link SynthesizedAnnotationAttributeProcessor} + * 处理后的、用于合成当前实例的全部关联注解的相关属性。 * * @author huangchengxing + * @see SynthesizedAnnotation + * @see SynthesizedAnnotationSelector + * @see SynthesizedAnnotationAttributeProcessor + * @see SyntheticMetaAnnotation */ public interface SyntheticAnnotation extends Annotation, AnnotatedElement { diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotationProxy.java b/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotationProxy.java index d27a650f4..5cf2d1723 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotationProxy.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotationProxy.java @@ -86,7 +86,7 @@ class SyntheticAnnotationProxy implements InvocationHandler { methods.put("hasAttribute", (method, args) -> annotation.hasAttribute((String)args[0], (Class)args[1])); methods.put("getAttribute", (method, args) -> annotation.getAttribute((String)args[0])); methods.put("annotationType", (method, args) -> annotation.annotationType()); - for (Method declaredMethod : annotation.getAnnotation().annotationType().getDeclaredMethods()) { + for (final Method declaredMethod : annotation.getAnnotation().annotationType().getDeclaredMethods()) { methods.put(declaredMethod.getName(), (method, args) -> proxyAttributeValue(method)); } }