mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复当注解存在循环引用时报错的问题
This commit is contained in:
parent
96d6c39a14
commit
de06d8777c
@ -10,7 +10,6 @@ import java.lang.annotation.Inherited;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* <p>注解元素映射,用于包装一个{@link AnnotatedElement},然后将被包装的元素上,
|
||||
@ -314,11 +313,15 @@ public class MetaAnnotatedElement<T extends AnnotationMapping<Annotation>> imple
|
||||
}
|
||||
// 保存该注解,并将其需要处理的元注解也加入队列
|
||||
mappings.put(mapping.annotationType(), mapping);
|
||||
Stream.of(AnnotationUtil.getDeclaredAnnotations(mapping.annotationType()))
|
||||
.map(annotation -> createMapping(mapping, annotation))
|
||||
.filter(Objects::nonNull)
|
||||
.filter(m -> isNeedMapping(mappings, m))
|
||||
.forEach(deque::addLast);
|
||||
for (final Annotation annotation : AnnotationUtil.getDeclaredAnnotations(mapping.annotationType())) {
|
||||
if (mappings.containsKey(annotation.annotationType())) {
|
||||
continue;
|
||||
}
|
||||
final T m = createMapping(mapping, annotation);
|
||||
if (Objects.nonNull(m) && isNeedMapping(mappings, m)) {
|
||||
deque.addLast(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* <p>支持可重复注解的增强{@link AnnotatedElement},
|
||||
@ -347,11 +346,15 @@ public class RepeatableMetaAnnotatedElement<T extends AnnotationMapping<Annotati
|
||||
continue;
|
||||
}
|
||||
collectedMappings.put(source.annotationType(), source);
|
||||
Stream.of(AnnotationUtil.getDeclaredAnnotations(source.annotationType()))
|
||||
.map(annotation -> mappingFactory.apply(source, annotation))
|
||||
.filter(Objects::nonNull)
|
||||
.filter(m -> isNeedMapping(collectedMappings, m))
|
||||
.forEach(deque::addLast);
|
||||
for (final Annotation annotation : AnnotationUtil.getDeclaredAnnotations(source.annotationType())) {
|
||||
if (collectedMappings.containsKey(annotation.annotationType())) {
|
||||
continue;
|
||||
}
|
||||
final T mapping = mappingFactory.apply(source, annotation);
|
||||
if (Objects.nonNull(mapping) && isNeedMapping(collectedMappings, mapping)) {
|
||||
deque.addLast(mapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
return collectedMappings;
|
||||
}
|
||||
|
@ -572,6 +572,7 @@ public class AnnotatedElementUtilTest {
|
||||
|
||||
// ================= interface =================
|
||||
|
||||
@Annotation6
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
private @interface Annotation5 {}
|
||||
|
@ -170,6 +170,7 @@ public class MetaAnnotatedElementTest {
|
||||
Assert.assertSame(source, element.getElement());
|
||||
}
|
||||
|
||||
@Annotation4 // 循环引用
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
private @interface None { }
|
||||
|
@ -199,6 +199,7 @@ public class RepeatableMetaAnnotatedElementTest {
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
private @interface Annotation3 { }
|
||||
|
||||
@Annotation4 // 循环引用
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
private @interface Annotation4 { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user