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 根注解
|
* @param rootAnnotation 根注解
|
||||||
* @return 合成注解
|
* @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
|
@Override
|
||||||
public Class<? extends Annotation> annotationType() {
|
public Class<? extends Annotation> annotationType() {
|
||||||
@ -116,6 +117,8 @@ public class SyntheticAnnotation<A extends Annotation> implements Annotation, An
|
|||||||
* <p>当不同层级的注解之间存在同名同类型属性时,将优先获取更接近根注解的属性
|
* <p>当不同层级的注解之间存在同名同类型属性时,将优先获取更接近根注解的属性
|
||||||
*
|
*
|
||||||
* @param attributeName 属性名
|
* @param attributeName 属性名
|
||||||
|
* @param attributeType 属性类型
|
||||||
|
* @return 属性
|
||||||
*/
|
*/
|
||||||
public Object getAttribute(String attributeName, Class<?> attributeType) {
|
public Object getAttribute(String attributeName, Class<?> attributeType) {
|
||||||
Map<Class<?>, Object> values = attributeCaches.computeIfAbsent(attributeName, t -> MapUtil.newHashMap());
|
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值
|
* @return toString值
|
||||||
*/
|
*/
|
||||||
private String getToString() {
|
private String getToString() {
|
||||||
String attributes = Stream.of(annotationType().getDeclaredMethods())
|
final String attributes = Stream.of(annotationType().getDeclaredMethods())
|
||||||
.filter(AnnotationUtil::isAttributeMethod)
|
.filter(AnnotationUtil::isAttributeMethod)
|
||||||
.map(method -> StrUtil.format("{}={}", method.getName(), syntheticAnnotation.getAttribute(method.getName(), method.getReturnType())))
|
.map(method -> StrUtil.format("{}={}", method.getName(), syntheticAnnotation.getAttribute(method.getName(), method.getReturnType())))
|
||||||
.collect(Collectors.joining(", "));
|
.collect(Collectors.joining(", "));
|
||||||
|
@ -58,20 +58,19 @@ public class MetaAnnotationScanner implements AnnotationScanner {
|
|||||||
* @param source 源注解
|
* @param source 源注解
|
||||||
* @param filter 过滤器
|
* @param filter 过滤器
|
||||||
* @author huangchengxing
|
* @author huangchengxing
|
||||||
* @date 2022/6/14 13:28
|
|
||||||
*/
|
*/
|
||||||
public void scan(BiConsumer<Integer, Annotation> consumer, Class<? extends Annotation> source, Predicate<Annotation> filter) {
|
public void scan(BiConsumer<Integer, Annotation> consumer, Class<? extends Annotation> source, Predicate<Annotation> filter) {
|
||||||
filter = ObjectUtil.defaultIfNull(filter, t -> true);
|
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;
|
int distance = 0;
|
||||||
do {
|
do {
|
||||||
List<Class<? extends Annotation>> annotationTypes = deque.removeFirst();
|
final List<Class<? extends Annotation>> annotationTypes = deque.removeFirst();
|
||||||
for (Class<? extends Annotation> type : annotationTypes) {
|
for (final Class<? extends Annotation> type : annotationTypes) {
|
||||||
List<Annotation> metaAnnotations = Stream.of(type.getAnnotations())
|
final List<Annotation> metaAnnotations = Stream.of(type.getAnnotations())
|
||||||
.filter(a -> !AnnotationUtil.isJdkMetaAnnotation(a.annotationType()))
|
.filter(a -> !AnnotationUtil.isJdkMetaAnnotation(a.annotationType()))
|
||||||
.filter(filter)
|
.filter(filter)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
for (Annotation metaAnnotation : metaAnnotations) {
|
for (final Annotation metaAnnotation : metaAnnotations) {
|
||||||
consumer.accept(distance, metaAnnotation);
|
consumer.accept(distance, metaAnnotation);
|
||||||
}
|
}
|
||||||
deque.addLast(CollStreamUtil.toList(metaAnnotations, Annotation::annotationType));
|
deque.addLast(CollStreamUtil.toList(metaAnnotations, Annotation::annotationType));
|
||||||
@ -83,7 +82,7 @@ public class MetaAnnotationScanner implements AnnotationScanner {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public List<Annotation> getAnnotations(AnnotatedElement annotatedElement) {
|
public List<Annotation> getAnnotations(AnnotatedElement annotatedElement) {
|
||||||
List<Annotation> annotations = new ArrayList<>();
|
final List<Annotation> annotations = new ArrayList<>();
|
||||||
scan(
|
scan(
|
||||||
(index, annotation) -> annotations.add(annotation),
|
(index, annotation) -> annotations.add(annotation),
|
||||||
(Class<? extends Annotation>) annotatedElement,
|
(Class<? extends Annotation>) annotatedElement,
|
||||||
|
@ -57,6 +57,8 @@ public class TypeAnnotationScanner implements AnnotationScanner {
|
|||||||
*
|
*
|
||||||
* @param includeSupperClass 是否允许扫描父类
|
* @param includeSupperClass 是否允许扫描父类
|
||||||
* @param includeInterfaces 是否允许扫描父接口
|
* @param includeInterfaces 是否允许扫描父接口
|
||||||
|
* @param filter 过滤器
|
||||||
|
* @param excludeTypes 不包含的类型
|
||||||
*/
|
*/
|
||||||
public TypeAnnotationScanner(boolean includeSupperClass, boolean includeInterfaces, Predicate<Class<?>> filter, Set<Class<?>> excludeTypes) {
|
public TypeAnnotationScanner(boolean includeSupperClass, boolean includeInterfaces, Predicate<Class<?>> filter, Set<Class<?>> excludeTypes) {
|
||||||
Assert.notNull(filter, "filter must not null");
|
Assert.notNull(filter, "filter must not null");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user