mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
添加判断是否为jdk元注解的方法;
This commit is contained in:
parent
84711ad790
commit
ef289dc676
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.annotation;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
@ -16,6 +17,7 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
@ -27,6 +29,58 @@ import java.util.function.Predicate;
|
||||
*/
|
||||
public class AnnotationUtil {
|
||||
|
||||
/**
|
||||
* 元注解
|
||||
*/
|
||||
static final Set<Class<? extends Annotation>> META_ANNOTATIONS = CollUtil.newHashSet(Target.class, //
|
||||
Retention.class, //
|
||||
Inherited.class, //
|
||||
Documented.class, //
|
||||
SuppressWarnings.class, //
|
||||
Override.class, //
|
||||
Deprecated.class//
|
||||
);
|
||||
|
||||
/**
|
||||
* 是否为Jdk自带的元注解。<br />
|
||||
* 包括:
|
||||
* <ul>
|
||||
* <li>{@link Target}</li>
|
||||
* <li>{@link Retention}</li>
|
||||
* <li>{@link Inherited}</li>
|
||||
* <li>{@link Documented}</li>
|
||||
* <li>{@link SuppressWarnings}</li>
|
||||
* <li>{@link Override}</li>
|
||||
* <li>{@link Deprecated}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param annotationType 注解类型
|
||||
* @return 是否为Jdk自带的元注解
|
||||
*/
|
||||
public static boolean isJdkMateAnnotation(Class<? extends Annotation> annotationType) {
|
||||
return META_ANNOTATIONS.contains(annotationType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否不为Jdk自带的元注解。<br />
|
||||
* 包括:
|
||||
* <ul>
|
||||
* <li>{@link Target}</li>
|
||||
* <li>{@link Retention}</li>
|
||||
* <li>{@link Inherited}</li>
|
||||
* <li>{@link Documented}</li>
|
||||
* <li>{@link SuppressWarnings}</li>
|
||||
* <li>{@link Override}</li>
|
||||
* <li>{@link Deprecated}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param annotationType 注解类型
|
||||
* @return 是否为Jdk自带的元注解
|
||||
*/
|
||||
public static boolean isNotJdkMateAnnotation(Class<? extends Annotation> annotationType) {
|
||||
return !isJdkMateAnnotation(annotationType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定的被注解的元素转换为组合注解元素
|
||||
*
|
||||
|
@ -39,18 +39,6 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa
|
||||
return new CombinationAnnotationElement(element, predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 元注解
|
||||
*/
|
||||
private static final Set<Class<? extends Annotation>> META_ANNOTATIONS = CollUtil.newHashSet(Target.class, //
|
||||
Retention.class, //
|
||||
Inherited.class, //
|
||||
Documented.class, //
|
||||
SuppressWarnings.class, //
|
||||
Override.class, //
|
||||
Deprecated.class//
|
||||
);
|
||||
|
||||
/**
|
||||
* 注解类型与注解对象对应表
|
||||
*/
|
||||
@ -138,7 +126,7 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa
|
||||
// 直接注解
|
||||
for (Annotation annotation : annotations) {
|
||||
annotationType = annotation.annotationType();
|
||||
if (false == META_ANNOTATIONS.contains(annotationType)) {
|
||||
if (AnnotationUtil.isNotJdkMateAnnotation(annotationType)) {
|
||||
if(test(annotation)){
|
||||
declaredAnnotationMap.put(annotationType, annotation);
|
||||
}
|
||||
@ -157,7 +145,7 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa
|
||||
Class<? extends Annotation> annotationType;
|
||||
for (Annotation annotation : annotations) {
|
||||
annotationType = annotation.annotationType();
|
||||
if (false == META_ANNOTATIONS.contains(annotationType)) {
|
||||
if (AnnotationUtil.isNotJdkMateAnnotation(annotationType)) {
|
||||
if(test(annotation)){
|
||||
annotationMap.put(annotationType, annotation);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user