Class AnnotationScanner

java.lang.Object
cloud.opencode.base.classloader.scanner.AnnotationScanner

public class AnnotationScanner extends Object
Annotation Scanner - Scans for annotated elements 注解扫描器 - 扫描带注解的元素

Scans classes, methods, fields and constructors for annotations.

扫描类、方法、字段和构造器上的注解。

Features | 主要功能:

  • Scan annotated classes - 扫描带注解的类
  • Scan annotated methods - 扫描带注解的方法
  • Scan annotated fields - 扫描带注解的字段
  • Scan meta-annotations - 扫描元注解

Usage Examples | 使用示例:

AnnotationScanner scanner = AnnotationScanner.of("com.example");
Set<Class<?>> services = scanner.scanClasses(Service.class);
Set<Method> getMappings = scanner.scanMethods(GetMapping.class);

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 Details

    • of

      public static AnnotationScanner of(String basePackage)
      Create annotation scanner 创建注解扫描器
      Parameters:
      basePackage - base package | 基础包
      Returns:
      scanner | 扫描器
    • classLoader

      public AnnotationScanner classLoader(ClassLoader classLoader)
      Set class loader 设置类加载器
      Parameters:
      classLoader - class loader | 类加载器
      Returns:
      this scanner | 此扫描器
    • includeInnerClasses

      public AnnotationScanner includeInnerClasses(boolean include)
      Include inner classes 包含内部类
      Parameters:
      include - include inner classes | 包含内部类
      Returns:
      this scanner | 此扫描器
    • scanClasses

      public Set<Class<?>> scanClasses(Class<? extends Annotation> annotation)
      Scan classes with annotation 扫描带注解的类
      Parameters:
      annotation - annotation class | 注解类
      Returns:
      set of annotated classes | 带注解的类集合
    • scanMethods

      public Set<Method> scanMethods(Class<? extends Annotation> annotation)
      Scan methods with annotation 扫描带注解的方法
      Parameters:
      annotation - annotation class | 注解类
      Returns:
      set of annotated methods | 带注解的方法集合
    • scanFields

      public Set<Field> scanFields(Class<? extends Annotation> annotation)
      Scan fields with annotation 扫描带注解的字段
      Parameters:
      annotation - annotation class | 注解类
      Returns:
      set of annotated fields | 带注解的字段集合
    • scanConstructors

      public Set<Constructor<?>> scanConstructors(Class<? extends Annotation> annotation)
      Scan constructors with annotation 扫描带注解的构造器
      Parameters:
      annotation - annotation class | 注解类
      Returns:
      set of annotated constructors | 带注解的构造器集合
    • scanMetaAnnotated

      public Set<Class<?>> scanMetaAnnotated(Class<? extends Annotation> metaAnnotation)
      Scan classes with meta-annotation (annotation's annotation) 扫描带元注解(注解的注解)的类
      Parameters:
      metaAnnotation - meta-annotation class | 元注解类
      Returns:
      set of classes with annotations that have the meta-annotation | 带有元注解的注解的类集合
    • scanParameters

      public Map<Method, List<Integer>> scanParameters(Class<? extends Annotation> annotation)
      Scan parameters with annotation 扫描带注解的参数
      Parameters:
      annotation - annotation class | 注解类
      Returns:
      map of method to annotated parameter indices | 方法到带注解参数索引的映射
    • scanClassesWithAnnotatedMethods

      public Set<Class<?>> scanClassesWithAnnotatedMethods(Class<? extends Annotation> annotation)
      Find all classes that have any method with the given annotation 查找所有拥有带指定注解方法的类
      Parameters:
      annotation - annotation class | 注解类
      Returns:
      set of classes | 类集合
    • scanClassesWithAnnotatedFields

      public Set<Class<?>> scanClassesWithAnnotatedFields(Class<? extends Annotation> annotation)
      Find all classes that have any field with the given annotation 查找所有拥有带指定注解字段的类
      Parameters:
      annotation - annotation class | 注解类
      Returns:
      set of classes | 类集合