Class ClassMetadata
java.lang.Object
cloud.opencode.base.classloader.metadata.ClassMetadata
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for ClassMetadata ClassMetadata 构建器 -
Method Summary
Modifier and TypeMethodDescriptionGet annotations 获取注解列表static ClassMetadata.Builderbuilder()Create builder 创建构建器Get fully qualified class name 获取完全限定类名booleanfields()Get fields 获取字段列表getAnnotation(String annotationClassName) Get specified annotation 获取指定注解Get field by name 按名称获取字段Get all field names 获取所有字段名Get generic signature of the class 获取类的泛型签名Get all method names 获取所有方法名getMethodsByName(String methodName) Get method by name 按名称获取方法Get outer class name if inner class 获取外部类名(如果是内部类)Get record components (empty list if not a record) 获取 Record 组件列表(非 Record 类返回空列表)Get type parameters of the class 获取类的类型参数列表booleanhasAnnotation(Class<? extends Annotation> annotationClass) Check if has specified annotation 检查是否有指定注解booleanhasAnnotation(String annotationClassName) Check if has specified annotation by class name 检查是否有指定注解(按类名)inthashCode()booleanCheck if the class has type parameters 检查类是否有类型参数Get interface names 获取接口名列表booleanCheck if abstract 检查是否为抽象类booleanCheck if annotation 检查是否为注解booleanCheck if is concrete class (not abstract and not interface) 检查是否为具体类(非抽象非接口)booleanisEnum()Check if enum 检查是否为枚举booleanisFinal()Check if final 检查是否为 finalbooleanCheck if is inner class 检查是否为内部类booleanCheck if interface 检查是否为接口booleanisRecord()Check if record 检查是否为 RecordbooleanisSealed()Check if sealed 检查是否为密封类booleanisSubTypeOf(String className) Check if is subtype of specified class 检查是否为指定类的子类型methods()Get methods 获取方法列表intGet modifiers 获取修饰符Get package name 获取包名Get permitted subclasses (for sealed types) 获取允许的子类(用于密封类型)Get simple class name 获取简单类名Get source file name 获取源文件名Get super class name 获取父类名toString()
-
Method Details
-
className
-
packageName
-
simpleName
-
superClassName
Get super class name 获取父类名- Returns:
- super class name or null | 父类名或 null
-
interfaceNames
-
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
-
methods
-
fields
-
annotations
Get annotations 获取注解列表- Returns:
- list of annotation metadata | 注解元数据列表
-
sourceFile
Get source file name 获取源文件名- Returns:
- source file name or null | 源文件名或 null
-
getGenericSignature
Get generic signature of the class 获取类的泛型签名- Returns:
- generic signature or null if not generic | 泛型签名,非泛型类返回 null
-
getTypeParameters
-
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
Check if has specified annotation by class name 检查是否有指定注解(按类名)- Parameters:
annotationClassName- annotation class name | 注解类名- Returns:
- true if has annotation | 有注解返回 true
-
hasAnnotation
Check if has specified annotation 检查是否有指定注解- Parameters:
annotationClass- annotation class | 注解类- Returns:
- true if has annotation | 有注解返回 true
-
getAnnotation
Get specified annotation 获取指定注解- Parameters:
annotationClassName- annotation class name | 注解类名- Returns:
- optional annotation | 可选的注解
-
isSubTypeOf
Check if is subtype of specified class 检查是否为指定类的子类型- Parameters:
className- class name | 类名- Returns:
- true if is subtype | 是子类型返回 true
-
getMethodNames
-
getFieldNames
-
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
-
getMethodsByName
Get method by name 按名称获取方法- Parameters:
methodName- method name | 方法名- Returns:
- list of methods with the name | 具有该名称的方法列表
-
getField
Get field by name 按名称获取字段- Parameters:
fieldName- field name | 字段名- Returns:
- optional field | 可选的字段
-
equals
-
hashCode
-
toString
-
builder
-