Class ClassScanner
java.lang.Object
cloud.opencode.base.reflect.scan.ClassScanner
Class Scanner
类扫描器
Scans for classes matching various criteria.
扫描匹配各种条件的类。
Features | 主要功能:
- Package scanning - 包扫描
- Annotation filtering - 注解过滤
- Subtype filtering - 子类型过滤
- Custom predicate filtering - 自定义谓词过滤
Usage Examples | 使用示例:
List<Class<?>> classes = ClassScanner.from(classPath)
.inPackage("com.example")
.recursive()
.withAnnotation(Component.class)
.scan();
Security | 安全性:
- Thread-safe: No (mutable builder state) - 线程安全: 否(可变构建器状态)
- Null-safe: No (class path must be non-null) - 空值安全: 否(类路径须非空)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionFilters for concrete classes only 仅过滤具体类static ClassScannercreate()Creates a scanner using current context ClassLoader 使用当前上下文ClassLoader创建扫描器Filters for enum classes only 仅过滤枚举类Filters by Class predicate (after loading) 按Class谓词过滤(加载后)filterInfo(Predicate<ClassInfo> predicate) Filters by ClassInfo predicate (before loading) 按ClassInfo谓词过滤(加载前)static ClassScannerCreates a scanner from ClassPath 从ClassPath创建扫描器static ClassScannerfrom(ClassLoader classLoader) Creates a scanner from ClassLoader 从ClassLoader创建扫描器implementing(Class<?> interfaceClass) Filters for implementations of an interface 过滤接口的实现类includeInnerClasses(boolean include) Sets whether to include inner classes 设置是否包含内部类Adds a base package to scan 添加要扫描的基础包inPackages(String... packageNames) Adds multiple base packages to scan 添加多个要扫描的基础包Filters for interfaces only 仅过滤接口Filters for record classes only 仅过滤Record类recursive(boolean recursive) Sets whether to scan recursively 设置是否递归扫描scan()Scans and returns loaded classes 扫描并返回已加载的类scanInfo()Scans and returns ClassInfo without loading classes 扫描并返回ClassInfo(不加载类)stream()Scans and returns as stream 扫描并返回为流Filters for subtypes of a class 过滤某类的子类型toList()Scans and returns as list 扫描并返回为列表withAnnotation(Class<? extends Annotation> annotationClass) Filters for classes with annotation 过滤具有注解的类
-
Method Details
-
from
Creates a scanner from ClassPath 从ClassPath创建扫描器- Parameters:
classPath- the ClassPath | ClassPath- Returns:
- the scanner | 扫描器
-
from
Creates a scanner from ClassLoader 从ClassLoader创建扫描器- Parameters:
classLoader- the class loader | 类加载器- Returns:
- the scanner | 扫描器
-
create
Creates a scanner using current context ClassLoader 使用当前上下文ClassLoader创建扫描器- Returns:
- the scanner | 扫描器
-
inPackage
Adds a base package to scan 添加要扫描的基础包- Parameters:
packageName- the package name | 包名- Returns:
- this scanner | 此扫描器
-
inPackages
Adds multiple base packages to scan 添加多个要扫描的基础包- Parameters:
packageNames- the package names | 包名- Returns:
- this scanner | 此扫描器
-
recursive
Sets whether to scan recursively 设置是否递归扫描- Parameters:
recursive- whether to scan recursively | 是否递归扫描- Returns:
- this scanner | 此扫描器
-
includeInnerClasses
Sets whether to include inner classes 设置是否包含内部类- Parameters:
include- whether to include | 是否包含- Returns:
- this scanner | 此扫描器
-
filterInfo
Filters by ClassInfo predicate (before loading) 按ClassInfo谓词过滤(加载前)- Parameters:
predicate- the predicate | 谓词- Returns:
- this scanner | 此扫描器
-
filter
Filters by Class predicate (after loading) 按Class谓词过滤(加载后)- Parameters:
predicate- the predicate | 谓词- Returns:
- this scanner | 此扫描器
-
withAnnotation
Filters for classes with annotation 过滤具有注解的类- Parameters:
annotationClass- the annotation class | 注解类- Returns:
- this scanner | 此扫描器
-
subtypeOf
Filters for subtypes of a class 过滤某类的子类型- Parameters:
superClass- the super class | 父类- Returns:
- this scanner | 此扫描器
-
implementing
Filters for implementations of an interface 过滤接口的实现类- Parameters:
interfaceClass- the interface class | 接口类- Returns:
- this scanner | 此扫描器
-
interfacesOnly
-
concreteOnly
Filters for concrete classes only 仅过滤具体类- Returns:
- this scanner | 此扫描器
-
recordsOnly
Filters for record classes only 仅过滤Record类- Returns:
- this scanner | 此扫描器
-
enumsOnly
-
scanInfo
-
scan
-
stream
-
toList
-