fix comment

This commit is contained in:
huangchengxing 2022-06-30 15:34:16 +08:00
parent 7cc0994942
commit 8cf3015075
7 changed files with 75 additions and 79 deletions

View File

@ -151,7 +151,7 @@ public class AnnotationUtil {
*/
public static Annotation[] getAnnotations(AnnotatedElement annotationEle, boolean isToCombination, Predicate<Annotation> predicate) {
if (null == annotationEle) {
return null;
return new Annotation[0];
}
if (isToCombination) {
@ -438,7 +438,7 @@ public class AnnotationUtil {
}
/**
* 方法是否为注解属性方法 <br />
* 方法是否为注解属性方法 <br>
* 方法无参数且有返回值的方法认为是注解属性的方法
*
* @param method 方法

View File

@ -159,14 +159,14 @@ public abstract class AbstractTypeAnnotationScanner<T extends AbstractTypeAnnota
/**
* 则根据广度优先递归扫描类的层级结构并对层级结构中类/接口声明的层级索引和它们声明的注解对象进行处理
*
* @param consumer 对获取到的注解和注解对应的层级索引的处理
* @param annotatedElement 注解元素
* @param filter 注解过滤器无法通过过滤器的注解不会被处理该参数允许为空
* @param consumer 对获取到的注解和注解对应的层级索引的处理
* @param annotatedEle 注解元素
* @param filter 注解过滤器无法通过过滤器的注解不会被处理该参数允许为空
*/
@Override
public void scan(BiConsumer<Integer, Annotation> consumer, AnnotatedElement annotatedElement, Predicate<Annotation> filter) {
public void scan(BiConsumer<Integer, Annotation> consumer, AnnotatedElement annotatedEle, Predicate<Annotation> filter) {
filter = ObjectUtil.defaultIfNull(filter, annotation -> true);
final Class<?> sourceClass = getClassFormAnnotatedElement(annotatedElement);
final Class<?> sourceClass = getClassFormAnnotatedElement(annotatedEle);
final Deque<List<Class<?>>> classDeque = CollUtil.newLinkedList(CollUtil.newArrayList(sourceClass));
final Set<Class<?>> accessedTypes = new LinkedHashSet<>();
int index = 0;
@ -185,7 +185,7 @@ public abstract class AbstractTypeAnnotationScanner<T extends AbstractTypeAnnota
// 扫描接口
scanInterfaceIfNecessary(nextClassQueue, targetClass);
// 处理层级索引和注解
final Annotation[] targetAnnotations = getAnnotationsFromTargetClass(annotatedElement, index, targetClass);
final Annotation[] targetAnnotations = getAnnotationsFromTargetClass(annotatedEle, index, targetClass);
for (final Annotation annotation : targetAnnotations) {
if (AnnotationUtil.isNotJdkMateAnnotation(annotation.annotationType()) || filter.test(annotation)) {
consumer.accept(index, annotation);

View File

@ -29,22 +29,22 @@ public interface AnnotationScanner {
/**
* 判断是否支持扫描该注解元素
*
* @param annotatedElement 注解元素
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @return 是否支持扫描该注解元素
*/
default boolean support(AnnotatedElement annotatedElement) {
default boolean support(AnnotatedElement annotatedEle) {
return false;
}
/**
* 获取注解元素上的全部注解调用该方法前需要确保调用{@link #support(AnnotatedElement)}返回为true
*
* @param annotatedElement 注解元素
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @return 注解
*/
default List<Annotation> getAnnotations(AnnotatedElement annotatedElement) {
default List<Annotation> getAnnotations(AnnotatedElement annotatedEle) {
final List<Annotation> annotations = new ArrayList<>();
scan((index, annotation) -> annotations.add(annotation), annotatedElement, null);
scan((index, annotation) -> annotations.add(annotation), annotatedEle, null);
return annotations;
}
@ -53,24 +53,24 @@ public interface AnnotationScanner {
* 则调用并返回{@link #getAnnotations(AnnotatedElement)}结果
* 否则返回{@link Collections#emptyList()}
*
* @param annotatedElement 注解元素
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @return 注解
*/
default List<Annotation> getIfSupport(AnnotatedElement annotatedElement) {
return support(annotatedElement) ? getAnnotations(annotatedElement) : Collections.emptyList();
default List<Annotation> getIfSupport(AnnotatedElement annotatedEle) {
return support(annotatedEle) ? getAnnotations(annotatedEle) : Collections.emptyList();
}
/**
* 扫描注解元素的层级结构若存在然后对获取到的注解和注解对应的层级索引进行处理
* 调用该方法前需要确保调用{@link #support(AnnotatedElement)}返回为true
*
* @param consumer 对获取到的注解和注解对应的层级索引的处理
* @param annotatedElement 注解元素
* @param filter 注解过滤器无法通过过滤器的注解不会被处理该参数允许为空
* @param consumer 对获取到的注解和注解对应的层级索引的处理
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @param filter 注解过滤器无法通过过滤器的注解不会被处理该参数允许为空
*/
default void scan(BiConsumer<Integer, Annotation> consumer, AnnotatedElement annotatedElement, Predicate<Annotation> filter) {
default void scan(BiConsumer<Integer, Annotation> consumer, AnnotatedElement annotatedEle, Predicate<Annotation> filter) {
filter = ObjectUtil.defaultIfNull(filter, annotation -> true);
for (Annotation annotation : annotatedElement.getAnnotations()) {
for (Annotation annotation : annotatedEle.getAnnotations()) {
if (AnnotationUtil.isNotJdkMateAnnotation(annotation.annotationType()) && filter.test(annotation)) {
consumer.accept(0, annotation);
}
@ -80,47 +80,47 @@ public interface AnnotationScanner {
/**
* {@link #support(AnnotatedElement)}返回{@code true}则调用{@link #scan(BiConsumer, AnnotatedElement, Predicate)}
*
* @param consumer 对获取到的注解和注解对应的层级索引的处理
* @param annotatedElement 注解元素
* @param filter 注解过滤器无法通过过滤器的注解不会被处理该参数允许为空
* @param consumer 对获取到的注解和注解对应的层级索引的处理
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @param filter 注解过滤器无法通过过滤器的注解不会被处理该参数允许为空
*/
default void scanIfSupport(BiConsumer<Integer, Annotation> consumer, AnnotatedElement annotatedElement, Predicate<Annotation> filter) {
if (support(annotatedElement)) {
scan(consumer, annotatedElement, filter);
default void scanIfSupport(BiConsumer<Integer, Annotation> consumer, AnnotatedElement annotatedEle, Predicate<Annotation> filter) {
if (support(annotatedEle)) {
scan(consumer, annotatedEle, filter);
}
}
/**
* 给定一组扫描器使用第一个支持处理该类型元素的扫描器获取元素上可能存在的注解
*
* @param annotatedElement 注解元素
* @param scanners 注解扫描器
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @param scanners 注解扫描器
* @return 注解
*/
static List<Annotation> scanByAnySupported(AnnotatedElement annotatedElement, AnnotationScanner... scanners) {
if (ObjectUtil.isNull(annotatedElement) && ArrayUtil.isNotEmpty(scanners)) {
static List<Annotation> scanByAnySupported(AnnotatedElement annotatedEle, AnnotationScanner... scanners) {
if (ObjectUtil.isNull(annotatedEle) && ArrayUtil.isNotEmpty(scanners)) {
return Collections.emptyList();
}
return Stream.of(scanners)
.filter(scanner -> scanner.support(annotatedElement))
.filter(scanner -> scanner.support(annotatedEle))
.findFirst()
.map(scanner -> scanner.getAnnotations(annotatedElement))
.map(scanner -> scanner.getAnnotations(annotatedEle))
.orElseGet(Collections::emptyList);
}
/**
* 根据指定的扫描器扫描元素上可能存在的注解
*
* @param annotatedElement 注解元素
* @param scanners 注解扫描器
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @param scanners 注解扫描器
* @return 注解
*/
static List<Annotation> scanByAllScanner(AnnotatedElement annotatedElement, AnnotationScanner... scanners) {
if (ObjectUtil.isNull(annotatedElement) && ArrayUtil.isNotEmpty(scanners)) {
static List<Annotation> scanByAllScanner(AnnotatedElement annotatedEle, AnnotationScanner... scanners) {
if (ObjectUtil.isNull(annotatedEle) && ArrayUtil.isNotEmpty(scanners)) {
return Collections.emptyList();
}
return Stream.of(scanners)
.map(scanner -> scanner.getIfSupport(annotatedElement))
.map(scanner -> scanner.getIfSupport(annotatedEle))
.flatMap(Collection::stream)
.collect(Collectors.toList());
}

View File

@ -19,25 +19,25 @@ public class FieldAnnotationScanner implements AnnotationScanner {
/**
* 判断是否支持扫描该注解元素仅当注解元素是{@link Field}时返回{@code true}
*
* @param annotatedElement 注解元素
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @return 是否支持扫描该注解元素
*/
@Override
public boolean support(AnnotatedElement annotatedElement) {
return annotatedElement instanceof Field;
public boolean support(AnnotatedElement annotatedEle) {
return annotatedEle instanceof Field;
}
/**
* 扫描{@link Field}上直接声明的注解调用前需要确保调用{@link #support(AnnotatedElement)}返回为true
*
* @param consumer 对获取到的注解和注解对应的层级索引的处理
* @param annotatedElement 注解元素
* @param filter 注解过滤器无法通过过滤器的注解不会被处理该参数允许为空
* @param consumer 对获取到的注解和注解对应的层级索引的处理
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @param filter 注解过滤器无法通过过滤器的注解不会被处理该参数允许为空
*/
@Override
public void scan(BiConsumer<Integer, Annotation> consumer, AnnotatedElement annotatedElement, Predicate<Annotation> filter) {
public void scan(BiConsumer<Integer, Annotation> consumer, AnnotatedElement annotatedEle, Predicate<Annotation> filter) {
filter = ObjectUtil.defaultIfNull(filter, annotation -> true);
for (Annotation annotation : annotatedElement.getAnnotations()) {
for (Annotation annotation : annotatedEle.getAnnotations()) {
if (AnnotationUtil.isNotJdkMateAnnotation(annotation.annotationType()) && filter.test(annotation)) {
consumer.accept(0, annotation);
}

View File

@ -49,27 +49,26 @@ public class MetaAnnotationScanner implements AnnotationScanner {
/**
* 判断是否支持扫描该注解元素仅当注解元素是{@link Annotation}接口的子类{@link Class}时返回{@code true}
*
* @param annotatedElement 注解元素
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @return 是否支持扫描该注解元素
*/
@Override
public boolean support(AnnotatedElement annotatedElement) {
return (annotatedElement instanceof Class && ClassUtil.isAssignable(Annotation.class, (Class<?>) annotatedElement));
public boolean support(AnnotatedElement annotatedEle) {
return (annotatedEle instanceof Class && ClassUtil.isAssignable(Annotation.class, (Class<?>)annotatedEle));
}
/**
* 获取注解元素上的全部注解调用该方法前需要确保调用{@link #support(AnnotatedElement)}返回为true
*
* @param annotatedElement 注解元素
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @return 注解
*/
@Override
public List<Annotation> getAnnotations(AnnotatedElement annotatedElement) {
public List<Annotation> getAnnotations(AnnotatedElement annotatedEle) {
final List<Annotation> annotations = new ArrayList<>();
scan(
(index, annotation) -> annotations.add(annotation),
annotatedElement,
annotation -> ObjectUtil.notEqual(annotation, annotatedElement)
(index, annotation) -> annotations.add(annotation), annotatedEle,
annotation -> ObjectUtil.notEqual(annotation, annotatedEle)
);
return annotations;
}
@ -77,15 +76,15 @@ public class MetaAnnotationScanner implements AnnotationScanner {
/**
* 按广度优先扫描指定注解上的元注解对扫描到的注解与层级索引进行操作
*
* @param consumer 当前层级索引与操作
* @param source 源注解
* @param filter 过滤器
* @param consumer 当前层级索引与操作
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @param filter 过滤器
*/
@SuppressWarnings("unchecked")
@Override
public void scan(BiConsumer<Integer, Annotation> consumer, AnnotatedElement source, Predicate<Annotation> filter) {
public void scan(BiConsumer<Integer, Annotation> consumer, AnnotatedElement annotatedEle, Predicate<Annotation> filter) {
filter = ObjectUtil.defaultIfNull(filter, t -> true);
final Deque<List<Class<? extends Annotation>>> deque = CollUtil.newLinkedList(CollUtil.newArrayList((Class<? extends Annotation>)source));
final Deque<List<Class<? extends Annotation>>> deque = CollUtil.newLinkedList(CollUtil.newArrayList((Class<? extends Annotation>)annotatedEle));
int distance = 0;
do {
final List<Class<? extends Annotation>> annotationTypes = deque.removeFirst();

View File

@ -49,21 +49,19 @@ public class MethodAnnotationScanner extends AbstractTypeAnnotationScanner<Metho
/**
* 判断是否支持扫描该注解元素仅当注解元素是{@link Method}时返回{@code true}
*
* @param annotatedElement 注解元素
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @return boolean 是否支持扫描该注解元素
*/
@Override
public boolean support(AnnotatedElement annotatedElement) {
return annotatedElement instanceof Method;
public boolean support(AnnotatedElement annotatedEle) {
return annotatedEle instanceof Method;
}
/**
* 获取声明该方法的类
*
* @param annotatedElement 注解元素
* @return java.lang.Class<?>
* @author huangchengxing
* @date 2022/6/29 17:21
* @return 要递归的类型
* @see Method#getDeclaringClass()
*/
@Override
@ -74,9 +72,10 @@ public class MethodAnnotationScanner extends AbstractTypeAnnotationScanner<Metho
/**
* 若父类/父接口中方法具有相同的方法签名则返回该方法上的注解
*
* @param source 原始方法
* @param index 类的层级索引
* @param source 原始方法
* @param index 类的层级索引
* @param targetClass
* @return 最终所需的目标注解
*/
@Override
protected Annotation[] getAnnotationsFromTargetClass(AnnotatedElement source, int index, Class<?> targetClass) {
@ -92,7 +91,7 @@ public class MethodAnnotationScanner extends AbstractTypeAnnotationScanner<Metho
/**
* 设置是否扫描类层级结构中具有相同方法签名的方法
*
* @param scanSuperMethodIfOverride 则是否扫描原方法
* @param scanSuperMethodIfOverride 是否扫描类层级结构中具有相同方法签名的方法
* @return 当前实例
*/
public MethodAnnotationScanner setScanSameSignatureMethod(boolean scanSuperMethodIfOverride) {

View File

@ -38,23 +38,23 @@ public class TypeAnnotationScanner extends AbstractTypeAnnotationScanner<TypeAnn
/**
* 判断是否支持扫描该注解元素仅当注解元素是{@link Class}接时返回{@code true}
*
* @param annotatedElement 注解元素
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @return 是否支持扫描该注解元素
*/
@Override
public boolean support(AnnotatedElement annotatedElement) {
return annotatedElement instanceof Class;
public boolean support(AnnotatedElement annotatedEle) {
return annotatedEle instanceof Class;
}
/**
* 将注解元素转为{@link Class}
*
* @param annotatedElement 注解元素
* @return
* @param annotatedEle {@link AnnotatedElement}可以是ClassMethodFieldConstructorReflectPermission
* @return 要递归的
*/
@Override
protected Class<?> getClassFormAnnotatedElement(AnnotatedElement annotatedElement) {
return (Class<?>)annotatedElement;
protected Class<?> getClassFormAnnotatedElement(AnnotatedElement annotatedEle) {
return (Class<?>)annotatedEle;
}
/**
@ -73,7 +73,7 @@ public class TypeAnnotationScanner extends AbstractTypeAnnotationScanner<TypeAnn
/**
* 是否允许扫描父类
*
* @param includeSupperClass 是否
* @param includeSupperClass 是否允许扫描父类
* @return 当前实例
*/
@Override
@ -84,7 +84,7 @@ public class TypeAnnotationScanner extends AbstractTypeAnnotationScanner<TypeAnn
/**
* 是否允许扫描父接口
*
* @param includeInterfaces 是否
* @param includeInterfaces 是否允许扫描父类
* @return 当前实例
*/
@Override
@ -94,9 +94,7 @@ public class TypeAnnotationScanner extends AbstractTypeAnnotationScanner<TypeAnn
/**
* 若类型为jdk代理类则尝试转换为原始被代理类
* @deprecated replace with {@link AbstractTypeAnnotationScanner.JdkProxyClassConverter}
*/
@Deprecated
public static class JdkProxyClassConverter implements UnaryOperator<Class<?>> {
@Override
public Class<?> apply(Class<?> sourceClass) {