Class AnnotationScanner
java.lang.Object
cloud.opencode.base.reflect.scan.AnnotationScanner
Annotation Scanner
注解扫描器
Scans for annotated elements (classes, methods, fields, etc.).
扫描被注解的元素(类、方法、字段等)。
Features | 主要功能:
- Annotated class scanning - 被注解类扫描
- Annotated method scanning - 被注解方法扫描
- Annotated field scanning - 被注解字段扫描
- Meta-annotation support - 元注解支持
Usage Examples | 使用示例:
List<Class<?>> controllers = AnnotationScanner.from(classScanner)
.includeMetaAnnotations()
.findClassesWithAnnotation(Controller.class);
Security | 安全性:
- Thread-safe: No (mutable configuration state) - 线程安全: 否(可变配置状态)
- Null-safe: No (caller must ensure non-null arguments) - 空值安全: 否(调用方须确保非空参数)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult holder for annotated element 被注解元素结果持有者 -
Method Summary
Modifier and TypeMethodDescriptionstatic AnnotationScannercreate()Creates an AnnotationScanner using context ClassLoader 使用上下文ClassLoader创建AnnotationScannerfindAllFieldsWithAnnotation(Class<? extends Annotation> annotationClass) Finds all fields with annotation as flat list 查找所有具有注解的字段(扁平列表)findAllMethodsWithAnnotation(Class<? extends Annotation> annotationClass) Finds all methods with annotation as flat list 查找所有具有注解的方法(扁平列表)findClassesWithAllAnnotations(Class<? extends Annotation>... annotationClasses) Finds all classes with all annotations 查找具有所有注解的类findClassesWithAnnotation(Class<? extends Annotation> annotationClass) Finds all classes with annotation 查找所有具有注解的类findClassesWithAnyAnnotation(Class<? extends Annotation>... annotationClasses) Finds all classes with any of the annotations 查找具有任一注解的所有类Map<Class<?>, Set<Constructor<?>>> findConstructorsWithAnnotation(Class<? extends Annotation> annotationClass) Finds all constructors with annotation 查找所有具有注解的构造器findFieldsWithAnnotation(Class<? extends Annotation> annotationClass) Finds all fields with annotation 查找所有具有注解的字段findMethodsWithAnnotation(Class<? extends Annotation> annotationClass) Finds all methods with annotation 查找所有具有注解的方法findParametersWithAnnotation(Class<? extends Annotation> annotationClass) Finds all parameters with annotation 查找所有具有注解的参数static AnnotationScannerfrom(ClassScanner classScanner) Creates an AnnotationScanner from ClassScanner 从ClassScanner创建AnnotationScannerstatic AnnotationScannerfrom(ClassLoader classLoader) Creates an AnnotationScanner from ClassLoader 从ClassLoader创建AnnotationScannerincludeMetaAnnotations(boolean include) Sets whether to include meta-annotations 设置是否包含元注解Sets the base package to scan 设置要扫描的基础包
-
Method Details
-
from
Creates an AnnotationScanner from ClassScanner 从ClassScanner创建AnnotationScanner- Parameters:
classScanner- the class scanner | 类扫描器- Returns:
- the annotation scanner | 注解扫描器
-
from
Creates an AnnotationScanner from ClassLoader 从ClassLoader创建AnnotationScanner- Parameters:
classLoader- the class loader | 类加载器- Returns:
- the annotation scanner | 注解扫描器
-
create
Creates an AnnotationScanner using context ClassLoader 使用上下文ClassLoader创建AnnotationScanner- Returns:
- the annotation scanner | 注解扫描器
-
inPackage
Sets the base package to scan 设置要扫描的基础包- Parameters:
packageName- the package name | 包名- Returns:
- this scanner | 此扫描器
-
includeMetaAnnotations
Sets whether to include meta-annotations 设置是否包含元注解- Parameters:
include- whether to include | 是否包含- Returns:
- this scanner | 此扫描器
-
findClassesWithAnnotation
Finds all classes with annotation 查找所有具有注解的类- Parameters:
annotationClass- the annotation class | 注解类- Returns:
- set of classes | 类集合
-
findClassesWithAnyAnnotation
@SafeVarargs public final Set<Class<?>> findClassesWithAnyAnnotation(Class<? extends Annotation>... annotationClasses) Finds all classes with any of the annotations 查找具有任一注解的所有类- Parameters:
annotationClasses- the annotation classes | 注解类- Returns:
- set of classes | 类集合
-
findClassesWithAllAnnotations
@SafeVarargs public final Set<Class<?>> findClassesWithAllAnnotations(Class<? extends Annotation>... annotationClasses) Finds all classes with all annotations 查找具有所有注解的类- Parameters:
annotationClasses- the annotation classes | 注解类- Returns:
- set of classes | 类集合
-
findMethodsWithAnnotation
-
findAllMethodsWithAnnotation
Finds all methods with annotation as flat list 查找所有具有注解的方法(扁平列表)- Parameters:
annotationClass- the annotation class | 注解类- Returns:
- list of methods | 方法列表
-
findFieldsWithAnnotation
-
findAllFieldsWithAnnotation
Finds all fields with annotation as flat list 查找所有具有注解的字段(扁平列表)- Parameters:
annotationClass- the annotation class | 注解类- Returns:
- list of fields | 字段列表
-
findConstructorsWithAnnotation
public Map<Class<?>, Set<Constructor<?>>> findConstructorsWithAnnotation(Class<? extends Annotation> annotationClass) Finds all constructors with annotation 查找所有具有注解的构造器- Parameters:
annotationClass- the annotation class | 注解类- Returns:
- map of class to constructors | 类到构造器的映射
-
findParametersWithAnnotation
public Map<Executable, Set<Parameter>> findParametersWithAnnotation(Class<? extends Annotation> annotationClass) Finds all parameters with annotation 查找所有具有注解的参数- Parameters:
annotationClass- the annotation class | 注解类- Returns:
- map of method to parameters | 方法到参数的映射
-