From 18f67274b81179c061d9336f6e90b9e8de51d7c9 Mon Sep 17 00:00:00 2001 From: huangchengxing <841396397@qq.com> Date: Wed, 13 Jul 2022 22:42:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=B1=BB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractLinkAnnotationPostProcessor.java | 8 +-- .../AbstractSynthesizedAnnotation.java | 8 +-- .../core/annotation/AggregateAnnotation.java | 27 ++++++++++ .../AliasAnnotationPostProcessor.java | 2 +- .../AliasLinkAnnotationPostProcessor.java | 6 +-- .../core/annotation/AnnotationAggregator.java | 49 ------------------- .../core/annotation/AnnotationAttribute.java | 2 +- .../core/annotation/AnnotationUtil.java | 8 +-- .../java/cn/hutool/core/annotation/Link.java | 4 +- .../MirrorLinkAnnotationPostProcessor.java | 2 +- .../hutool/core/annotation/RelationType.java | 6 +-- ...va => SynthesizedAggregateAnnotation.java} | 35 ++++++++----- .../annotation/SynthesizedAnnotation.java | 6 +-- ...nthesizedAnnotationAttributeProcessor.java | 2 +- .../SynthesizedAnnotationPostProcessor.java | 19 ++++++- .../SynthesizedAnnotationSelector.java | 2 +- ...> SynthesizedMetaAggregateAnnotation.java} | 32 +++++------- .../annotation/SyntheticAnnotationProxy.java | 10 ++-- .../scanner/MethodAnnotationScanner.java | 2 +- .../AliasAnnotationPostProcessorTest.java | 17 +++---- .../AliasLinkAnnotationPostProcessorTest.java | 19 +++---- ...sizedAnnotationAttributeProcessorTest.java | 2 +- ...MirrorLinkAnnotationPostProcessorTest.java | 16 +++--- .../SynthesizedAnnotationSelectorTest.java | 2 +- .../SyntheticMetaAnnotationTest.java | 48 +++++++++--------- 25 files changed, 158 insertions(+), 176 deletions(-) create mode 100644 hutool-core/src/main/java/cn/hutool/core/annotation/AggregateAnnotation.java delete mode 100644 hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationAggregator.java rename hutool-core/src/main/java/cn/hutool/core/annotation/{SynthesizedAnnotationAggregator.java => SynthesizedAggregateAnnotation.java} (78%) rename hutool-core/src/main/java/cn/hutool/core/annotation/{SynthesizedMetaAnnotationAggregator.java => SynthesizedMetaAggregateAnnotation.java} (89%) diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/AbstractLinkAnnotationPostProcessor.java b/hutool-core/src/main/java/cn/hutool/core/annotation/AbstractLinkAnnotationPostProcessor.java index 6dbd38142..d510176ad 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/AbstractLinkAnnotationPostProcessor.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/AbstractLinkAnnotationPostProcessor.java @@ -21,7 +21,7 @@ public abstract class AbstractLinkAnnotationPostProcessor implements Synthesized /** * 若一个注解属性上存在{@link Link}注解,注解的{@link Link#type()}返回值在{@link #processTypes()}中存在, - * 且此{@link Link}指定的注解对象在当前的{@link SynthesizedAnnotationAggregator}中存在, + * 且此{@link Link}指定的注解对象在当前的{@link SynthesizedAggregateAnnotation}中存在, * 则从聚合器中获取类型对应的合成注解对象,与该对象中的指定属性,然后将全部关联数据交给 * {@link #processLinkedAttribute}处理。 * @@ -29,7 +29,7 @@ public abstract class AbstractLinkAnnotationPostProcessor implements Synthesized * @param aggregator 合成注解聚合器 */ @Override - public void process(SynthesizedAnnotation synthesizedAnnotation, SynthesizedAnnotationAggregator aggregator) { + public void process(SynthesizedAnnotation synthesizedAnnotation, SynthesizedAggregateAnnotation aggregator) { final Map attributeMap = new HashMap<>(synthesizedAnnotation.getAttributes()); attributeMap.forEach((originalAttributeName, originalAttribute) -> { // 获取注解 @@ -72,7 +72,7 @@ public abstract class AbstractLinkAnnotationPostProcessor implements Synthesized * @param linkedAttribute {@link Link}指向的{@code originalAnnotation}中的关联属性,该参数可能为空 */ protected abstract void processLinkedAttribute( - SynthesizedAnnotationAggregator aggregator, Link annotation, + SynthesizedAggregateAnnotation aggregator, Link annotation, SynthesizedAnnotation originalAnnotation, AnnotationAttribute originalAttribute, SynthesizedAnnotation linkedAnnotation, AnnotationAttribute linkedAttribute ); @@ -100,7 +100,7 @@ public abstract class AbstractLinkAnnotationPostProcessor implements Synthesized * @param synthesizedAnnotationAggregator 合成注解 */ protected SynthesizedAnnotation getLinkedAnnotation( - Link annotation, SynthesizedAnnotationAggregator synthesizedAnnotationAggregator, Class defaultType) { + Link annotation, SynthesizedAggregateAnnotation synthesizedAnnotationAggregator, Class defaultType) { final Class targetAnnotationType = getLinkedAnnotationType(annotation, defaultType); return synthesizedAnnotationAggregator.getSynthesizedAnnotation(targetAnnotationType); } diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/AbstractSynthesizedAnnotation.java b/hutool-core/src/main/java/cn/hutool/core/annotation/AbstractSynthesizedAnnotation.java index bf33bfadb..c8b906cc5 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/AbstractSynthesizedAnnotation.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/AbstractSynthesizedAnnotation.java @@ -20,7 +20,7 @@ import java.util.stream.Stream; */ public abstract class AbstractSynthesizedAnnotation implements Annotation, SynthesizedAnnotation { - private final SynthesizedAnnotationAggregator owner; + private final SynthesizedAggregateAnnotation owner; private final R root; private final Annotation annotation; private final Map attributeMethodCaches; @@ -37,7 +37,7 @@ public abstract class AbstractSynthesizedAnnotation implements Annotation, Sy * @param horizontalDistance 距离根对象的垂直距离 */ protected AbstractSynthesizedAnnotation( - SynthesizedAnnotationAggregator owner, R root, Annotation annotation, int verticalDistance, int horizontalDistance) { + SynthesizedAggregateAnnotation owner, R root, Annotation annotation, int verticalDistance, int horizontalDistance) { this.owner = owner; this.root = root; this.annotation = annotation; @@ -53,7 +53,7 @@ public abstract class AbstractSynthesizedAnnotation implements Annotation, Sy * @return 注解属性 */ protected Map loadAttributeMethods() { - return Stream.of(annotation.annotationType().getDeclaredMethods()) + return Stream.of(ClassUtil.getDeclaredMethods(annotation.annotationType())) .filter(AnnotationUtil::isAttributeMethod) .collect(Collectors.toMap(Method::getName, method -> new CacheableAnnotationAttribute(annotation, method))); } @@ -136,7 +136,7 @@ public abstract class AbstractSynthesizedAnnotation implements Annotation, Sy * @return 合成注解 */ @Override - public SynthesizedAnnotationAggregator getOwner() { + public SynthesizedAggregateAnnotation getOwner() { return owner; } diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/AggregateAnnotation.java b/hutool-core/src/main/java/cn/hutool/core/annotation/AggregateAnnotation.java new file mode 100644 index 000000000..000c99175 --- /dev/null +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/AggregateAnnotation.java @@ -0,0 +1,27 @@ +package cn.hutool.core.annotation; + +import java.lang.annotation.Annotation; + +/** + * 表示一组被聚合在一起的注解对象 + * + * @author huangchengxing + */ +public interface AggregateAnnotation extends Annotation { + + /** + * 在聚合中是否存在的指定类型注解对象 + * + * @param annotationType 注解类型 + * @return 是否 + */ + boolean isAnnotationPresent(Class annotationType); + + /** + * 获取聚合中的全部注解对象 + * + * @return 注解对象 + */ + Annotation[] getAnnotations(); + +} diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/AliasAnnotationPostProcessor.java b/hutool-core/src/main/java/cn/hutool/core/annotation/AliasAnnotationPostProcessor.java index a06578a6f..fe8aa890d 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/AliasAnnotationPostProcessor.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/AliasAnnotationPostProcessor.java @@ -27,7 +27,7 @@ public class AliasAnnotationPostProcessor implements SynthesizedAnnotationPostPr } @Override - public void process(SynthesizedAnnotation synthesizedAnnotation, SynthesizedAnnotationAggregator aggregator) { + public void process(SynthesizedAnnotation synthesizedAnnotation, SynthesizedAggregateAnnotation aggregator) { final Map attributeMap = synthesizedAnnotation.getAttributes(); // 记录别名与属性的关系 diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/AliasLinkAnnotationPostProcessor.java b/hutool-core/src/main/java/cn/hutool/core/annotation/AliasLinkAnnotationPostProcessor.java index 5f3e26f5a..d5fe28f18 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/AliasLinkAnnotationPostProcessor.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/AliasLinkAnnotationPostProcessor.java @@ -52,7 +52,7 @@ public class AliasLinkAnnotationPostProcessor extends AbstractLinkAnnotationPost */ @Override protected void processLinkedAttribute( - SynthesizedAnnotationAggregator aggregator, Link annotation, + SynthesizedAggregateAnnotation aggregator, Link annotation, SynthesizedAnnotation originalAnnotation, AnnotationAttribute originalAttribute, SynthesizedAnnotation linkedAnnotation, AnnotationAttribute linkedAttribute) { // 校验别名关系 @@ -70,7 +70,7 @@ public class AliasLinkAnnotationPostProcessor extends AbstractLinkAnnotationPost * 对指定注解属性进行包装,若该属性已被包装过,则递归以其为根节点的树结构,对树上全部的叶子节点进行包装 */ private void wrappingLinkedAttribute( - SynthesizedAnnotationAggregator synthesizedAnnotationAggregator, AnnotationAttribute originalAttribute, AnnotationAttribute aliasAttribute, BinaryOperator wrapping) { + SynthesizedAggregateAnnotation synthesizedAnnotationAggregator, AnnotationAttribute originalAttribute, AnnotationAttribute aliasAttribute, BinaryOperator wrapping) { // 不是包装属性 if (!aliasAttribute.isWrapped()) { processAttribute(synthesizedAnnotationAggregator, originalAttribute, aliasAttribute, wrapping); @@ -87,7 +87,7 @@ public class AliasLinkAnnotationPostProcessor extends AbstractLinkAnnotationPost * 获取指定注解属性,然后将其再进行一层包装 */ private void processAttribute( - SynthesizedAnnotationAggregator synthesizedAnnotationAggregator, AnnotationAttribute originalAttribute, + SynthesizedAggregateAnnotation synthesizedAnnotationAggregator, AnnotationAttribute originalAttribute, AnnotationAttribute target, BinaryOperator wrapping) { Opt.ofNullable(target.getAnnotationType()) .map(synthesizedAnnotationAggregator::getSynthesizedAnnotation) diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationAggregator.java b/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationAggregator.java deleted file mode 100644 index 25e15d1cf..000000000 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationAggregator.java +++ /dev/null @@ -1,49 +0,0 @@ -package cn.hutool.core.annotation; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; - -/** - * 表示一组被聚合在一起的注解对象 - * - * @author huangchengxing - */ -public interface AnnotationAggregator extends AnnotatedElement { - - /** - * 获取在聚合中存在的指定注解对象 - * - * @param annotationType 注解类型 - * @param 注解类型 - * @return 注解对象 - */ - @Override - T getAnnotation(Class annotationType); - - /** - * 在聚合中是否存在的指定类型注解对象 - * - * @param annotationType 注解类型 - * @return 是否 - */ - @Override - boolean isAnnotationPresent(Class annotationType); - - /** - * 获取聚合中的全部注解对象 - * - * @return 注解对象 - */ - @Override - Annotation[] getAnnotations(); - - /** - * 从聚合中获取指定类型的属性值 - * - * @param attributeName 属性名称 - * @param attributeType 属性类型 - * @return 属性值 - */ - Object getAttribute(String attributeName, Class attributeType); - -} diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationAttribute.java b/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationAttribute.java index 77631b12d..d69d5772b 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationAttribute.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationAttribute.java @@ -7,7 +7,7 @@ import java.lang.reflect.Method; /** *

表示注解的某个属性,等同于绑定的调用对象的{@link Method}方法。
- * 在{@link SynthesizedAnnotationAggregator}的解析以及取值过程中, + * 在{@link SynthesizedAggregateAnnotation}的解析以及取值过程中, * 可以通过设置{@link SynthesizedAnnotation}的注解属性, * 从而使得可以从一个注解对象中属性获取另一个注解对象的属性值 * diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationUtil.java b/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationUtil.java index 570ef8b6c..b2d947111 100755 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationUtil.java @@ -351,11 +351,11 @@ public class AnnotationUtil { * @param annotationType 注解类 * @param 注解类型 * @return 合成注解 - * @see SynthesizedAnnotationAggregator + * @see SynthesizedAggregateAnnotation */ public static T getSynthesizedAnnotation(Annotation annotation, Class annotationType) { // TODO 缓存合成注解信息,避免重复解析 - return SynthesizedAnnotationAggregator.of(annotation).synthesize(annotationType); + return SynthesizedAggregateAnnotation.of(annotation).synthesize(annotationType); } /** @@ -369,7 +369,7 @@ public class AnnotationUtil { * @param annotationType 注解类 * @param 注解类型 * @return 合成注解 - * @see SynthesizedAnnotationAggregator + * @see SynthesizedAggregateAnnotation */ public static T getSynthesizedAnnotation(AnnotatedElement annotatedEle, Class annotationType) { T target = annotatedEle.getAnnotation(annotationType); @@ -397,7 +397,7 @@ public class AnnotationUtil { * @param annotationType 注解类 * @param 注解类型 * @return 合成注解 - * @see SynthesizedAnnotationAggregator + * @see SynthesizedAggregateAnnotation */ public static List getAllSynthesizedAnnotations(AnnotatedElement annotatedEle, Class annotationType) { AnnotationScanner[] scanners = new AnnotationScanner[]{ diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/Link.java b/hutool-core/src/main/java/cn/hutool/core/annotation/Link.java index 6d1bb3f50..f04683ab5 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/Link.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/Link.java @@ -4,7 +4,7 @@ import java.lang.annotation.*; /** *

用于在同一注解中,或具有一定关联的不同注解的属性中,表明这些属性之间具有特定的关联关系。 - * 在通过{@link SynthesizedAnnotationAggregator}获取合成注解后,合成注解获取属性值时会根据该注解进行调整。
+ * 在通过{@link SynthesizedAggregateAnnotation}获取合成注解后,合成注解获取属性值时会根据该注解进行调整。
* *

该注解存在三个字注解:{@link MirrorFor}、{@link ForceAliasFor}或{@link AliasFor}, * 使用三个子注解等同于{@link Link}。但是需要注意的是, @@ -14,7 +14,7 @@ import java.lang.annotation.*; * 注意:该注解的优先级低于{@link Alias} * * @author huangchengxing - * @see SynthesizedAnnotationAggregator + * @see SynthesizedAggregateAnnotation * @see RelationType * @see AliasFor * @see MirrorFor diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/MirrorLinkAnnotationPostProcessor.java b/hutool-core/src/main/java/cn/hutool/core/annotation/MirrorLinkAnnotationPostProcessor.java index 9b1601989..f523473e8 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/MirrorLinkAnnotationPostProcessor.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/MirrorLinkAnnotationPostProcessor.java @@ -45,7 +45,7 @@ public class MirrorLinkAnnotationPostProcessor extends AbstractLinkAnnotationPos */ @Override protected void processLinkedAttribute( - SynthesizedAnnotationAggregator aggregator, Link annotation, + SynthesizedAggregateAnnotation aggregator, Link annotation, SynthesizedAnnotation originalAnnotation, AnnotationAttribute originalAttribute, SynthesizedAnnotation linkedAnnotation, AnnotationAttribute linkedAttribute) { diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/RelationType.java b/hutool-core/src/main/java/cn/hutool/core/annotation/RelationType.java index accfd98ac..1c2248cf3 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/RelationType.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/RelationType.java @@ -3,8 +3,8 @@ package cn.hutool.core.annotation; /** *

注解属性的关系类型
* 若将被{@link Link}注解的属性称为“原始属性”,而在{@link Link}注解中指向的注解属性称为“关联属性”, - * 则该枚举用于描述“原始属性”与“关联属性”在{@link SynthesizedAnnotationAggregator}处理过程中的作用关系。
- * 根据在{@link Link#type()}中指定的关系类型的不同,通过{@link SynthesizedAnnotationAggregator}合成的注解的属性值也将有所变化。 + * 则该枚举用于描述“原始属性”与“关联属性”在{@link SynthesizedAggregateAnnotation}处理过程中的作用关系。
+ * 根据在{@link Link#type()}中指定的关系类型的不同,通过{@link SynthesizedAggregateAnnotation}合成的注解的属性值也将有所变化。 * *

当一个注解中的所有属性同时具备多种关系时,将依次按下述顺序处理: *

    @@ -15,7 +15,7 @@ package cn.hutool.core.annotation; *
* * @author huangchengxing - * @see SynthesizedAnnotationAggregator + * @see SynthesizedAggregateAnnotation * @see Link */ public enum RelationType { diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationAggregator.java b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAggregateAnnotation.java similarity index 78% rename from hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationAggregator.java rename to hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAggregateAnnotation.java index 1dd24f2fb..fe85356a1 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAnnotationAggregator.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedAggregateAnnotation.java @@ -1,16 +1,15 @@ package cn.hutool.core.annotation; import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; import java.util.Collection; /** - * 表示基于特定规则聚合的一组注解对象 + * 表示基于特定规则聚合,将一组注解聚合而来的注解对象 * *

合成注解一般被用于处理类层级结果中具有直接或间接关联的注解对象, * 当实例被创建时,会获取到这些注解对象,并使用{@link SynthesizedAnnotationSelector}对类型相同的注解进行过滤, * 并最终得到类型不重复的有效注解对象。这些有效注解将被包装为{@link SynthesizedAnnotation}, - * 然后最终用于“合成”一个{@link SynthesizedAnnotationAggregator}。
+ * 然后最终用于“合成”一个{@link SynthesizedAggregateAnnotation}。
* {@link SynthesizedAnnotationSelector}是合成注解生命周期中的第一个钩子, * 自定义选择器以拦截原始注解被扫描的过程。 * @@ -28,18 +27,23 @@ import java.util.Collection; * {@link SynthesizedAnnotationAttributeProcessor}是合成注解生命周期中的第三个钩子, * 自定义属性处理器以拦截合成注解的取值过程。 * - *

合成注解可以作为一个特殊的{@link Annotation}或者{@link AnnotatedElement}, - * 当调用{@link Annotation}的方法时,应当返回当前实例本身的有效信息, - * 而当调用{@link AnnotatedElement}的方法时,应当返回用于合成该对象的相关注解的信息。 - * * @author huangchengxing * @see SynthesizedAnnotation * @see SynthesizedAnnotationSelector * @see SynthesizedAnnotationAttributeProcessor * @see SynthesizedAnnotationPostProcessor - * @see SynthesizedMetaAnnotationAggregator + * @see SynthesizedMetaAggregateAnnotation */ -public interface SynthesizedAnnotationAggregator extends Annotation, AnnotationAggregator { +public interface SynthesizedAggregateAnnotation extends Annotation, AggregateAnnotation { + + /** + * 获取在聚合中存在的指定注解对象 + * + * @param annotationType 注解类型 + * @param 注解类型 + * @return 注解对象 + */ + T getAnnotation(Class annotationType); /** * 获取合成注解选择器 @@ -87,6 +91,15 @@ public interface SynthesizedAnnotationAggregator extends Annotation, AnnotationA return this.getClass(); } + /** + * 从聚合中获取指定类型的属性值 + * + * @param attributeName 属性名称 + * @param attributeType 属性类型 + * @return 属性值 + */ + Object getAttribute(String attributeName, Class attributeType); + /** * 获取合成注解 * @@ -103,8 +116,8 @@ public interface SynthesizedAnnotationAggregator extends Annotation, AnnotationA * @param 注解类型 * @return 合成注解 */ - static SynthesizedAnnotationAggregator of(T rootAnnotation) { - return new SynthesizedMetaAnnotationAggregator(rootAnnotation); + static SynthesizedAggregateAnnotation of(T rootAnnotation) { + return new SynthesizedMetaAggregateAnnotation(rootAnnotation); } } 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 483525e2e..40bd70499 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 @@ -8,13 +8,13 @@ import java.util.Map; import java.util.function.UnaryOperator; /** - *

用于在{@link SynthesizedAnnotationAggregator}中表示一个处于合成状态的注解对象。
+ *

用于在{@link SynthesizedAggregateAnnotation}中表示一个处于合成状态的注解对象。
* 当对多个合成注解排序时,默认使用{@link #DEFAULT_CHILD_PRIORITY_COMPARATOR}进行排序, * 从保证合成注解按{@link #getVerticalDistance()}与{@link #getHorizontalDistance()}的返回值保持有序, * 从而使得距离根元素更接近的注解对象在被处理是具有更高的优先级。 * * @author huangchengxing - * @see SynthesizedAnnotationAggregator + * @see SynthesizedAggregateAnnotation */ public interface SynthesizedAnnotation extends Annotation, Comparable { @@ -32,7 +32,7 @@ public interface SynthesizedAnnotation extends Annotation, Comparable被合成注解后置处理器,用于在{@link SynthesizedAnnotationAggregator}加载完所有待合成注解后, + *

被合成注解后置处理器,用于在{@link SynthesizedAggregateAnnotation}加载完所有待合成注解后, * 再对加载好的{@link SynthesizedAnnotation}进行后置处理。
* 当多个{@link SynthesizedAnnotationPostProcessor}需要一起执行时,将按照{@link #order()}的返回值进行排序, * 该值更小的处理器将被优先执行。 @@ -25,6 +25,21 @@ import java.util.Comparator; */ public interface SynthesizedAnnotationPostProcessor extends Comparable { + /** + * 属性上带有{@link Alias}的注解对象的后置处理器 + */ + AliasAnnotationPostProcessor ALIAS_ANNOTATION_POST_PROCESSOR = new AliasAnnotationPostProcessor(); + + /** + * 属性上带有{@link Link},且与其他注解的属性存在镜像关系的注解对象的后置处理器 + */ + MirrorLinkAnnotationPostProcessor MIRROR_LINK_ANNOTATION_POST_PROCESSOR = new MirrorLinkAnnotationPostProcessor(); + + /** + * 属性上带有{@link Link},且与其他注解的属性存在别名关系的注解对象的后置处理器 + */ + AliasLinkAnnotationPostProcessor ALIAS_LINK_ANNOTATION_POST_PROCESSOR = new AliasLinkAnnotationPostProcessor(); + /** * 在一组后置处理器中被调用的顺序,越小越靠前 * @@ -51,6 +66,6 @@ public interface SynthesizedAnnotationPostProcessor extends Comparable - * 该接口用于在{@link SynthesizedAnnotationAggregator}中用于从一批相同的注解对象中筛选最终用于合成注解对象。 + * 该接口用于在{@link SynthesizedAggregateAnnotation}中用于从一批相同的注解对象中筛选最终用于合成注解对象。 * * @author huangchengxing */ diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedMetaAnnotationAggregator.java b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedMetaAggregateAnnotation.java similarity index 89% rename from hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedMetaAnnotationAggregator.java rename to hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedMetaAggregateAnnotation.java index d6d96044f..4c9106c46 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedMetaAnnotationAggregator.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/SynthesizedMetaAggregateAnnotation.java @@ -10,10 +10,10 @@ import java.lang.reflect.AnnotatedElement; import java.util.*; /** - * {@link SynthesizedAnnotationAggregator}的基本实现,表示一个根注解与根注解上的多层元注解的聚合状态 + * {@link SynthesizedAggregateAnnotation}的基本实现,表示一个根注解与根注解上的多层元注解的聚合得到的注解 * *

假设现有注解A,A上存在元注解B,B上存在元注解C,则对注解A进行解析, - * 将得到包含根注解A,以及其元注解B、C在内的合成元注解聚合{@link SynthesizedMetaAnnotationAggregator}。 + * 将得到包含根注解A,以及其元注解B、C在内的合成元注解聚合{@link SynthesizedMetaAggregateAnnotation}。 * 从{@link AnnotatedElement}的角度来说,得到的合成注解是一个同时承载有ABC三个注解对象的被注解元素, * 因此通过调用{@link AnnotatedElement}的相关方法将返回对应符合语义的注解对象。 * @@ -34,7 +34,7 @@ import java.util.*; * * 若用户需要自行扩展,则需要保证上述三个处理器被正确注入当前实例。 * - *

{@link SynthesizedMetaAnnotationAggregator}支持通过{@link #getAttribute(String, Class)}, + *

{@link SynthesizedMetaAggregateAnnotation}支持通过{@link #getAttribute(String, Class)}, * 或通过{@link #synthesize(Class)}获得注解代理对象后获取指定类型的注解属性值, * 返回的属性值将根据合成注解中对应原始注解属性上的{@link Alias}与{@link Link}注解而有所变化。 * 通过当前实例获取属性值时,将经过{@link SynthesizedAnnotationAttributeProcessor}的处理。
@@ -45,7 +45,7 @@ import java.util.*; * @see AnnotationUtil * @see SynthesizedAnnotationSelector */ -public class SynthesizedMetaAnnotationAggregator implements SynthesizedAnnotationAggregator { +public class SynthesizedMetaAggregateAnnotation implements SynthesizedAggregateAnnotation { /** * 根注解,即当前查找的注解 @@ -79,14 +79,14 @@ public class SynthesizedMetaAnnotationAggregator implements SynthesizedAnnotatio * * @param source 源注解 */ - public SynthesizedMetaAnnotationAggregator(Annotation source) { + public SynthesizedMetaAggregateAnnotation(Annotation source) { this( source, SynthesizedAnnotationSelector.NEAREST_AND_OLDEST_PRIORITY, new CacheableSynthesizedAnnotationAttributeProcessor(), Arrays.asList( - new AliasAnnotationPostProcessor(), - new MirrorLinkAnnotationPostProcessor(), - new AliasLinkAnnotationPostProcessor() + SynthesizedAnnotationPostProcessor.ALIAS_ANNOTATION_POST_PROCESSOR, + SynthesizedAnnotationPostProcessor.MIRROR_LINK_ANNOTATION_POST_PROCESSOR, + SynthesizedAnnotationPostProcessor.ALIAS_LINK_ANNOTATION_POST_PROCESSOR ) ); } @@ -98,7 +98,7 @@ public class SynthesizedMetaAnnotationAggregator implements SynthesizedAnnotatio * @param annotationSelector 合成注解选择器 * @param attributeProcessor 注解属性处理器 */ - public SynthesizedMetaAnnotationAggregator( + public SynthesizedMetaAggregateAnnotation( Annotation annotation, SynthesizedAnnotationSelector annotationSelector, SynthesizedAnnotationAttributeProcessor attributeProcessor, @@ -240,23 +240,13 @@ public class SynthesizedMetaAnnotationAggregator implements SynthesizedAnnotatio * * @param annotationType 注解类型 * @return 合成注解对象 - * @see SyntheticAnnotationProxy#create(Class, SynthesizedAnnotationAggregator) + * @see SyntheticAnnotationProxy#create(Class, SynthesizedAggregateAnnotation) */ @Override public T synthesize(Class annotationType) { return SyntheticAnnotationProxy.create(annotationType, this); } - /** - * 获取根注解直接声明的注解,该方法正常情况下当只返回原注解 - * - * @return 直接声明注解 - */ - @Override - public Annotation[] getDeclaredAnnotations() { - return new Annotation[]{getSource()}; - } - /** * 广度优先遍历并缓存该根注解上的全部元注解 */ @@ -294,7 +284,7 @@ public class SynthesizedMetaAnnotationAggregator implements SynthesizedAnnotatio * @param verticalDistance 距离根对象的水平距离 * @param horizontalDistance 距离根对象的垂直距离 */ - protected MetaAnnotation(SynthesizedAnnotationAggregator owner, Annotation root, Annotation annotation, int verticalDistance, int horizontalDistance) { + protected MetaAnnotation(SynthesizedAggregateAnnotation owner, Annotation root, Annotation annotation, int verticalDistance, int horizontalDistance) { super(owner, root, annotation, verticalDistance, horizontalDistance); } 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 f33557d7f..f107c290e 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 @@ -38,7 +38,7 @@ class SyntheticAnnotationProxy implements InvocationHandler { /** * 创建一个代理注解,生成的代理对象将是{@link SyntheticProxyAnnotation}与指定的注解类的子类。 *

    - *
  • 当作为{@code annotationType}所指定的类型使用时,其属性将通过合成它的{@link SynthesizedAnnotationAggregator}获取;
  • + *
  • 当作为{@code annotationType}所指定的类型使用时,其属性将通过合成它的{@link SynthesizedAggregateAnnotation}获取;
  • *
  • 当作为{@link SyntheticProxyAnnotation}或{@link SynthesizedAnnotation}使用时,将可以获得原始注解实例的相关信息;
  • *
* @@ -48,7 +48,7 @@ class SyntheticAnnotationProxy implements InvocationHandler { */ @SuppressWarnings("unchecked") static T create( - Class annotationType, SynthesizedAnnotationAggregator synthesizedAnnotationAggregator) { + Class annotationType, SynthesizedAggregateAnnotation synthesizedAnnotationAggregator) { final SynthesizedAnnotation annotation = synthesizedAnnotationAggregator.getSynthesizedAnnotation(annotationType); if (ObjectUtil.isNull(annotation)) { return null; @@ -93,13 +93,13 @@ class SyntheticAnnotationProxy implements InvocationHandler { methods.put("getAttributeValue", (method, args) -> annotation.getAttributeValue((String)args[0])); methods.put("getOwner", (method, args) -> annotation.getOwner()); methods.put("annotationType", (method, args) -> annotation.annotationType()); - for (final Method declaredMethod : annotation.getAnnotation().annotationType().getDeclaredMethods()) { + for (final Method declaredMethod : ClassUtil.getDeclaredMethods(annotation.getAnnotation().annotationType())) { methods.put(declaredMethod.getName(), (method, args) -> proxyAttributeValue(method)); } } private String proxyToString() { - final String attributes = Stream.of(annotation.annotationType().getDeclaredMethods()) + final String attributes = Stream.of(ClassUtil.getDeclaredMethods(annotation.getAnnotation().annotationType())) .filter(AnnotationUtil::isAttributeMethod) .map(method -> StrUtil.format("{}={}", method.getName(), annotation.getOwner().getAttribute(method.getName(), method.getReturnType()))) .collect(Collectors.joining(", ")); @@ -134,7 +134,7 @@ class SyntheticAnnotationProxy implements InvocationHandler { * * @return 合成注解 */ - SynthesizedAnnotationAggregator getSynthesizedAnnotationAggregator(); + SynthesizedAggregateAnnotation getSynthesizedAnnotationAggregator(); /** * 获取该代理注解对应的已合成注解 diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/MethodAnnotationScanner.java b/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/MethodAnnotationScanner.java index ac054f88f..18be3ea1b 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/MethodAnnotationScanner.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/MethodAnnotationScanner.java @@ -80,7 +80,7 @@ public class MethodAnnotationScanner extends AbstractTypeAnnotationScanner targetClass) { final Method sourceMethod = (Method) source; - return Stream.of(targetClass.getDeclaredMethods()) + return Stream.of(ClassUtil.getDeclaredMethods(targetClass)) .filter(superMethod -> !superMethod.isBridge()) .filter(superMethod -> hasSameSignature(sourceMethod, superMethod)) .map(AnnotatedElement::getAnnotations) diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/AliasAnnotationPostProcessorTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/AliasAnnotationPostProcessorTest.java index 8c792a1c9..db9558fd4 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/AliasAnnotationPostProcessorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/AliasAnnotationPostProcessorTest.java @@ -19,7 +19,7 @@ public class AliasAnnotationPostProcessorTest { AliasAnnotationPostProcessor processor = new AliasAnnotationPostProcessor(); Map, SynthesizedAnnotation> annotationMap = new HashMap<>(); - SynthesizedAnnotationAggregator synthesizedAnnotationAggregator = new TestSynthesizedAnnotationAggregator(annotationMap); + SynthesizedAggregateAnnotation synthesizedAnnotationAggregator = new TestSynthesizedAggregateAnnotation(annotationMap); AnnotationForTest annotation = ClassForTest.class.getAnnotation(AnnotationForTest.class); SynthesizedAnnotation synthesizedAnnotation = new TestSynthesizedAnnotation(synthesizedAnnotationAggregator, annotation); annotationMap.put(annotation.annotationType(), synthesizedAnnotation); @@ -49,11 +49,11 @@ public class AliasAnnotationPostProcessorTest { String name() default ""; } - static class TestSynthesizedAnnotationAggregator implements SynthesizedAnnotationAggregator { + static class TestSynthesizedAggregateAnnotation implements SynthesizedAggregateAnnotation { private final Map, SynthesizedAnnotation> annotationMap; - public TestSynthesizedAnnotationAggregator(Map, SynthesizedAnnotation> annotationMap) { + public TestSynthesizedAggregateAnnotation(Map, SynthesizedAnnotation> annotationMap) { this.annotationMap = annotationMap; } @@ -106,20 +106,15 @@ public class AliasAnnotationPostProcessorTest { public Object getAttribute(String attributeName, Class attributeType) { return null; } - - @Override - public Annotation[] getDeclaredAnnotations() { - return new Annotation[0]; - } } static class TestSynthesizedAnnotation implements SynthesizedAnnotation { private final Annotation annotation; - private final SynthesizedAnnotationAggregator owner; + private final SynthesizedAggregateAnnotation owner; private final Map attributeMap; - public TestSynthesizedAnnotation(SynthesizedAnnotationAggregator owner, Annotation annotation) { + public TestSynthesizedAnnotation(SynthesizedAggregateAnnotation owner, Annotation annotation) { this.owner = owner; this.attributeMap = new HashMap<>(); this.annotation = annotation; @@ -129,7 +124,7 @@ public class AliasAnnotationPostProcessorTest { } @Override - public SynthesizedAnnotationAggregator getOwner() { + public SynthesizedAggregateAnnotation getOwner() { return owner; } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/AliasLinkAnnotationPostProcessorTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/AliasLinkAnnotationPostProcessorTest.java index 339b012d5..1ca645d53 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/AliasLinkAnnotationPostProcessorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/AliasLinkAnnotationPostProcessorTest.java @@ -19,7 +19,7 @@ public class AliasLinkAnnotationPostProcessorTest { AliasLinkAnnotationPostProcessor processor = new AliasLinkAnnotationPostProcessor(); Map, SynthesizedAnnotation> annotationMap = new HashMap<>(); - SynthesizedAnnotationAggregator synthesizedAnnotationAggregator = new TestSynthesizedAnnotationAggregator(annotationMap); + SynthesizedAggregateAnnotation synthesizedAnnotationAggregator = new TestSynthesizedAggregateAnnotation(annotationMap); AnnotationForTest annotation = ClassForTest.class.getAnnotation(AnnotationForTest.class); SynthesizedAnnotation synthesizedAnnotation = new TestSynthesizedAnnotation(synthesizedAnnotationAggregator, annotation); annotationMap.put(annotation.annotationType(), synthesizedAnnotation); @@ -43,7 +43,7 @@ public class AliasLinkAnnotationPostProcessorTest { AliasLinkAnnotationPostProcessor processor = new AliasLinkAnnotationPostProcessor(); Map, SynthesizedAnnotation> annotationMap = new HashMap<>(); - SynthesizedAnnotationAggregator synthesizedAnnotationAggregator = new TestSynthesizedAnnotationAggregator(annotationMap); + SynthesizedAggregateAnnotation synthesizedAnnotationAggregator = new TestSynthesizedAggregateAnnotation(annotationMap); AnnotationForTest annotation = ClassForTest.class.getAnnotation(AnnotationForTest.class); SynthesizedAnnotation synthesizedAnnotation = new TestSynthesizedAnnotation(synthesizedAnnotationAggregator, annotation); annotationMap.put(annotation.annotationType(), synthesizedAnnotation); @@ -77,11 +77,11 @@ public class AliasLinkAnnotationPostProcessorTest { String name2() default ""; } - static class TestSynthesizedAnnotationAggregator implements SynthesizedAnnotationAggregator { + static class TestSynthesizedAggregateAnnotation implements SynthesizedAggregateAnnotation { private final Map, SynthesizedAnnotation> annotationMap; - public TestSynthesizedAnnotationAggregator(Map, SynthesizedAnnotation> annotationMap) { + public TestSynthesizedAggregateAnnotation(Map, SynthesizedAnnotation> annotationMap) { this.annotationMap = annotationMap; } @@ -134,20 +134,15 @@ public class AliasLinkAnnotationPostProcessorTest { public Object getAttribute(String attributeName, Class attributeType) { return null; } - - @Override - public Annotation[] getDeclaredAnnotations() { - return new Annotation[0]; - } } static class TestSynthesizedAnnotation implements SynthesizedAnnotation { private final Annotation annotation; - private final SynthesizedAnnotationAggregator owner; + private final SynthesizedAggregateAnnotation owner; private final Map attributeMap; - public TestSynthesizedAnnotation(SynthesizedAnnotationAggregator owner, Annotation annotation) { + public TestSynthesizedAnnotation(SynthesizedAggregateAnnotation owner, Annotation annotation) { this.owner = owner; this.attributeMap = new HashMap<>(); this.annotation = annotation; @@ -157,7 +152,7 @@ public class AliasLinkAnnotationPostProcessorTest { } @Override - public SynthesizedAnnotationAggregator getOwner() { + public SynthesizedAggregateAnnotation getOwner() { return owner; } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/CacheableSynthesizedAnnotationAttributeProcessorTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/CacheableSynthesizedAnnotationAttributeProcessorTest.java index c4db00adf..3a9717134 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/CacheableSynthesizedAnnotationAttributeProcessorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/CacheableSynthesizedAnnotationAttributeProcessorTest.java @@ -39,7 +39,7 @@ public class CacheableSynthesizedAnnotationAttributeProcessorTest { } @Override - public SynthesizedAnnotationAggregator getOwner() { + public SynthesizedAggregateAnnotation getOwner() { return null; } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/MirrorLinkAnnotationPostProcessorTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/MirrorLinkAnnotationPostProcessorTest.java index 2c741e32d..5f18f9574 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/MirrorLinkAnnotationPostProcessorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/MirrorLinkAnnotationPostProcessorTest.java @@ -19,7 +19,7 @@ public class MirrorLinkAnnotationPostProcessorTest { MirrorLinkAnnotationPostProcessor processor = new MirrorLinkAnnotationPostProcessor(); Map, SynthesizedAnnotation> annotationMap = new HashMap<>(); - SynthesizedAnnotationAggregator synthesizedAnnotationAggregator = new TestSynthesizedAnnotationAggregator(annotationMap); + SynthesizedAggregateAnnotation synthesizedAnnotationAggregator = new TestSynthesizedAggregateAnnotation(annotationMap); AnnotationForTest annotation = ClassForTest.class.getAnnotation(AnnotationForTest.class); SynthesizedAnnotation synthesizedAnnotation = new TestSynthesizedAnnotation(synthesizedAnnotationAggregator, annotation); annotationMap.put(annotation.annotationType(), synthesizedAnnotation); @@ -51,11 +51,11 @@ public class MirrorLinkAnnotationPostProcessorTest { String name() default ""; } - static class TestSynthesizedAnnotationAggregator implements SynthesizedAnnotationAggregator { + static class TestSynthesizedAggregateAnnotation implements SynthesizedAggregateAnnotation { private final Map, SynthesizedAnnotation> annotationMap; - public TestSynthesizedAnnotationAggregator(Map, SynthesizedAnnotation> annotationMap) { + public TestSynthesizedAggregateAnnotation(Map, SynthesizedAnnotation> annotationMap) { this.annotationMap = annotationMap; } @@ -109,19 +109,15 @@ public class MirrorLinkAnnotationPostProcessorTest { return null; } - @Override - public Annotation[] getDeclaredAnnotations() { - return new Annotation[0]; - } } static class TestSynthesizedAnnotation implements SynthesizedAnnotation { private final Annotation annotation; - private final SynthesizedAnnotationAggregator owner; + private final SynthesizedAggregateAnnotation owner; private final Map attributeMap; - public TestSynthesizedAnnotation(SynthesizedAnnotationAggregator owner, Annotation annotation) { + public TestSynthesizedAnnotation(SynthesizedAggregateAnnotation owner, Annotation annotation) { this.owner = owner; this.attributeMap = new HashMap<>(); this.annotation = annotation; @@ -131,7 +127,7 @@ public class MirrorLinkAnnotationPostProcessorTest { } @Override - public SynthesizedAnnotationAggregator getOwner() { + public SynthesizedAggregateAnnotation getOwner() { return owner; } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/SynthesizedAnnotationSelectorTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/SynthesizedAnnotationSelectorTest.java index cadb3d6f9..0436d5c4c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/SynthesizedAnnotationSelectorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/SynthesizedAnnotationSelectorTest.java @@ -88,7 +88,7 @@ public class SynthesizedAnnotationSelectorTest { } @Override - public SynthesizedAnnotationAggregator getOwner() { + public SynthesizedAggregateAnnotation getOwner() { return null; } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/SyntheticMetaAnnotationTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/SyntheticMetaAnnotationTest.java index b34f2d4dc..a0a279641 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/SyntheticMetaAnnotationTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/SyntheticMetaAnnotationTest.java @@ -4,12 +4,15 @@ import cn.hutool.core.util.ReflectUtil; import org.junit.Assert; import org.junit.Test; -import java.lang.annotation.*; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.lang.reflect.Method; import java.util.Arrays; /** - * 合成注解{@link SynthesizedMetaAnnotationAggregator}的测试用例 + * 合成注解{@link SynthesizedMetaAggregateAnnotation}的测试用例 * * @author huangchengxing */ @@ -22,10 +25,10 @@ public class SyntheticMetaAnnotationTest { final GrandParentAnnotation grandParentAnnotation = ChildAnnotation.class.getAnnotation(GrandParentAnnotation.class); final ParentAnnotation parentAnnotation = ChildAnnotation.class.getAnnotation(ParentAnnotation.class); final ChildAnnotation childAnnotation = AnnotatedClass.class.getAnnotation(ChildAnnotation.class); - final SynthesizedMetaAnnotationAggregator syntheticMetaAnnotation = new SynthesizedMetaAnnotationAggregator(childAnnotation); + final SynthesizedMetaAggregateAnnotation syntheticMetaAnnotation = new SynthesizedMetaAggregateAnnotation(childAnnotation); // Annotation & AnnotatedElement - Assert.assertEquals(SynthesizedMetaAnnotationAggregator.class, syntheticMetaAnnotation.annotationType()); + Assert.assertEquals(SynthesizedMetaAggregateAnnotation.class, syntheticMetaAnnotation.annotationType()); Assert.assertTrue(syntheticMetaAnnotation.isAnnotationPresent(GrandParentAnnotation.class)); Assert.assertTrue(syntheticMetaAnnotation.isAnnotationPresent(ParentAnnotation.class)); Assert.assertTrue(syntheticMetaAnnotation.isAnnotationPresent(ChildAnnotation.class)); @@ -36,7 +39,6 @@ public class SyntheticMetaAnnotationTest { Arrays.asList(childAnnotation, grandParentAnnotation, parentAnnotation), Arrays.asList(syntheticMetaAnnotation.getAnnotations()) ); - Assert.assertArrayEquals(new Annotation[]{ childAnnotation }, syntheticMetaAnnotation.getDeclaredAnnotations()); // 扩展方法 Assert.assertNotNull(syntheticMetaAnnotation.getSynthesizedAnnotation(GrandParentAnnotation.class)); @@ -53,11 +55,9 @@ public class SyntheticMetaAnnotationTest { @Test public void synthesisAnnotationAttributeTest() { final ChildAnnotation rootAnnotation = AnnotatedClass.class.getAnnotation(ChildAnnotation.class); - SynthesizedMetaAnnotationAggregator syntheticMetaAnnotation = new SynthesizedMetaAnnotationAggregator(rootAnnotation); + SynthesizedMetaAggregateAnnotation syntheticMetaAnnotation = new SynthesizedMetaAggregateAnnotation(rootAnnotation); Assert.assertEquals(syntheticMetaAnnotation.getSource(), rootAnnotation); - Assert.assertEquals(syntheticMetaAnnotation.annotationType(), SynthesizedMetaAnnotationAggregator.class); - Assert.assertEquals(1, syntheticMetaAnnotation.getDeclaredAnnotations().length); - Assert.assertEquals(syntheticMetaAnnotation.getDeclaredAnnotations()[0], rootAnnotation); + Assert.assertEquals(syntheticMetaAnnotation.annotationType(), SynthesizedMetaAggregateAnnotation.class); Assert.assertEquals(3, syntheticMetaAnnotation.getAnnotations().length); Assert.assertEquals("Child!", syntheticMetaAnnotation.getAttribute("childValue", String.class)); @@ -69,7 +69,7 @@ public class SyntheticMetaAnnotationTest { @Test public void syntheticAnnotationTest() { final ChildAnnotation rootAnnotation = AnnotatedClass.class.getAnnotation(ChildAnnotation.class); - SynthesizedMetaAnnotationAggregator syntheticMetaAnnotation = new SynthesizedMetaAnnotationAggregator(rootAnnotation); + SynthesizedMetaAggregateAnnotation syntheticMetaAnnotation = new SynthesizedMetaAggregateAnnotation(rootAnnotation); final ChildAnnotation childAnnotation = syntheticMetaAnnotation.synthesize(ChildAnnotation.class); SynthesizedAnnotation childSyntheticAnnotation = syntheticMetaAnnotation.getSynthesizedAnnotation(ChildAnnotation.class); @@ -82,7 +82,7 @@ public class SyntheticMetaAnnotationTest { Assert.assertEquals("Child!", childAnnotation.childValue()); Assert.assertEquals("Child!", childAnnotation.childValueAlias()); Assert.assertEquals(childAnnotation.grandParentType(), Integer.class); - Assert.assertThrows(IllegalArgumentException.class, () -> new SynthesizedMetaAnnotationAggregator(childAnnotation)); + Assert.assertThrows(IllegalArgumentException.class, () -> new SynthesizedMetaAggregateAnnotation(childAnnotation)); final ParentAnnotation parentAnnotation = syntheticMetaAnnotation.synthesize(ParentAnnotation.class); SynthesizedAnnotation parentSyntheticAnnotation = syntheticMetaAnnotation.getSynthesizedAnnotation(ParentAnnotation.class); @@ -93,7 +93,7 @@ public class SyntheticMetaAnnotationTest { Assert.assertNotNull(parentAnnotation); Assert.assertEquals("Child's Parent!", parentAnnotation.parentValue()); Assert.assertEquals("java.lang.Void", parentAnnotation.grandParentType()); - Assert.assertThrows(IllegalArgumentException.class, () -> new SynthesizedMetaAnnotationAggregator(parentAnnotation)); + Assert.assertThrows(IllegalArgumentException.class, () -> new SynthesizedMetaAggregateAnnotation(parentAnnotation)); final GrandParentAnnotation grandParentAnnotation = syntheticMetaAnnotation.synthesize(GrandParentAnnotation.class); SynthesizedAnnotation grandParentSyntheticAnnotation = syntheticMetaAnnotation.getSynthesizedAnnotation(GrandParentAnnotation.class); @@ -105,13 +105,13 @@ public class SyntheticMetaAnnotationTest { Assert.assertNotNull(grandParentAnnotation); Assert.assertEquals("Child's GrandParent!", grandParentAnnotation.grandParentValue()); Assert.assertEquals(grandParentAnnotation.grandParentType(), Integer.class); - Assert.assertThrows(IllegalArgumentException.class, () -> new SynthesizedMetaAnnotationAggregator(grandParentAnnotation)); + Assert.assertThrows(IllegalArgumentException.class, () -> new SynthesizedMetaAggregateAnnotation(grandParentAnnotation)); } @Test public void linkTest() { final Method method = ReflectUtil.getMethod(AnnotationForLinkTest.class, "value"); - final SynthesizedAnnotationAggregator synthesizedAnnotationAggregator = new SynthesizedMetaAnnotationAggregator(method.getAnnotation(AliasFor.class)); + final SynthesizedAggregateAnnotation synthesizedAnnotationAggregator = new SynthesizedMetaAggregateAnnotation(method.getAnnotation(AliasFor.class)); final Link link = synthesizedAnnotationAggregator.synthesize(Link.class); Assert.assertEquals(AnnotationForLinkTest.class, link.annotation()); Assert.assertEquals("name", link.attribute()); @@ -120,19 +120,19 @@ public class SyntheticMetaAnnotationTest { @Test public void mirrorAttributeTest() { AnnotationForMirrorTest annotation = ClassForMirrorTest.class.getAnnotation(AnnotationForMirrorTest.class); - SynthesizedAnnotationAggregator synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + SynthesizedAggregateAnnotation synthetic = new SynthesizedMetaAggregateAnnotation(annotation); AnnotationForMirrorTest syntheticAnnotation = synthetic.synthesize(AnnotationForMirrorTest.class); Assert.assertEquals("Foo", syntheticAnnotation.name()); Assert.assertEquals("Foo", syntheticAnnotation.value()); annotation = ClassForMirrorTest2.class.getAnnotation(AnnotationForMirrorTest.class); - synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + synthetic = new SynthesizedMetaAggregateAnnotation(annotation); syntheticAnnotation = synthetic.synthesize(AnnotationForMirrorTest.class); Assert.assertEquals("Foo", syntheticAnnotation.name()); Assert.assertEquals("Foo", syntheticAnnotation.value()); annotation = ClassForMirrorTest3.class.getAnnotation(AnnotationForMirrorTest.class); - synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + synthetic = new SynthesizedMetaAggregateAnnotation(annotation); syntheticAnnotation = synthetic.synthesize(AnnotationForMirrorTest.class); AnnotationForMirrorTest finalSyntheticAnnotation = syntheticAnnotation; Assert.assertThrows(IllegalArgumentException.class, finalSyntheticAnnotation::name); @@ -141,14 +141,14 @@ public class SyntheticMetaAnnotationTest { @Test public void aliasForTest() { AnnotationForAliasForTest annotation = ClassForAliasForTest.class.getAnnotation(AnnotationForAliasForTest.class); - SynthesizedAnnotationAggregator synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + SynthesizedAggregateAnnotation synthetic = new SynthesizedMetaAggregateAnnotation(annotation); MetaAnnotationForAliasForTest metaAnnotation = synthetic.synthesize(MetaAnnotationForAliasForTest.class); Assert.assertEquals("Meta", metaAnnotation.name()); AnnotationForAliasForTest childAnnotation = synthetic.synthesize(AnnotationForAliasForTest.class); Assert.assertEquals("", childAnnotation.value()); annotation = ClassForAliasForTest2.class.getAnnotation(AnnotationForAliasForTest.class); - synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + synthetic = new SynthesizedMetaAggregateAnnotation(annotation); metaAnnotation = synthetic.synthesize(MetaAnnotationForAliasForTest.class); Assert.assertEquals("Foo", metaAnnotation.name()); childAnnotation = synthetic.synthesize(AnnotationForAliasForTest.class); @@ -158,14 +158,14 @@ public class SyntheticMetaAnnotationTest { @Test public void forceAliasForTest() { AnnotationForceForAliasForTest annotation = ClassForForceAliasForTest.class.getAnnotation(AnnotationForceForAliasForTest.class); - SynthesizedAnnotationAggregator synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + SynthesizedAggregateAnnotation synthetic = new SynthesizedMetaAggregateAnnotation(annotation); MetaAnnotationForForceAliasForTest metaAnnotation = synthetic.synthesize(MetaAnnotationForForceAliasForTest.class); Assert.assertEquals("", metaAnnotation.name()); AnnotationForceForAliasForTest childAnnotation = synthetic.synthesize(AnnotationForceForAliasForTest.class); Assert.assertEquals("", childAnnotation.value()); annotation = ClassForForceAliasForTest2.class.getAnnotation(AnnotationForceForAliasForTest.class); - synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + synthetic = new SynthesizedMetaAggregateAnnotation(annotation); metaAnnotation = synthetic.synthesize(MetaAnnotationForForceAliasForTest.class); Assert.assertEquals("Foo", metaAnnotation.name()); childAnnotation = synthetic.synthesize(AnnotationForceForAliasForTest.class); @@ -175,7 +175,7 @@ public class SyntheticMetaAnnotationTest { @Test public void aliasForAndMirrorTest() { AnnotationForMirrorThenAliasForTest annotation = ClassForAliasForAndMirrorTest.class.getAnnotation(AnnotationForMirrorThenAliasForTest.class); - SynthesizedAnnotationAggregator synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + SynthesizedAggregateAnnotation synthetic = new SynthesizedMetaAggregateAnnotation(annotation); MetaAnnotationForMirrorThenAliasForTest metaAnnotation = synthetic.synthesize(MetaAnnotationForMirrorThenAliasForTest.class); Assert.assertEquals("test", metaAnnotation.name()); Assert.assertEquals("test", metaAnnotation.value()); @@ -186,7 +186,7 @@ public class SyntheticMetaAnnotationTest { @Test public void multiAliasForTest() { final AnnotationForMultiAliasForTest annotation = ClassForMultiAliasForTest.class.getAnnotation(AnnotationForMultiAliasForTest.class); - final SynthesizedAnnotationAggregator synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + final SynthesizedAggregateAnnotation synthetic = new SynthesizedMetaAggregateAnnotation(annotation); final MetaAnnotationForMultiAliasForTest1 metaAnnotation1 = synthetic.synthesize(MetaAnnotationForMultiAliasForTest1.class); Assert.assertEquals("test", metaAnnotation1.name()); @@ -200,7 +200,7 @@ public class SyntheticMetaAnnotationTest { @Test public void implicitAliasTest() { final AnnotationForImplicitAliasTest annotation = ClassForImplicitAliasTest.class.getAnnotation(AnnotationForImplicitAliasTest.class); - final SynthesizedAnnotationAggregator synthetic = new SynthesizedMetaAnnotationAggregator(annotation); + final SynthesizedAggregateAnnotation synthetic = new SynthesizedMetaAggregateAnnotation(annotation); final MetaAnnotationForImplicitAliasTest metaAnnotation = synthetic.synthesize(MetaAnnotationForImplicitAliasTest.class); Assert.assertEquals("Meta", metaAnnotation.name());