Class TypeHierarchy

java.lang.Object
io.helidon.codegen.TypeHierarchy

public final class TypeHierarchy extends Object
Utilities for type hierarchy.
  • Method Details

    • hierarchyAnnotations

      public static List<Annotation> hierarchyAnnotations(CodegenContext ctx, TypeInfo type)
      Find all annotations on the whole type hierarchy. Adds all annotations on the provided type, and all Inherited annotations on supertype(s) and/or interface(s).
      Parameters:
      ctx - codegen context
      type - type info to process
      Returns:
      all annotations on the type and in its hierarchy
    • hierarchyAnnotations

      public static List<Annotation> hierarchyAnnotations(CodegenContext ctx, TypeInfo type, TypedElementInfo element)
      Find all annotations on the whole type hierarchy. Adds all annotations on the provided element, and all Inherited annotations on the same element from supertype(s), and/or interfaces, and/or annotations.

      Based on element type:

      If the same annotation is on multiple levels (i.e. method, super type method, and interface), it will always be used ONLY from the "closest" type - order is: this element, super type element, interface element.
      Parameters:
      ctx - codegen context
      type - type info owning the executable
      element - executable (method or constructor) element info
      Returns:
      all annotations on the type and in its hierarchy
    • hierarchyAnnotations

      public static List<Annotation> hierarchyAnnotations(CodegenContext ctx, TypeInfo type, TypedElementInfo executable, TypedElementInfo parameter, int parameterIndex)
      Annotations of a parameter, taken from the full inheritance hierarchy (super type(s), interface(s).
      Parameters:
      ctx - codegen context to obtain TypeInfo of types
      type - type info of the processed type
      executable - owner of the parameter (constructor or method)
      parameter - parameter info itself
      parameterIndex - index of the parameter within the method (as names may be wrong at runtime)
      Returns:
      list of annotations on this parameter on this type, super type(s), and interface methods it implements
    • nestedAnnotations

      public static Set<TypeName> nestedAnnotations(CodegenContext ctx, TypeInfo typeInfo)
      Annotations on the typeInfo, its methods, method parameters, and the type-use positions nested in their TypeNames.

      Type-use positions include type arguments, wildcard bounds, and array component types of the type itself, element return or field types, and parameter types.

      Parameters:
      ctx - context
      typeInfo - type info to check
      Returns:
      a set of all annotation types on any of the elements, including inherited annotations
    • mergeHierarchyAnnotations

      public static TypedElementInfo mergeHierarchyAnnotations(TypeInfo type, TypedElementInfo element)
      Merge method and parameter annotations, and return and parameter type-use annotations, from overridden methods and interface methods into the provided method element. Non-method elements are returned unchanged.

      When the same annotation type exists on both the target method and an inherited method, the target method annotation is preserved. Type-use annotations are merged using mergeTypeNameAnnotations(TypeName, TypeName).

      Parameters:
      type - type declaring the element
      element - element to merge
      Returns:
      element with matching hierarchy annotations merged in
    • typeNameAnnotations

      public static List<Annotation> typeNameAnnotations(TypeName typeName)
      Annotation instances nested inside a type name. This includes annotations declared directly on the provided type name and annotations declared on nested type arguments, wildcard bounds, and array component types.
      Parameters:
      typeName - type name to scan
      Returns:
      nested annotation instances
    • mergeTypeNameAnnotations

      public static TypeName mergeTypeNameAnnotations(TypeName typeName, TypeName sourceTypeName)
      Merge type-use annotations from a source type name into a target type name. If the type names do not have the same structure, the target type name is returned unchanged.

      Matching type names merge direct and inherited annotations on the root type, type arguments, wildcard bounds, and array component types. When both type names contain the same annotation type at a matching position, the target annotation is preserved. Formal type parameter names do not block merging.

      Parameters:
      typeName - target type name
      sourceTypeName - source type name
      Returns:
      type name with annotations merged from the source