From 028f498a048806902a9130dfa2d66406766b5dd8 Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 2 Jan 2024 23:15:29 +0800 Subject: [PATCH] change name --- .../core/annotation/AnnotatedElementUtil.java | 7 +++- .../core/annotation/AnnotationUtil.java | 11 ++--- .../annotation/ResolvedAnnotationMapping.java | 1 + .../CombinationAnnotatedElement.java} | 42 ++++++++++--------- .../HierarchicalAnnotatedElements.java | 5 ++- .../{ => elements}/MetaAnnotatedElement.java | 7 +++- .../RepeatableMetaAnnotatedElement.java | 7 +++- .../annotation/elements/package-info.java | 18 ++++++++ .../core/annotation/AnnotationUtilTest.java | 3 +- ...a => CombinationAnnotatedElementTest.java} | 15 +++---- .../HierarchicalAnnotatedElementTest.java | 1 + .../annotation/MetaAnnotatedElementTest.java | 1 + .../RepeatableMetaAnnotatedElementTest.java | 1 + 13 files changed, 78 insertions(+), 41 deletions(-) rename hutool-core/src/main/java/org/dromara/hutool/core/annotation/{CombinationAnnotationElement.java => elements/CombinationAnnotatedElement.java} (81%) rename hutool-core/src/main/java/org/dromara/hutool/core/annotation/{ => elements}/HierarchicalAnnotatedElements.java (98%) rename hutool-core/src/main/java/org/dromara/hutool/core/annotation/{ => elements}/MetaAnnotatedElement.java (97%) rename hutool-core/src/main/java/org/dromara/hutool/core/annotation/{ => elements}/RepeatableMetaAnnotatedElement.java (97%) create mode 100644 hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/package-info.java rename hutool-core/src/test/java/org/dromara/hutool/core/annotation/{CombinationAnnotationElementTest.java => CombinationAnnotatedElementTest.java} (73%) diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/AnnotatedElementUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/AnnotatedElementUtil.java index 9d6b67136..cbc9e094e 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/AnnotatedElementUtil.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/AnnotatedElementUtil.java @@ -12,6 +12,9 @@ package org.dromara.hutool.core.annotation; +import org.dromara.hutool.core.annotation.elements.HierarchicalAnnotatedElements; +import org.dromara.hutool.core.annotation.elements.MetaAnnotatedElement; +import org.dromara.hutool.core.annotation.elements.RepeatableMetaAnnotatedElement; import org.dromara.hutool.core.map.WeakConcurrentMap; import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.util.ObjUtil; @@ -41,11 +44,11 @@ import java.util.stream.Stream; * eg:
* 若类A分别有父类和父接口BC, * 则通过getXXX方法将只能获得A上的注解, - * 而通过getXXX方法将能获得ABC上的注解。 + * 而通过findXXX方法将能获得ABC上的注解。 * *

搜索元注解 *

工具类支持搜索注解的元注解。在所有格式为getXXXfindXXX的静态方法中, - * 若不带有directly关键字,则该方法支持搜索元注解,否则皆支持搜索元注解。
+ * 若不带有directly关键字,则该方法支持搜索元注解,否则不支持搜索元注解。
* eg:
* 若类A分别有父类和父接口BC,上面分别有注解X与其元注解Y, * 则此时基于A有: diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/AnnotationUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/AnnotationUtil.java index 3533c3619..16f71e573 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/AnnotationUtil.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/AnnotationUtil.java @@ -12,6 +12,7 @@ package org.dromara.hutool.core.annotation; +import org.dromara.hutool.core.annotation.elements.CombinationAnnotatedElement; import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.classloader.ClassLoaderUtil; import org.dromara.hutool.core.exception.HutoolException; @@ -68,11 +69,11 @@ public class AnnotationUtil { * @param annotationEle 注解元素 * @return 组合注解元素 */ - public static CombinationAnnotationElement toCombination(final AnnotatedElement annotationEle) { - if (annotationEle instanceof CombinationAnnotationElement) { - return (CombinationAnnotationElement) annotationEle; + public static CombinationAnnotatedElement toCombination(final AnnotatedElement annotationEle) { + if (annotationEle instanceof CombinationAnnotatedElement) { + return (CombinationAnnotatedElement) annotationEle; } - return new CombinationAnnotationElement(annotationEle); + return new CombinationAnnotatedElement(annotationEle); } /** @@ -139,7 +140,7 @@ public class AnnotationUtil { if (null == predicate) { return toCombination(annotationEle).getAnnotations(); } - return CombinationAnnotationElement.of(annotationEle, predicate).getAnnotations(); + return CombinationAnnotatedElement.of(annotationEle, predicate).getAnnotations(); } final Annotation[] result = annotationEle.getAnnotations(); diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/ResolvedAnnotationMapping.java b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/ResolvedAnnotationMapping.java index 605a11d57..b6e987b96 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/ResolvedAnnotationMapping.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/ResolvedAnnotationMapping.java @@ -12,6 +12,7 @@ package org.dromara.hutool.core.annotation; +import org.dromara.hutool.core.annotation.elements.MetaAnnotatedElement; import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.map.multi.Graph; diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/CombinationAnnotationElement.java b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/CombinationAnnotatedElement.java similarity index 81% rename from hutool-core/src/main/java/org/dromara/hutool/core/annotation/CombinationAnnotationElement.java rename to hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/CombinationAnnotatedElement.java index a6f1abd0a..c2fbd1b72 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/CombinationAnnotationElement.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/CombinationAnnotatedElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 looly(loolly@aliyun.com) + * Copyright (c) 2023-2024. looly(loolly@aliyun.com) * Hutool is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -10,8 +10,9 @@ * See the Mulan PSL v2 for more details. */ -package org.dromara.hutool.core.annotation; +package org.dromara.hutool.core.annotation.elements; +import org.dromara.hutool.core.annotation.AnnotationUtil; import org.dromara.hutool.core.collection.set.SetUtil; import org.dromara.hutool.core.map.TableMap; @@ -32,7 +33,7 @@ import java.util.function.Predicate; * @since 4.0.9 **/ -public class CombinationAnnotationElement implements AnnotatedElement, Serializable { +public class CombinationAnnotatedElement implements AnnotatedElement, Serializable { private static final long serialVersionUID = 1L; /** @@ -43,20 +44,21 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa * @return CombinationAnnotationElement * @since 5.8.0 */ - public static CombinationAnnotationElement of(final AnnotatedElement element, final Predicate predicate) { - return new CombinationAnnotationElement(element, predicate); + public static CombinationAnnotatedElement of(final AnnotatedElement element, final Predicate predicate) { + return new CombinationAnnotatedElement(element, predicate); } /** * 元注解 */ - private static final Set> META_ANNOTATIONS = SetUtil.of(Target.class, // - Retention.class, // - Inherited.class, // - Documented.class, // - SuppressWarnings.class, // - Override.class, // - Deprecated.class// + private static final Set> META_ANNOTATIONS = SetUtil.of( + Target.class, // + Retention.class, // + Inherited.class, // + Documented.class, // + SuppressWarnings.class, // + Override.class, // + Deprecated.class// ); /** @@ -77,7 +79,7 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa * * @param element 需要解析注解的元素:可以是Class、Method、Field、Constructor、ReflectPermission */ - public CombinationAnnotationElement(final AnnotatedElement element) { + public CombinationAnnotatedElement(final AnnotatedElement element) { this(element, null); } @@ -88,7 +90,7 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa * @param predicate 过滤器,{@link Predicate#test(Object)}返回{@code true}保留,否则不保留 * @since 5.8.0 */ - public CombinationAnnotationElement(final AnnotatedElement element, final Predicate predicate) { + public CombinationAnnotatedElement(final AnnotatedElement element, final Predicate predicate) { this.predicate = predicate; init(element); } @@ -147,9 +149,9 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa for (final Annotation annotation : annotations) { annotationType = annotation.annotationType(); if (!META_ANNOTATIONS.contains(annotationType) - // issue#I5FQGW@Gitee:跳过元注解和已经处理过的注解,防止递归调用 - && !declaredAnnotationMap.containsKey(annotationType)) { - if(test(annotation)){ + // issue#I5FQGW@Gitee:跳过元注解和已经处理过的注解,防止递归调用 + && !declaredAnnotationMap.containsKey(annotationType)) { + if (test(annotation)) { declaredAnnotationMap.put(annotationType, annotation); } // 测试不通过的注解,不影响继续递归 @@ -168,9 +170,9 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa for (final Annotation annotation : annotations) { annotationType = annotation.annotationType(); if (!META_ANNOTATIONS.contains(annotationType) - // issue#I5FQGW@Gitee:跳过元注解和已经处理过的注解,防止递归调用 - && !annotationMap.containsKey(annotationType)) { - if(test(annotation)){ + // issue#I5FQGW@Gitee:跳过元注解和已经处理过的注解,防止递归调用 + && !annotationMap.containsKey(annotationType)) { + if (test(annotation)) { annotationMap.put(annotationType, annotation); } // 测试不通过的注解,不影响继续递归 diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/HierarchicalAnnotatedElements.java b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/HierarchicalAnnotatedElements.java similarity index 98% rename from hutool-core/src/main/java/org/dromara/hutool/core/annotation/HierarchicalAnnotatedElements.java rename to hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/HierarchicalAnnotatedElements.java index 96026a67b..48ab7b0a2 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/HierarchicalAnnotatedElements.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/HierarchicalAnnotatedElements.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 looly(loolly@aliyun.com) + * Copyright (c) 2023-2024. looly(loolly@aliyun.com) * Hutool is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -10,8 +10,9 @@ * See the Mulan PSL v2 for more details. */ -package org.dromara.hutool.core.annotation; +package org.dromara.hutool.core.annotation.elements; +import org.dromara.hutool.core.annotation.AnnotationUtil; import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.reflect.ClassUtil; import org.dromara.hutool.core.reflect.method.MethodUtil; diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/MetaAnnotatedElement.java b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/MetaAnnotatedElement.java similarity index 97% rename from hutool-core/src/main/java/org/dromara/hutool/core/annotation/MetaAnnotatedElement.java rename to hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/MetaAnnotatedElement.java index 141dc0bc1..c01aa10ab 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/MetaAnnotatedElement.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/MetaAnnotatedElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 looly(loolly@aliyun.com) + * Copyright (c) 2023-2024. looly(loolly@aliyun.com) * Hutool is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -10,8 +10,11 @@ * See the Mulan PSL v2 for more details. */ -package org.dromara.hutool.core.annotation; +package org.dromara.hutool.core.annotation.elements; +import org.dromara.hutool.core.annotation.AnnotationMapping; +import org.dromara.hutool.core.annotation.AnnotationUtil; +import org.dromara.hutool.core.annotation.ResolvedAnnotationMapping; import org.dromara.hutool.core.stream.EasyStream; import org.dromara.hutool.core.text.CharSequenceUtil; import org.dromara.hutool.core.array.ArrayUtil; diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/RepeatableMetaAnnotatedElement.java b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/RepeatableMetaAnnotatedElement.java similarity index 97% rename from hutool-core/src/main/java/org/dromara/hutool/core/annotation/RepeatableMetaAnnotatedElement.java rename to hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/RepeatableMetaAnnotatedElement.java index e5c569a66..392014993 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/RepeatableMetaAnnotatedElement.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/RepeatableMetaAnnotatedElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 looly(loolly@aliyun.com) + * Copyright (c) 2023-2024. looly(loolly@aliyun.com) * Hutool is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -10,8 +10,11 @@ * See the Mulan PSL v2 for more details. */ -package org.dromara.hutool.core.annotation; +package org.dromara.hutool.core.annotation.elements; +import org.dromara.hutool.core.annotation.AnnotationMapping; +import org.dromara.hutool.core.annotation.AnnotationUtil; +import org.dromara.hutool.core.annotation.RepeatableAnnotationCollector; import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.text.CharSequenceUtil; import org.dromara.hutool.core.array.ArrayUtil; diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/package-info.java b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/package-info.java new file mode 100644 index 000000000..8e9f5da0e --- /dev/null +++ b/hutool-core/src/main/java/org/dromara/hutool/core/annotation/elements/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024. looly(loolly@aliyun.com) + * Hutool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * https://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * AnnotatedElement对象实现 + * + * @author Looly, huangchengxing + */ +package org.dromara.hutool.core.annotation.elements; diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/AnnotationUtilTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/AnnotationUtilTest.java index 3ec29b2be..ff753056b 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/AnnotationUtilTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/AnnotationUtilTest.java @@ -12,6 +12,7 @@ package org.dromara.hutool.core.annotation; +import org.dromara.hutool.core.annotation.elements.CombinationAnnotatedElement; import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.util.ObjUtil; import lombok.SneakyThrows; @@ -41,7 +42,7 @@ public class AnnotationUtilTest { @Test public void testToCombination() { - final CombinationAnnotationElement element = AnnotationUtil.toCombination(ClassForTest.class); + final CombinationAnnotatedElement element = AnnotationUtil.toCombination(ClassForTest.class); Assertions.assertEquals(2, element.getAnnotations().length); } diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/CombinationAnnotationElementTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/CombinationAnnotatedElementTest.java similarity index 73% rename from hutool-core/src/test/java/org/dromara/hutool/core/annotation/CombinationAnnotationElementTest.java rename to hutool-core/src/test/java/org/dromara/hutool/core/annotation/CombinationAnnotatedElementTest.java index 76411b122..e62e61eae 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/CombinationAnnotationElementTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/CombinationAnnotatedElementTest.java @@ -12,25 +12,26 @@ package org.dromara.hutool.core.annotation; +import org.dromara.hutool.core.annotation.elements.CombinationAnnotatedElement; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.lang.annotation.*; /** - * test for {@link CombinationAnnotationElement} + * test for {@link CombinationAnnotatedElement} */ -public class CombinationAnnotationElementTest { +public class CombinationAnnotatedElementTest { @Test public void testOf() { - final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); + final CombinationAnnotatedElement element = CombinationAnnotatedElement.of(ClassForTest.class, a -> true); Assertions.assertNotNull(element); } @Test public void testIsAnnotationPresent() { - final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); + final CombinationAnnotatedElement element = CombinationAnnotatedElement.of(ClassForTest.class, a -> true); Assertions.assertTrue(element.isAnnotationPresent(MetaAnnotationForTest.class)); } @@ -38,21 +39,21 @@ public class CombinationAnnotationElementTest { public void testGetAnnotation() { final AnnotationForTest annotation1 = ClassForTest.class.getAnnotation(AnnotationForTest.class); final MetaAnnotationForTest annotation2 = AnnotationForTest.class.getAnnotation(MetaAnnotationForTest.class); - final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); + final CombinationAnnotatedElement element = CombinationAnnotatedElement.of(ClassForTest.class, a -> true); Assertions.assertEquals(annotation1, element.getAnnotation(AnnotationForTest.class)); Assertions.assertEquals(annotation2, element.getAnnotation(MetaAnnotationForTest.class)); } @Test public void testGetAnnotations() { - final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); + final CombinationAnnotatedElement element = CombinationAnnotatedElement.of(ClassForTest.class, a -> true); final Annotation[] annotations = element.getAnnotations(); Assertions.assertEquals(2, annotations.length); } @Test public void testGetDeclaredAnnotations() { - final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); + final CombinationAnnotatedElement element = CombinationAnnotatedElement.of(ClassForTest.class, a -> true); final Annotation[] annotations = element.getDeclaredAnnotations(); Assertions.assertEquals(2, annotations.length); } diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/HierarchicalAnnotatedElementTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/HierarchicalAnnotatedElementTest.java index a148d1f95..6f2fa1b94 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/HierarchicalAnnotatedElementTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/HierarchicalAnnotatedElementTest.java @@ -13,6 +13,7 @@ package org.dromara.hutool.core.annotation; import lombok.SneakyThrows; +import org.dromara.hutool.core.annotation.elements.HierarchicalAnnotatedElements; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/MetaAnnotatedElementTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/MetaAnnotatedElementTest.java index 8f314bf23..32a8e855e 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/MetaAnnotatedElementTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/MetaAnnotatedElementTest.java @@ -12,6 +12,7 @@ package org.dromara.hutool.core.annotation; +import org.dromara.hutool.core.annotation.elements.MetaAnnotatedElement; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java index 735b35673..d4e8c8cb5 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java @@ -12,6 +12,7 @@ package org.dromara.hutool.core.annotation; +import org.dromara.hutool.core.annotation.elements.RepeatableMetaAnnotatedElement; import org.dromara.hutool.core.collection.iter.IterUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test;