Class ClassScanner
java.lang.Object
cloud.opencode.base.classloader.scanner.ClassScanner
Class Scanner - Scans classes in specified packages
类扫描器 - 扫描指定包下的类
Scans and finds classes matching specified criteria.
扫描并查找匹配指定条件的类。
Features | 主要功能:
- Package scanning - 包扫描
- Annotation scanning - 注解扫描
- Subtype scanning - 子类型扫描
- Custom filter support - 自定义过滤器支持
- Disk cache support for scan results - 扫描结果磁盘缓存支持
Usage Examples | 使用示例:
ClassScanner scanner = ClassScanner.of("com.example");
Set<Class<?>> services = scanner.scanWithAnnotation(Service.class);
Set<Class<?>> all = scanner.scan();
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-classloader V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionSet cache directory for scan result caching 设置扫描结果缓存目录Set cache key (e.g. application version) 设置缓存键(如应用版本号)classLoader(ClassLoader classLoader) Set class loader 设置类加载器Return class name stream (without loading) 返回类名流(不加载类)excludePackage(String packageName) Add excluded package 添加排除包includeInnerClasses(boolean include) Set whether to include inner classes 设置是否包含内部类includeJars(boolean include) Set whether to include JAR files 设置是否包含 JAR 文件includeNestedJars(boolean include) Set whether to include nested JARs (e.g.static ClassScannerof(ClassLoader classLoader, String basePackage) Create scanner with classloader 使用类加载器创建扫描器static ClassScannerCreate scanner for single package 为单个包创建扫描器static ClassScannerCreate scanner for multiple packages 为多个包创建扫描器parallel(boolean parallel) Set parallel scanning 设置并行扫描scan()Scan all classes 扫描所有类scan(ScanFilter filter) Scan with filter 使用过滤器扫描scanImplementations(Class<T> interfaceType) Scan for interface implementations 扫描接口实现scanSubTypes(Class<T> superType) Scan for subtypes 扫描子类型scanWithAnnotation(Class<? extends Annotation> annotation) Scan for classes with annotation 扫描带注解的类stream()Return class stream (lazy loading) 返回类流(懒加载)
-
Method Details
-
of
Create scanner for single package 为单个包创建扫描器- Parameters:
basePackage- base package | 基础包- Returns:
- scanner | 扫描器
-
of
Create scanner for multiple packages 为多个包创建扫描器- Parameters:
basePackages- base packages | 基础包数组- Returns:
- scanner | 扫描器
-
of
Create scanner with classloader 使用类加载器创建扫描器- Parameters:
classLoader- class loader | 类加载器basePackage- base package | 基础包- Returns:
- scanner | 扫描器
-
includeJars
Set whether to include JAR files 设置是否包含 JAR 文件- Parameters:
include- include JARs | 包含 JAR- Returns:
- this scanner | 此扫描器
-
includeInnerClasses
Set whether to include inner classes 设置是否包含内部类- Parameters:
include- include inner classes | 包含内部类- Returns:
- this scanner | 此扫描器
-
includeNestedJars
Set whether to include nested JARs (e.g. BOOT-INF/lib/ in Spring Boot fat JARs) 设置是否包含嵌套 JAR(如 Spring Boot fat JAR 中的 BOOT-INF/lib/)When enabled, the scanner will discover and scan nested JAR files inside fat JARs (BOOT-INF/lib/, WEB-INF/lib/, lib/) using
NestedJarHandler.启用后,扫描器将使用
NestedJarHandler发现并扫描 fat JAR 内的嵌套 JAR 文件。- Parameters:
include- include nested JARs | 包含嵌套 JAR- Returns:
- this scanner | 此扫描器
-
parallel
Set parallel scanning 设置并行扫描- Parameters:
parallel- enable parallel | 启用并行- Returns:
- this scanner | 此扫描器
-
excludePackage
Add excluded package 添加排除包- Parameters:
packageName- package name | 包名- Returns:
- this scanner | 此扫描器
-
classLoader
Set class loader 设置类加载器- Parameters:
classLoader- class loader | 类加载器- Returns:
- this scanner | 此扫描器
-
cacheDir
Set cache directory for scan result caching 设置扫描结果缓存目录When both cacheDir and cacheKey are configured, scan results will be cached to disk and reused on subsequent scans if the classpath hasn't changed.
当 cacheDir 和 cacheKey 都已配置时,扫描结果将被缓存到磁盘, 如果类路径未变化,后续扫描将复用缓存。
- Parameters:
cacheDir- cache directory path | 缓存目录路径- Returns:
- this scanner | 此扫描器
-
cacheKey
Set cache key (e.g. application version) 设置缓存键(如应用版本号)The cache key is used together with basePackage to form the cache file name.
缓存键与 basePackage 一起构成缓存文件名。
- Parameters:
cacheKey- cache key | 缓存键- Returns:
- this scanner | 此扫描器
-
scan
-
scan
Scan with filter 使用过滤器扫描- Parameters:
filter- scan filter | 扫描过滤器- Returns:
- set of matching classes | 匹配的类集合
-
scanWithAnnotation
Scan for classes with annotation 扫描带注解的类- Parameters:
annotation- annotation class | 注解类- Returns:
- set of annotated classes | 带注解的类集合
-
scanSubTypes
-
scanImplementations
-
stream
-
classNameStream
-