diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotation.java b/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotation.java index 0d964cce10..b40cfd0a6f 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotation.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/SyntheticAnnotation.java @@ -76,6 +76,7 @@ public class SyntheticAnnotation implements Annotation, An /** * 基于指定根注解,构建包括其元注解在内的合成注解 * + * @param 注解类型 * @param rootAnnotation 根注解 * @return 合成注解 */ @@ -104,7 +105,7 @@ Map, MetaAnnotation> getMetaAnnotationMap() { /** * 获取根注解类型 * - * @return java.lang.Class + * @return java.lang.Class<? extends java.lang.annotation.Annotation> */ @Override public Class annotationType() { @@ -116,6 +117,8 @@ public Class annotationType() { *

当不同层级的注解之间存在同名同类型属性时,将优先获取更接近根注解的属性 * * @param attributeName 属性名 + * @param attributeType 属性类型 + * @return 属性 */ public Object getAttribute(String attributeName, Class attributeType) { Map, Object> values = attributeCaches.computeIfAbsent(attributeName, t -> MapUtil.newHashMap()); @@ -333,7 +336,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl * @return toString值 */ private String getToString() { - String attributes = Stream.of(annotationType().getDeclaredMethods()) + final String attributes = Stream.of(annotationType().getDeclaredMethods()) .filter(AnnotationUtil::isAttributeMethod) .map(method -> StrUtil.format("{}={}", method.getName(), syntheticAnnotation.getAttribute(method.getName(), method.getReturnType()))) .collect(Collectors.joining(", ")); diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/MetaAnnotationScanner.java b/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/MetaAnnotationScanner.java index 862ca76cec..bbb036f310 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/MetaAnnotationScanner.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/MetaAnnotationScanner.java @@ -48,30 +48,29 @@ public MetaAnnotationScanner() { @Override public boolean support(AnnotatedElement annotatedElement) { - return (annotatedElement instanceof Class && ClassUtil.isAssignable(Annotation.class, (Class)annotatedElement)); + return (annotatedElement instanceof Class && ClassUtil.isAssignable(Annotation.class, (Class) annotatedElement)); } /** * 按广度优先扫描指定注解上的元注解,对扫描到的注解与层级索引进行操作 * * @param consumer 当前层级索引与操作 - * @param source 源注解 - * @param filter 过滤器 + * @param source 源注解 + * @param filter 过滤器 * @author huangchengxing - * @date 2022/6/14 13:28 */ public void scan(BiConsumer consumer, Class source, Predicate filter) { filter = ObjectUtil.defaultIfNull(filter, t -> true); - Deque>> deque = CollUtil.newLinkedList(CollUtil.newArrayList(source)); + final Deque>> deque = CollUtil.newLinkedList(CollUtil.newArrayList(source)); int distance = 0; do { - List> annotationTypes = deque.removeFirst(); - for (Class type : annotationTypes) { - List metaAnnotations = Stream.of(type.getAnnotations()) - .filter(a -> !AnnotationUtil.isJdkMetaAnnotation(a.annotationType())) - .filter(filter) - .collect(Collectors.toList()); - for (Annotation metaAnnotation : metaAnnotations) { + final List> annotationTypes = deque.removeFirst(); + for (final Class type : annotationTypes) { + final List metaAnnotations = Stream.of(type.getAnnotations()) + .filter(a -> !AnnotationUtil.isJdkMetaAnnotation(a.annotationType())) + .filter(filter) + .collect(Collectors.toList()); + for (final Annotation metaAnnotation : metaAnnotations) { consumer.accept(distance, metaAnnotation); } deque.addLast(CollStreamUtil.toList(metaAnnotations, Annotation::annotationType)); @@ -83,11 +82,11 @@ public void scan(BiConsumer consumer, Class getAnnotations(AnnotatedElement annotatedElement) { - List annotations = new ArrayList<>(); + final List annotations = new ArrayList<>(); scan( - (index, annotation) -> annotations.add(annotation), - (Class)annotatedElement, - annotation -> ObjectUtil.notEqual(annotation, annotatedElement) + (index, annotation) -> annotations.add(annotation), + (Class) annotatedElement, + annotation -> ObjectUtil.notEqual(annotation, annotatedElement) ); return annotations; } diff --git a/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/TypeAnnotationScanner.java b/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/TypeAnnotationScanner.java index 5501befe7b..76066b412c 100644 --- a/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/TypeAnnotationScanner.java +++ b/hutool-core/src/main/java/cn/hutool/core/annotation/scanner/TypeAnnotationScanner.java @@ -56,7 +56,9 @@ public class TypeAnnotationScanner implements AnnotationScanner { * 构造一个类注解扫描器 * * @param includeSupperClass 是否允许扫描父类 - * @param includeInterfaces 是否允许扫描父接口 + * @param includeInterfaces 是否允许扫描父接口 + * @param filter 过滤器 + * @param excludeTypes 不包含的类型 */ public TypeAnnotationScanner(boolean includeSupperClass, boolean includeInterfaces, Predicate> filter, Set> excludeTypes) { Assert.notNull(filter, "filter must not null"); @@ -161,11 +163,11 @@ public boolean support(AnnotatedElement annotatedElement) { @Override public List getAnnotations(AnnotatedElement annotatedElement) { - return scan((Class)annotatedElement).stream() - .map(Class::getAnnotations) - .flatMap(Stream::of) - .filter(a -> !AnnotationUtil.isJdkMetaAnnotation(a.annotationType())) - .collect(Collectors.toList()); + return scan((Class) annotatedElement).stream() + .map(Class::getAnnotations) + .flatMap(Stream::of) + .filter(a -> !AnnotationUtil.isJdkMetaAnnotation(a.annotationType())) + .collect(Collectors.toList()); } private Class convert(Class target) {