Class GeneratorContext

java.lang.Object
org.codehaus.groovy.classgen.GeneratorContext

public class GeneratorContext extends Object
A context shared across generations of a class and its inner classes.
  • Constructor Details

    • GeneratorContext

      public GeneratorContext(CompileUnit compileUnit)
      Creates a new generator context for the given compile unit.
      Parameters:
      compileUnit - the compile unit this context is associated with
    • GeneratorContext

      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 Details

    • getNextInnerClassIdx

      public int getNextInnerClassIdx()
      Returns and increments the inner class index for generating unique inner class names.
      Returns:
      the next available inner class index
    • getCompileUnit

      public CompileUnit getCompileUnit()
      Returns the compile unit associated with this context.
      Returns:
      the compile unit
    • getNextClosureInnerName

      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
    • getNextLambdaInnerName

      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
    • getNextConstructorReferenceSyntheticMethodName

      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
    • encodeAsValidClassName

      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