Interface Synthetic

All Superinterfaces:
AnnotatedElement, Annotation
All Known Implementing Classes:
SyntheticMeta

public interface Synthetic extends Annotation, AnnotatedElement
表示基于特定规则聚合的一组注解对象

合成注解一般被用于处理类层级结果中具有直接或间接关联的注解对象, 当实例被创建时,会获取到这些注解对象,并使用SynthesizedSelector对类型相同的注解进行过滤, 并最终得到类型不重复的有效注解对象这些有效注解将被包装为Synthesized, 然后最终用于“合成”一个Synthesized

合成注解可以作为一个特殊的Annotation或者AnnotatedElement, 当调用Annotation的方法时,应当返回当前实例本身的有效信息, 而当调用AnnotatedElement的方法时,应当返回用于合成该对象的相关注解的信息

合成注解允许通过syntheticAnnotation(Class)合成一个指定的注解对象, 该方法返回的注解对象可能是原始的注解对象,也有可能通过动态代理的方式生成, 该对象实例的属性不一定来自对象本身,而是来自于经过SynthesizedProcessor 处理后的、用于合成当前实例的全部关联注解的相关属性

Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • of

      static <T extends Annotation> Synthetic of(T rootAnnotation)
      基于指定根注解,构建包括其元注解在内的合成注解
      Type Parameters:
      T - 注解类型
      Parameters:
      rootAnnotation - 根注解
      Returns:
      合成注解
    • getAnnotationSelector

      SynthesizedSelector getAnnotationSelector()
      获取合成注解选择器
      Returns:
      合成注解选择器
    • getAttributeProcessor

      SynthesizedProcessor getAttributeProcessor()
      获取合成注解属性处理器
      Returns:
      合成注解属性处理器
    • getSynthesizedAnnotation

      Synthesized getSynthesizedAnnotation(Class<?> annotationType)
      获取已合成的注解
      Parameters:
      annotationType - 注解类型
      Returns:
      已合成的注解
    • annotationType

      default Class<? extends Annotation> annotationType()
      获取当前的注解类型
      Specified by:
      annotationType in interface Annotation
      Returns:
      注解类型
    • getAnnotation

      <T extends Annotation> T getAnnotation(Class<T> annotationType)
      获取指定注解对象
      Specified by:
      getAnnotation in interface AnnotatedElement
      Type Parameters:
      T - 注解类型
      Parameters:
      annotationType - 注解类型
      Returns:
      注解对象
    • isAnnotationPresent

      boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
      是否存在指定注解
      Specified by:
      isAnnotationPresent in interface AnnotatedElement
      Parameters:
      annotationType - 注解类型
      Returns:
      是否
    • getAnnotations

      Annotation[] getAnnotations()
      获取全部注解
      Specified by:
      getAnnotations in interface AnnotatedElement
      Returns:
      注解对象
    • syntheticAnnotation

      <T extends Annotation> T syntheticAnnotation(Class<T> annotationType)
      获取合成注解
      Type Parameters:
      T - 注解类型
      Parameters:
      annotationType - 注解类型
      Returns:
      类型
    • getAttribute

      Object getAttribute(String attributeName, Class<?> attributeType)
      获取属性值
      Parameters:
      attributeName - 属性名称
      attributeType - 属性类型
      Returns:
      属性值