mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix comment
This commit is contained in:
parent
d8047b00c4
commit
6d8509155a
@ -76,6 +76,7 @@ public class SyntheticAnnotation<A extends Annotation> implements Annotation, An
|
||||
/**
|
||||
* 基于指定根注解,构建包括其元注解在内的合成注解
|
||||
*
|
||||
* @param <T> 注解类型
|
||||
* @param rootAnnotation 根注解
|
||||
* @return 合成注解
|
||||
*/
|
||||
@ -104,7 +105,7 @@ public class SyntheticAnnotation<A extends Annotation> implements Annotation, An
|
||||
/**
|
||||
* 获取根注解类型
|
||||
*
|
||||
* @return java.lang.Class<? extends java.lang.annotation.Annotation>
|
||||
* @return java.lang.Class<? extends java.lang.annotation.Annotation>
|
||||
*/
|
||||
@Override
|
||||
public Class<? extends Annotation> annotationType() {
|
||||
@ -116,6 +117,8 @@ public class SyntheticAnnotation<A extends Annotation> implements Annotation, An
|
||||
* <p>当不同层级的注解之间存在同名同类型属性时,将优先获取更接近根注解的属性
|
||||
*
|
||||
* @param attributeName 属性名
|
||||
* @param attributeType 属性类型
|
||||
* @return 属性
|
||||
*/
|
||||
public Object getAttribute(String attributeName, Class<?> attributeType) {
|
||||
Map<Class<?>, Object> values = attributeCaches.computeIfAbsent(attributeName, t -> MapUtil.newHashMap());
|
||||
@ -333,7 +336,7 @@ public class SyntheticAnnotation<A extends Annotation> implements Annotation, An
|
||||
* @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(", "));
|
||||
|
@ -48,30 +48,29 @@ public class MetaAnnotationScanner implements AnnotationScanner {
|
||||
|
||||
@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<Integer, Annotation> consumer, Class<? extends Annotation> source, Predicate<Annotation> filter) {
|
||||
filter = ObjectUtil.defaultIfNull(filter, t -> true);
|
||||
Deque<List<Class<? extends Annotation>>> deque = CollUtil.newLinkedList(CollUtil.newArrayList(source));
|
||||
final Deque<List<Class<? extends Annotation>>> deque = CollUtil.newLinkedList(CollUtil.newArrayList(source));
|
||||
int distance = 0;
|
||||
do {
|
||||
List<Class<? extends Annotation>> annotationTypes = deque.removeFirst();
|
||||
for (Class<? extends Annotation> type : annotationTypes) {
|
||||
List<Annotation> metaAnnotations = Stream.of(type.getAnnotations())
|
||||
.filter(a -> !AnnotationUtil.isJdkMetaAnnotation(a.annotationType()))
|
||||
.filter(filter)
|
||||
.collect(Collectors.toList());
|
||||
for (Annotation metaAnnotation : metaAnnotations) {
|
||||
final List<Class<? extends Annotation>> annotationTypes = deque.removeFirst();
|
||||
for (final Class<? extends Annotation> type : annotationTypes) {
|
||||
final List<Annotation> 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 class MetaAnnotationScanner implements AnnotationScanner {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Annotation> getAnnotations(AnnotatedElement annotatedElement) {
|
||||
List<Annotation> annotations = new ArrayList<>();
|
||||
final List<Annotation> annotations = new ArrayList<>();
|
||||
scan(
|
||||
(index, annotation) -> annotations.add(annotation),
|
||||
(Class<? extends Annotation>)annotatedElement,
|
||||
annotation -> ObjectUtil.notEqual(annotation, annotatedElement)
|
||||
(index, annotation) -> annotations.add(annotation),
|
||||
(Class<? extends Annotation>) annotatedElement,
|
||||
annotation -> ObjectUtil.notEqual(annotation, annotatedElement)
|
||||
);
|
||||
return annotations;
|
||||
}
|
||||
|
@ -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<Class<?>> filter, Set<Class<?>> excludeTypes) {
|
||||
Assert.notNull(filter, "filter must not null");
|
||||
@ -161,11 +163,11 @@ public class TypeAnnotationScanner implements AnnotationScanner {
|
||||
|
||||
@Override
|
||||
public List<Annotation> 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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user