Class IntersectionTypeClassNode

All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>, NodeMetaDataHandler

public final class IntersectionTypeClassNode extends ClassNode
Represents a user-written intersection type used as the target of a cast expression or as coercion, e.g.
     (Runnable & Serializable) () -> ...
     value as (A & B)
 

Distinct from the implicit lowest-upper-bound nodes that StaticTypeCheckingVisitor synthesizes during inference: an instance of this class records the ordered list of components exactly as written by the user. That ordering is needed for cast-conversion checks, error messages and (in later phases) bytecode generation via LambdaMetafactory.altMetafactory markers.

Lifecycle: at parse time the components have not yet been resolved to bound ClassNodes, so the constructor places all components in the inherited interfaces array with Object as the placeholder superclass. After ResolveVisitor resolves each component it should call reclassifyComponents() so that the interfaces array contains only interface components and the superclass is the (at most one) class component.

Since:
6.0.0
  • Constructor Details

    • IntersectionTypeClassNode

      public IntersectionTypeClassNode(ClassNode[] components)
  • Method Details

    • getComponents

      public ClassNode[] getComponents()
      Returns the components of this intersection type in user-written order.
    • reclassifyComponents

      public void reclassifyComponents()
      Reclassifies the components after resolution: separates the (at most one) class component from the interface components and updates the inherited superclass and interfaces accordingly. Components are resolved in place — callers do not need to substitute new instances.
    • getText

      public String getText()
      Description copied from class: ASTNode
      Returns a human-readable text representation of this AST node. Used for debugging and error messages. Default implementation returns a message indicating the representation is not yet implemented for this node type.
      Overrides:
      getText in class ClassNode
      Returns:
      text representation of this node, or placeholder for unimplemented types
    • toString

      public String toString(boolean showRedirect)
      Description copied from class: ClassNode
      Returns a string representation of this ClassNode with optional redirect information. For array types, appends "[]" to the component type's string representation. For generic types, includes generic type parameters (e.g., "List"). If showRedirect is true and this is a redirect node, includes arrow notation showing the redirect target; otherwise the redirect information is omitted.
      Overrides:
      toString in class ClassNode
      Parameters:
      showRedirect - if true, includes redirect information in the output; if false, omits it
      Returns:
      a string representation of this ClassNode