public interface RepeatableAnnotationCollector
Modifier and Type | Interface and Description |
---|---|
static class |
RepeatableAnnotationCollector.AbstractCollector
RepeatableAnnotationCollector 的基本实现 |
static class |
RepeatableAnnotationCollector.Condition
自定义判断条件的实现,当解析注解属性时,将根据给定的判断条件,
确定该属性中是否含有可重复注解,收集器将返回所有匹配的属性中的可重复注解。
|
static class |
RepeatableAnnotationCollector.Full
全量实现,当注解中存在有属性为注解数组,且该数组对应的注解类型被
Repeatable 注解时,
认为该属性包含可重复注解。 |
static class |
RepeatableAnnotationCollector.None
空实现
|
static class |
RepeatableAnnotationCollector.Standard
标准实现,当注解中有且仅有一个名为
value 的属性时,
若该属性类型为注解数组,且该数组对应的注解类型被Repeatable 注解,
则收集器将返回该属性中包括的可重复注解。 |
Modifier and Type | Method and Description |
---|---|
static void |
clearSingletonCaches()
清空单例缓存
|
static RepeatableAnnotationCollector |
condition(BiPredicate<Annotation,Method> predicate)
当解析注解属性时,将根据给定的判断条件,确定该属性中是否含有可重复注解。
|
static RepeatableAnnotationCollector |
full()
当注解中存在有属性为注解数组,且该数组对应的注解类型被
Repeatable 注解时,
认为该属性包含可重复注解。 |
List<Annotation> |
getAllRepeatableAnnotations(Annotation annotation)
若一个注解是可重复注解的容器注解,则尝试通过其属性获得获得包含的注解对象。
|
List<Annotation> |
getFinalRepeatableAnnotations(Annotation annotation)
若一个注解是可重复注解的容器注解,则尝试通过其属性获得获得包含的注解对象。
|
<T extends Annotation> |
getRepeatableAnnotations(Annotation annotation,
Class<T> annotationType)
若一个注解是可重复注解的容器注解,则尝试通过其属性获得获得包含的指定类型注解对象。
|
static RepeatableAnnotationCollector |
none()
空实现
|
static RepeatableAnnotationCollector |
standard()
当注解中有且仅有一个名为
value 的属性时,
若该属性类型为注解数组,且该数组对应的注解类型被Repeatable 注解,
则收集器将返回该属性中包括的可重复注解。 |
static RepeatableAnnotationCollector none()
RepeatableAnnotationCollector
实例static RepeatableAnnotationCollector standard()
当注解中有且仅有一个名为value
的属性时,
若该属性类型为注解数组,且该数组对应的注解类型被Repeatable
注解,
则收集器将返回该属性中包括的可重复注解。
eg:
// 容器注解
@interface Annotation {
Item[] value() default {};
}
// 可重复注解
@Repeatable(Annotation.class)
@interface Item {}
解析任意Annotation
注解对象,则可以获得value
属性中的Item
注解对象RepeatableAnnotationCollector
实例RepeatableAnnotationCollector.Standard
static RepeatableAnnotationCollector condition(BiPredicate<Annotation,Method> predicate)
predicate
- 是否为容纳可重复注解的属性的判断条件RepeatableAnnotationCollector
实例static RepeatableAnnotationCollector full()
当注解中存在有属性为注解数组,且该数组对应的注解类型被Repeatable
注解时,
认为该属性包含可重复注解。
收集器将返回所有符合上述条件的属性中的可重复注解。
eg:
@interface Annotation {
Item1[] items1() default {};
Item2[] items2() default {};
}
解析任意Annotation
注解对象,
则可以获得items1
属性中的Item1
注解对象,
以及items2
属性中的Item2
注解对象,RepeatableAnnotationCollector
实例static void clearSingletonCaches()
List<Annotation> getFinalRepeatableAnnotations(Annotation annotation)
若一个注解是可重复注解的容器注解,则尝试通过其属性获得获得包含的注解对象。
若包含的注解对象也是可重复注解的容器注解,则继续解析直到获得所有非容器注解为止。
eg:
若存在嵌套关系a -> b -> c
,
则解析注解a,则将得到全部c注解。
如果注解不包含可重复注解,则返回a本身。
annotation
- 容器注解annotation
不为容器注解,则数组中仅有其本身一个对象List<Annotation> getAllRepeatableAnnotations(Annotation annotation)
若一个注解是可重复注解的容器注解,则尝试通过其属性获得获得包含的注解对象。
若包含的注解对象也是可重复注解的容器注解,则继续解析直到获得所有非容器注解为止。
eg:
若存在嵌套关系a -> b -> c
,则解析注解a,
将获得全部a、b、c注解。
如果注解不包含可重复注解,则返回a本身。
annotation
- 容器注解annotation
不为容器注解,则数组中仅有其本身一个对象<T extends Annotation> List<T> getRepeatableAnnotations(Annotation annotation, Class<T> annotationType)
若一个注解是可重复注解的容器注解,则尝试通过其属性获得获得包含的指定类型注解对象。
eg:
若存在嵌套关系a -> b -> c
,则:
T
- 注解类型annotation
- 容器注解annotationType
- 注解类型Copyright © 2025. All rights reserved.