Package: org.codehaus.groovy.classgen

## [Java] Class GeneratorContext

- org.codehaus.groovy.classgen.GeneratorContext

-     public class GeneratorContext
      extends Object

  A context shared across generations of a class and its inner classes.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `GeneratorContext(CompileUnit compileUnit)` Creates a new generator context for the given compile unit.
    `GeneratorContext(CompileUnit compileUnit, int innerClassOffset)` Creates a new generator context with a custom inner class index offset.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static String` | `encodeAsValidClassName(String name)` Encodes a name to be a valid Java class name by replacing special characters with underscores.
    `` | `public CompileUnit` | `getCompileUnit()` Returns the compile unit associated with this context.
    `` | `public String` | `getNextClosureInnerName(ClassNode owner, ClassNode enclosingClass, MethodNode enclosingMethod)` Generates the next unique closure inner class name.
    `` | `public String` | `getNextConstructorReferenceSyntheticMethodName(MethodNode enclosingMethodNode)` Generates a unique synthetic method name for a constructor reference.
    `` | `public int` | `getNextInnerClassIdx()` Returns and increments the inner class index for generating unique inner class names.
    `` | `public String` | `getNextLambdaInnerName(ClassNode owner, ClassNode enclosingClass, MethodNode enclosingMethod)` Generates the next unique lambda inner class name.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### public GeneratorContext(CompileUnit compileUnit)

      Creates a new generator context for the given compile unit.

      Parameters:
        `compileUnit` - the compile unit this context is associated with

    - #### public GeneratorContext(CompileUnit compileUnit, int innerClassOffset)

      Creates a new generator context with a custom inner class index offset.

      Parameters:
        `compileUnit` - the compile unit this context is associated with
        `innerClassOffset` - the starting index for inner class naming

  - ### Method Detail

    - #### public static String encodeAsValidClassName(String name)

      Encodes a name to be a valid Java class name by replacing special characters with underscores. Characters such as operators, punctuation, and other invalid class name characters are encoded. The special names "module-info" and "package-info" are preserved unchanged.

      Parameters:
        `name` - the name to encode
      Returns:
        the encoded class name safe for use as a Java identifier

    - #### public CompileUnit getCompileUnit()

      Returns the compile unit associated with this context.

      Returns:
        the compile unit

    - #### public String getNextClosureInnerName(ClassNode owner, ClassNode enclosingClass, MethodNode enclosingMethod)

      Generates the next unique closure inner class name.

      Parameters:
        `owner` - the owner class (currently unused but kept for API compatibility)
        `enclosingClass` - the class that encloses the closure
        `enclosingMethod` - the method that encloses the closure, or null if at class level
      Returns:
        a unique name for the closure inner class

    - #### public String getNextConstructorReferenceSyntheticMethodName(MethodNode enclosingMethodNode)

      Generates a unique synthetic method name for a constructor reference.

      Parameters:
        `enclosingMethodNode` - the method that contains the constructor reference, or null if at class level
      Returns:
        a unique synthetic method name for the constructor reference

    - #### public int getNextInnerClassIdx()

      Returns and increments the inner class index for generating unique inner class names.

      Returns:
        the next available inner class index

    - #### public String getNextLambdaInnerName(ClassNode owner, ClassNode enclosingClass, MethodNode enclosingMethod)

      Generates the next unique lambda inner class name.

      Parameters:
        `owner` - the owner class (currently unused but kept for API compatibility)
        `enclosingClass` - the class that encloses the lambda
        `enclosingMethod` - the method that encloses the lambda, or null if at class level
      Returns:
        a unique name for the lambda inner class