Class AnnotationMetadata

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

public final class AnnotationMetadata extends Object
Annotation Metadata - Immutable annotation information 注解元数据 - 不可变的注解信息

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

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

Features | 主要功能:

  • Annotation type information - 注解类型信息
  • Annotation attributes access - 注解属性访问
  • Runtime visibility check - 运行时可见性检查

Usage Examples | 使用示例:

AnnotationMetadata annotation = classMetadata.getAnnotation("Service").orElseThrow();
String value = annotation.getAttribute("value", String.class).orElse("");
boolean isRuntime = annotation.isRuntimeVisible();

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:
  • Constructor Details

    • AnnotationMetadata

      public AnnotationMetadata(String annotationType, Map<String,Object> attributes, boolean runtimeVisible)
      Create annotation metadata 创建注解元数据
      Parameters:
      annotationType - annotation type name | 注解类型名称
      attributes - annotation attributes | 注解属性
      runtimeVisible - whether visible at runtime | 是否运行时可见
  • Method Details

    • annotationType

      public String annotationType()
      Get annotation type name 获取注解类型名称
      Returns:
      annotation type name | 注解类型名称
    • attributes

      public Map<String,Object> attributes()
      Get annotation attributes 获取注解属性
      Returns:
      unmodifiable map of attributes | 不可修改的属性映射
    • isRuntimeVisible

      public boolean isRuntimeVisible()
      Check if annotation is visible at runtime 检查注解是否运行时可见
      Returns:
      true if runtime visible | 运行时可见返回 true
    • getAttribute

      public <T> Optional<T> getAttribute(String name, Class<T> type)
      Get attribute value with type 获取指定类型的属性值
      Type Parameters:
      T - type parameter | 类型参数
      Parameters:
      name - attribute name | 属性名
      type - expected type | 期望类型
      Returns:
      optional attribute value | 可选的属性值
    • getAttribute

      public <T> T getAttribute(String name, Class<T> type, T defaultValue)
      Get attribute value with type and default 获取指定类型的属性值,带默认值
      Type Parameters:
      T - type parameter | 类型参数
      Parameters:
      name - attribute name | 属性名
      type - expected type | 期望类型
      defaultValue - default value | 默认值
      Returns:
      attribute value or default | 属性值或默认值
    • getValue

      public Optional<Object> getValue()
      Get 'value' attribute 获取 'value' 属性
      Returns:
      optional value | 可选的值
    • getStringValue

      public Optional<String> getStringValue()
      Get 'value' attribute as String 获取 'value' 属性作为字符串
      Returns:
      optional string value | 可选的字符串值
    • hasAttribute

      public boolean hasAttribute(String name)
      Check if attribute exists 检查属性是否存在
      Parameters:
      name - attribute name | 属性名
      Returns:
      true if exists | 存在返回 true
    • getAttributeNames

      public Set<String> getAttributeNames()
      Get all attribute names 获取所有属性名
      Returns:
      set of attribute names | 属性名集合
    • getSimpleName

      public String getSimpleName()
      Get simple type name (without package) 获取简单类型名(不含包名)
      Returns:
      simple name | 简单名称
    • 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