mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
change name
This commit is contained in:
parent
9e426dd3a5
commit
028f498a04
@ -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: <br>
|
||||
* 若类<em>A</em>分别有父类和父接口<em>B</em>、<em>C</em>,
|
||||
* 则通过<em>getXXX</em>方法将只能获得<em>A</em>上的注解,
|
||||
* 而通过<em>getXXX</em>方法将能获得<em>A</em>、<em>B</em>、<em>C</em>上的注解。
|
||||
* 而通过<em>findXXX</em>方法将能获得<em>A</em>、<em>B</em>、<em>C</em>上的注解。
|
||||
*
|
||||
* <p><strong>搜索元注解</strong>
|
||||
* <p>工具类支持搜索注解的元注解。在所有格式为<em>getXXX</em>或<em>findXXX</em>的静态方法中,
|
||||
* 若不带有<em>directly</em>关键字,则该方法支持搜索元注解,否则皆支持搜索元注解。<br>
|
||||
* 若不带有<em>directly</em>关键字,则该方法支持搜索元注解,否则不支持搜索元注解。<br>
|
||||
* eg: <br>
|
||||
* 若类<em>A</em>分别有父类和父接口<em>B</em>、<em>C</em>,上面分别有注解<em>X</em>与其元注解<em>Y</em>,
|
||||
* 则此时基于<em>A</em>有:
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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<Annotation> predicate) {
|
||||
return new CombinationAnnotationElement(element, predicate);
|
||||
public static CombinationAnnotatedElement of(final AnnotatedElement element, final Predicate<Annotation> predicate) {
|
||||
return new CombinationAnnotatedElement(element, predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 元注解
|
||||
*/
|
||||
private static final Set<Class<? extends Annotation>> META_ANNOTATIONS = SetUtil.of(Target.class, //
|
||||
Retention.class, //
|
||||
Inherited.class, //
|
||||
Documented.class, //
|
||||
SuppressWarnings.class, //
|
||||
Override.class, //
|
||||
Deprecated.class//
|
||||
private static final Set<Class<? extends Annotation>> 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<Annotation> predicate) {
|
||||
public CombinationAnnotatedElement(final AnnotatedElement element, final Predicate<Annotation> 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);
|
||||
}
|
||||
// 测试不通过的注解,不影响继续递归
|
@ -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;
|
@ -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;
|
@ -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;
|
@ -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;
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user