Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Jun 27, 2022
1 parent d8047b0 commit 6d85091
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class SyntheticAnnotation<A extends Annotation> implements Annotation, An
/**
* 基于指定根注解,构建包括其元注解在内的合成注解
*
* @param <T> 注解类型
* @param rootAnnotation 根注解
* @return 合成注解
*/
Expand Down Expand Up @@ -104,7 +105,7 @@ Map<Class<? extends Annotation>, MetaAnnotation> getMetaAnnotationMap() {
/**
* 获取根注解类型
*
* @return java.lang.Class<? extends java.lang.annotation.Annotation>
* @return java.lang.Class&lt;? extends java.lang.annotation.Annotation&gt;
*/
@Override
public Class<? extends Annotation> annotationType() {
Expand All @@ -116,6 +117,8 @@ public Class<? extends Annotation> annotationType() {
* <p>当不同层级的注解之间存在同名同类型属性时,将优先获取更接近根注解的属性
*
* @param attributeName 属性名
* @param attributeType 属性类型
* @return 属性
*/
public Object getAttribute(String attributeName, Class<?> attributeType) {
Map<Class<?>, Object> values = attributeCaches.computeIfAbsent(attributeName, t -> MapUtil.newHashMap());
Expand Down Expand Up @@ -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(", "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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));
Expand All @@ -83,11 +82,11 @@ public void scan(BiConsumer<Integer, Annotation> consumer, Class<? extends Annot
@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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -161,11 +163,11 @@ public boolean support(AnnotatedElement annotatedElement) {

@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) {
Expand Down

0 comments on commit 6d85091

Please sign in to comment.