Class InnerClassNode

All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>, NodeMetaDataHandler
Direct Known Subclasses:
EnumConstantClassNode, InterfaceHelperClassNode

public class InnerClassNode extends ClassNode
Represents a nested (inner) class definition within an outer class. Inner classes maintain a reference to their enclosing ClassNode and support Groovy-specific features such as variable scoping and anonymous class detection. Automatically marks inner classes as static when defined in interfaces per JLS specifications.
See Also:
  • Constructor Details

    • InnerClassNode

      public InnerClassNode(ClassNode outerClass, String name, int modifiers, ClassNode superClass)
      Creates an inner class with the specified outer class, name, modifiers, and superclass.
      Parameters:
      outerClass - the enclosing class, or null for top-level classes
      name - the fully qualified name of the inner class
      modifiers - the org.objectweb.asm.Opcodes modifiers for this class
      superClass - the superclass of this inner class, or ClassNode.EMPTY_ARRAY for Object
      See Also:
      • Opcodes
    • InnerClassNode

      public InnerClassNode(ClassNode outerClass, String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins)
      Creates an inner class with the specified outer class, name, modifiers, superclass, interfaces, and mixins. If the outer class is an interface, the inner class is automatically marked as static.
      Parameters:
      outerClass - the enclosing class, or null for top-level classes
      name - the fully qualified name of the inner class
      modifiers - the org.objectweb.asm.Opcodes modifiers for this class
      superClass - the superclass of this inner class
      interfaces - the interfaces implemented by this inner class
      mixins - the mixins applied to this inner class
      See Also:
      • Opcodes
  • Method Details

    • getOuterClass

      public ClassNode getOuterClass()
      Returns the class that encloses this inner class, or null if this is a top-level class.
      Overrides:
      getOuterClass in class ClassNode
      Returns:
      the enclosing ClassNode, or null
      See Also:
    • getOuterMostClass

      public ClassNode getOuterMostClass()
      Returns the outermost class in the nesting hierarchy by recursively traversing outer class references until reaching a class that has no outer class.
      Returns:
      the topmost ClassNode in the nesting chain
    • getOuterField

      public FieldNode getOuterField(String name)
      Retrieves a field from the enclosing class by name, enabling access to outer class fields from within the inner class scope.
      Overrides:
      getOuterField in class ClassNode
      Parameters:
      name - the field name to retrieve from the outer class
      Returns:
      the FieldNode from the outer class, or null if not found
      See Also:
    • getVariableScope

      public VariableScope getVariableScope()
      Returns the variable scope associated with this inner class, tracking declarations and references for closure and method boundary analysis.
      Returns:
      the VariableScope, or null if not set
      See Also:
    • setVariableScope

      public void setVariableScope(VariableScope scope)
      Sets the variable scope that manages variables declared and referenced within this inner class.
      Parameters:
      scope - the VariableScope to associate with this inner class
    • isSealed

      public boolean isSealed()
      Checks if this inner class is sealed per JLS 15.9.5, returning false for anonymous classes since they cannot be further subclassed.
      Overrides:
      isSealed in class ClassNode
      Returns:
      true if this inner class is sealed and not anonymous
    • isAnonymous

      public boolean isAnonymous()
      Returns whether this inner class represents an anonymous class (created with inline expressions).
      Returns:
      true if this is an anonymous inner class
    • setAnonymous

      public void setAnonymous(boolean anonymous)
      Marks this inner class as anonymous if not already set. Anonymous classes have restricted modifiers: static and abstract modifiers are removed, and final is removed for enums per JLS 15.9.5. Once set to anonymous, this state cannot be reverted.
      Parameters:
      anonymous - true to mark this inner class as anonymous
      Throws:
      IllegalArgumentException - if attempting to demote from anonymous to non-anonymous