Package org.codehaus.groovy.classgen
Class GeneratorContext
java.lang.Object
org.codehaus.groovy.classgen.GeneratorContext
A context shared across generations of a class and its inner classes.
-
Constructor Summary
ConstructorsConstructorDescriptionGeneratorContext(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. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringencodeAsValidClassName(String name) Encodes a name to be a valid Java class name by replacing special characters with underscores.Returns the compile unit associated with this context.getNextClosureInnerName(ClassNode owner, ClassNode enclosingClass, MethodNode enclosingMethod) Generates the next unique closure inner class name.getNextConstructorReferenceSyntheticMethodName(MethodNode enclosingMethodNode) Generates a unique synthetic method name for a constructor reference.intReturns and increments the inner class index for generating unique inner class names.getNextLambdaInnerName(ClassNode owner, ClassNode enclosingClass, MethodNode enclosingMethod) Generates the next unique lambda inner class name.
-
Constructor Details
-
GeneratorContext
Creates a new generator context for the given compile unit.- Parameters:
compileUnit- the compile unit this context is associated with
-
GeneratorContext
Creates a new generator context with a custom inner class index offset.- Parameters:
compileUnit- the compile unit this context is associated withinnerClassOffset- 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
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 closureenclosingMethod- 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 lambdaenclosingMethod- the method that encloses the lambda, or null if at class level- Returns:
- a unique name for the lambda inner class
-
getNextConstructorReferenceSyntheticMethodName
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
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
-