Class ClassMetadata

java.lang.Object
cloud.opencode.base.classloader.metadata.ClassMetadata

public final class ClassMetadata extends Object
Class Metadata - Immutable class information 类元数据 - 不可变的类信息

Represents class metadata read from class files without loading the class.

表示从类文件读取的类元数据,无需加载类。

Features | 主要功能:

  • Class hierarchy information - 类层次信息
  • Method and field metadata - 方法和字段元数据
  • Annotation metadata - 注解元数据
  • Type information (interface, abstract, enum, record, sealed) - 类型信息

Usage Examples | 使用示例:

ClassMetadata metadata = OpenMetadata.read("com.example.MyClass");
String className = metadata.className();
boolean hasService = metadata.hasAnnotation("org.springframework.stereotype.Service");
List<MethodMetadata> methods = metadata.methods();

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是 (不可变)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-classloader V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • className

      public String className()
      Get fully qualified class name 获取完全限定类名
      Returns:
      class name | 类名
    • packageName

      public String packageName()
      Get package name 获取包名
      Returns:
      package name | 包名
    • simpleName

      public String simpleName()
      Get simple class name 获取简单类名
      Returns:
      simple name | 简单名称
    • superClassName

      public String superClassName()
      Get super class name 获取父类名
      Returns:
      super class name or null | 父类名或 null
    • interfaceNames

      public List<String> interfaceNames()
      Get interface names 获取接口名列表
      Returns:
      list of interface names | 接口名列表
    • modifiers

      public int modifiers()
      Get modifiers 获取修饰符
      Returns:
      modifier flags | 修饰符标志
    • isInterface

      public boolean isInterface()
      Check if interface 检查是否为接口
      Returns:
      true if interface | 是接口返回 true
    • isAbstract

      public boolean isAbstract()
      Check if abstract 检查是否为抽象类
      Returns:
      true if abstract | 是抽象类返回 true
    • isAnnotation

      public boolean isAnnotation()
      Check if annotation 检查是否为注解
      Returns:
      true if annotation | 是注解返回 true
    • isEnum

      public boolean isEnum()
      Check if enum 检查是否为枚举
      Returns:
      true if enum | 是枚举返回 true
    • isRecord

      public boolean isRecord()
      Check if record 检查是否为 Record
      Returns:
      true if record | 是 Record 返回 true
    • isSealed

      public boolean isSealed()
      Check if sealed 检查是否为密封类
      Returns:
      true if sealed | 是密封类返回 true
    • isFinal

      public boolean isFinal()
      Check if final 检查是否为 final
      Returns:
      true if final | 是 final 返回 true
    • permittedSubclasses

      public List<String> permittedSubclasses()
      Get permitted subclasses (for sealed types) 获取允许的子类(用于密封类型)
      Returns:
      list of permitted subclass names | 允许的子类名列表
    • methods

      public List<MethodMetadata> methods()
      Get methods 获取方法列表
      Returns:
      list of method metadata | 方法元数据列表
    • fields

      public List<FieldMetadata> fields()
      Get fields 获取字段列表
      Returns:
      list of field metadata | 字段元数据列表
    • annotations

      public List<AnnotationMetadata> annotations()
      Get annotations 获取注解列表
      Returns:
      list of annotation metadata | 注解元数据列表
    • sourceFile

      public String sourceFile()
      Get source file name 获取源文件名
      Returns:
      source file name or null | 源文件名或 null
    • getGenericSignature

      public String getGenericSignature()
      Get generic signature of the class 获取类的泛型签名
      Returns:
      generic signature or null if not generic | 泛型签名,非泛型类返回 null
    • getTypeParameters

      public List<String> getTypeParameters()
      Get type parameters of the class 获取类的类型参数列表
      Returns:
      list of type parameter strings (e.g. ["T", "K extends Comparable<K>"]) | 类型参数字符串列表
    • getRecordComponents

      public List<RecordComponentMetadata> getRecordComponents()
      Get record components (empty list if not a record) 获取 Record 组件列表(非 Record 类返回空列表)
      Returns:
      list of record component metadata | Record 组件元数据列表
    • hasTypeParameters

      public boolean hasTypeParameters()
      Check if the class has type parameters 检查类是否有类型参数
      Returns:
      true if has type parameters | 有类型参数返回 true
    • hasAnnotation

      public boolean hasAnnotation(String annotationClassName)
      Check if has specified annotation by class name 检查是否有指定注解(按类名)
      Parameters:
      annotationClassName - annotation class name | 注解类名
      Returns:
      true if has annotation | 有注解返回 true
    • hasAnnotation

      public boolean hasAnnotation(Class<? extends Annotation> annotationClass)
      Check if has specified annotation 检查是否有指定注解
      Parameters:
      annotationClass - annotation class | 注解类
      Returns:
      true if has annotation | 有注解返回 true
    • getAnnotation

      public Optional<AnnotationMetadata> getAnnotation(String annotationClassName)
      Get specified annotation 获取指定注解
      Parameters:
      annotationClassName - annotation class name | 注解类名
      Returns:
      optional annotation | 可选的注解
    • isSubTypeOf

      public boolean isSubTypeOf(String className)
      Check if is subtype of specified class 检查是否为指定类的子类型
      Parameters:
      className - class name | 类名
      Returns:
      true if is subtype | 是子类型返回 true
    • getMethodNames

      public List<String> getMethodNames()
      Get all method names 获取所有方法名
      Returns:
      list of method names | 方法名列表
    • getFieldNames

      public List<String> getFieldNames()
      Get all field names 获取所有字段名
      Returns:
      list of field names | 字段名列表
    • isConcrete

      public boolean isConcrete()
      Check if is concrete class (not abstract and not interface) 检查是否为具体类(非抽象非接口)
      Returns:
      true if concrete | 是具体类返回 true
    • isInnerClass

      public boolean isInnerClass()
      Check if is inner class 检查是否为内部类
      Returns:
      true if inner class | 是内部类返回 true
    • getOuterClassName

      public Optional<String> getOuterClassName()
      Get outer class name if inner class 获取外部类名(如果是内部类)
      Returns:
      optional outer class name | 可选的外部类名
    • getMethodsByName

      public List<MethodMetadata> getMethodsByName(String methodName)
      Get method by name 按名称获取方法
      Parameters:
      methodName - method name | 方法名
      Returns:
      list of methods with the name | 具有该名称的方法列表
    • getField

      public Optional<FieldMetadata> getField(String fieldName)
      Get field by name 按名称获取字段
      Parameters:
      fieldName - field name | 字段名
      Returns:
      optional field | 可选的字段
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static ClassMetadata.Builder builder()
      Create builder 创建构建器
      Returns:
      new builder | 新构建器