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 8662caf8b..570ef8b6c 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 @@ -353,34 +353,11 @@ public class AnnotationUtil { * @return 合成注解 * @see SynthesizedAnnotationAggregator */ - public static T getSynthesisAnnotation(Annotation annotation, Class annotationType) { + public static T getSynthesizedAnnotation(Annotation annotation, Class annotationType) { // TODO 缓存合成注解信息,避免重复解析 return SynthesizedAnnotationAggregator.of(annotation).synthesize(annotationType); } - /** - * 获取元素上所有指定注解 - *
    - *
  • 若元素是类,则递归解析全部父类和全部父接口上的注解;
  • - *
  • 若元素是方法、属性或注解,则只解析其直接声明的注解;
  • - *
- * - * @param annotatedEle {@link AnnotatedElement},可以是Class、Method、Field、Constructor、ReflectPermission - * @param annotationType 注解类 - * @param 注解类型 - * @return 合成注解 - * @see SynthesizedAnnotationAggregator - */ - public static List getAllSynthesisAnnotations(AnnotatedElement annotatedEle, Class annotationType) { - AnnotationScanner[] scanners = new AnnotationScanner[]{ - new MetaAnnotationScanner(), new TypeAnnotationScanner(), new MethodAnnotationScanner(), new FieldAnnotationScanner() - }; - return AnnotationScanner.scanByAnySupported(annotatedEle, scanners).stream() - .map(annotation -> getSynthesisAnnotation(annotation, annotationType)) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - } - /** * 获取元素上距离指定元素最接近的合成注解 *
    @@ -394,7 +371,7 @@ public class AnnotationUtil { * @return 合成注解 * @see SynthesizedAnnotationAggregator */ - public static T getSyntheticAnnotation(AnnotatedElement annotatedEle, Class annotationType) { + public static T getSynthesizedAnnotation(AnnotatedElement annotatedEle, Class annotationType) { T target = annotatedEle.getAnnotation(annotationType); if (ObjectUtil.isNotNull(target)) { return target; @@ -403,10 +380,33 @@ public class AnnotationUtil { new MetaAnnotationScanner(), new TypeAnnotationScanner(), new MethodAnnotationScanner(), new FieldAnnotationScanner() }; return AnnotationScanner.scanByAnySupported(annotatedEle, scanners).stream() - .map(annotation -> getSynthesisAnnotation(annotation, annotationType)) + .map(annotation -> getSynthesizedAnnotation(annotation, annotationType)) + .filter(Objects::nonNull) + .findFirst() + .orElse(null); + } + + /** + * 获取元素上所有指定注解 + *
      + *
    • 若元素是类,则递归解析全部父类和全部父接口上的注解;
    • + *
    • 若元素是方法、属性或注解,则只解析其直接声明的注解;
    • + *
    + * + * @param annotatedEle {@link AnnotatedElement},可以是Class、Method、Field、Constructor、ReflectPermission + * @param annotationType 注解类 + * @param 注解类型 + * @return 合成注解 + * @see SynthesizedAnnotationAggregator + */ + public static List getAllSynthesizedAnnotations(AnnotatedElement annotatedEle, Class annotationType) { + AnnotationScanner[] scanners = new AnnotationScanner[]{ + new MetaAnnotationScanner(), new TypeAnnotationScanner(), new MethodAnnotationScanner(), new FieldAnnotationScanner() + }; + return AnnotationScanner.scanByAnySupported(annotatedEle, scanners).stream() + .map(annotation -> getSynthesizedAnnotation(annotation, annotationType)) .filter(Objects::nonNull) - .findFirst() - .orElse(null); + .collect(Collectors.toList()); } /** 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 8a8688944..5fb175cc5 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 @@ -80,7 +80,7 @@ class SyntheticAnnotationProxy implements InvocationHandler { void loadMethods() { methods.put("toString", (method, args) -> proxyToString()); methods.put("hashCode", (method, args) -> proxyHashCode()); - methods.put("getSyntheticAnnotation", (method, args) -> proxyGetSyntheticAnnotation()); + methods.put("getSynthesizedAnnotation", (method, args) -> proxyGetSyntheticAnnotation()); methods.put("getSynthesizedAnnotation", (method, args) -> proxyGetSynthesizedAnnotation()); methods.put("getRoot", (method, args) -> annotation.getRoot()); methods.put("getVerticalDistance", (method, args) -> annotation.getVerticalDistance()); diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotationUtil.java b/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotationUtil.java index dc054c90f..9a5f8f5a4 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotationUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotationUtil.java @@ -24,7 +24,7 @@ class SyntheticAnnotationUtil { */ static Link getLink(AnnotationAttribute attribute, RelationType... relationTypes) { return Opt.ofNullable(attribute) - .map(t -> AnnotationUtil.getSyntheticAnnotation(attribute.getAttribute(), Link.class)) + .map(t -> AnnotationUtil.getSynthesizedAnnotation(attribute.getAttribute(), Link.class)) .filter(a -> ArrayUtil.contains(relationTypes, a.type())) .get(); }