Package: org.codehaus.groovy.classgen.asm.sc

## [Java] Class StaticTypesWriterController

- org.codehaus.groovy.classgen.asm.sc.StaticTypesWriterController

-     public class StaticTypesWriterController
      extends DelegatingController

  An alternative WriterController which handles static types and method dispatch. In case of a "mixed mode" where only some methods are annotated with TypeChecked then this writer will delegate to the classic writer controller.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected boolean` | `isInStaticallyCheckedMethod` | Tracks whether the current member is being emitted through the static-compilation fast path.

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class WriterController` | `optimizeForInt`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `StaticTypesWriterController(WriterController controller)` Creates a delegating writer controller that switches between dynamic and static code-generation strategies.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public BinaryExpressionHelper` | `getBinaryExpressionHelper()` * * Returns the appropriate BinaryExpressionHelper for the current code path. * Selects fast-path specialized handling when isFastPath() is true, * otherwise delegates to the general-purpose binary expression handler. * Fast-path optimization is controlled by optimizeForInt. * * Returns: the binary expression writer for the active compilation mode
    `` | `public CallSiteWriter` | `getCallSiteWriter()` * * Returns the CallSiteWriter responsible for generating dynamic call site * infrastructure. Behavior depends on bytecode strategy: either invokedynamic * for modern JVMs or traditional call-site caching for broader compatibility.
    `` | `public CallSiteWriter` | `getCallSiteWriterFor(Expression expression)` * * Returns the CallSiteWriter for a specific expression. * Currently delegates to the default CallSiteWriter; reserved for * future expression-specific optimization strategies. * * Parameters: `expression` - the expression being processed * Returns: the appropriate call site writer for this expression * * Since: 6.0.0
    `` | `public ClosureWriter` | `getClosureWriter()` * * Returns the ClosureWriter for compiling Groovy closure literals into * inner classes implementing GroovyObject and supporting variable capture.
    `` | `public InvocationWriter` | `getInvocationWriter()` * * Returns the InvocationWriter for compiling method calls and dynamic * function invocations into appropriate bytecode patterns.
    `` | `public LambdaWriter` | `getLambdaWriter()` * * Returns the LambdaWriter for compiling Java-style lambda expressions * (using the `->` operator) into functional interfaces.
    `` | `public MethodReferenceExpressionWriter` | `getMethodReferenceExpressionWriter()` * * Returns the MethodReferenceExpressionWriter for compiling method reference * expressions compatible with Java functional interface targets.
    `` | `public CallSiteWriter` | `getRegularCallSiteWriter()` Returns the regular dynamic call-site writer used for fallback expressions.
    `` | `public InvocationWriter` | `getRegularInvocationWriter()` Returns the regular dynamic invocation writer used for fallback expressions.
    `` | `public StatementWriter` | `getStatementWriter()` * * Returns the StatementWriter for compiling Groovy statements into bytecode. * Selection depends on optimization mode: OptimizingStatementWriter for * optimizeForInt, otherwise generic StatementWriter.
    `` | `public TypeChooser` | `getTypeChooser()` * * Returns the TypeChooser used to select appropriate type representations * for expressions during compilation, supporting both dynamic and typed paths.
    `` | `public UnaryExpressionHelper` | `getUnaryExpressionHelper()` * * Returns the appropriate UnaryExpressionHelper for the current code path. * Selects fast-path specialized handling when isFastPath() is true, * otherwise delegates to the general-purpose unary expression handler. * Fast-path optimization is controlled by optimizeForInt. * * Returns: the unary expression writer for the active compilation mode
    `` | `public void` | `init(AsmClassGenerator asmClassGenerator, GeneratorContext gcon, org.objectweb.asm.ClassVisitor cv, ClassNode cn)` * * Initializes this controller with compilation context and ASM infrastructure. * Must be called exactly once before any bytecode generation operations. * Sets up all supporting writers (call site, closure, lambda, etc.) and * configures optimization strategies based on compiler configuration. * * Parameters: `asmClassGenerator` - the class generator managing the overall compilation * `gcon` - the compilation context tracking state across the compilation unit * `cv` - the ASM ClassVisitor for emitting bytecode directives * `cn` - the ClassNode being compiled
    `` | `public boolean` | `isFastPath()` * * Returns true if the compiler is currently in fast-path mode, * emitting specialized bytecode for primitive type operations. * Use this to determine whether expression helpers should apply optimizations. * * Returns: true if fast-path compilation mode is active
    `` | `public boolean` | `methodHasDynamicResolution()` GROOVY-11968: returns `true` when the current statically compiled method contains one or more sub-expressions that will be routed through the regular (non-static) call site writer via getCallSiteWriterFor.
    `` | `public void` | `setConstructorNode(ConstructorNode cn)` * * Sets the ConstructorNode for the constructor currently being compiled. * Automatically clears any active method node, since only one can be active. * Used during compilation to track which constructor's bytecode is being generated. * * Parameters: `constructorNode` - the ConstructorNode to compile, or null to deactivate
    `` | `public void` | `setMethodNode(MethodNode mn)` * * Sets the MethodNode for the method currently being compiled. * Automatically clears any active constructor node, since only one can be active. * Used during compilation to track which method's bytecode is being generated. * * Parameters: `methodNode` - the MethodNode to compile, or null to deactivate

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class DelegatingController` | `getAcg, getAssertionWriter, getBinaryExpressionHelper, getBytecodeVersion, getCallSiteWriter, getCallSiteWriterFor, getClassName, getClassNode, getClassVisitor, getClosureWriter, getCompileStack, getConstructorNode, getContext, getCv, getInterfaceClassLoadingClass, getInternalBaseClassName, getInternalClassName, getInvocationWriter, getLambdaWriter, getLineNumber, getMethodNode, getMethodPointerExpressionWriter, getMethodReferenceExpressionWriter, getMethodVisitor, getOperandStack, getOutermostClass, getReturnType, getSourceUnit, getStatementWriter, getTypeChooser, getUnaryExpressionHelper, init, isConstructor, isFastPath, isInGeneratedFunction, isInGeneratedFunctionConstructor, isInScriptBody, isNotClinit, isStaticConstructor, isStaticContext, isStaticMethod, resetLineNumber, setConstructorNode, setInterfaceClassLoadingClass, setLineNumber, setMethodNode, setMethodVisitor, shouldOptimizeForInt, switchToFastPath, switchToSlowPath`
    `class WriterController` | `getAcg, getAssertionWriter, getBinaryExpressionHelper, getBytecodeVersion, getCallSiteWriter, getCallSiteWriterFor, getClassName, getClassNode, getClassVisitor, getClosureWriter, getCompileStack, getConstructorNode, getContext, getCv, getInterfaceClassLoadingClass, getInternalBaseClassName, getInternalClassName, getInvocationWriter, getLambdaWriter, getLineNumber, getMethodNode, getMethodPointerExpressionWriter, getMethodReferenceExpressionWriter, getMethodVisitor, getNextHelperMethodIndex, getOperandStack, getOutermostClass, getReturnType, getSourceUnit, getStatementWriter, getSuperMethodNames, getThisType, getTypeChooser, getUnaryExpressionHelper, init, isConstructor, isFastPath, isInGeneratedFunction, isInGeneratedFunctionConstructor, isInScriptBody, isNotClinit, isStaticConstructor, isStaticContext, isStaticMethod, resetLineNumber, setConstructorNode, setInterfaceClassLoadingClass, setLineNumber, setMethodNode, setMethodVisitor, shouldOptimizeForInt, switchToFastPath, switchToSlowPath, visitLineNumber`

- - ### Field Detail

    - #### protected boolean isInStaticallyCheckedMethod

      Tracks whether the current member is being emitted through the static-compilation fast path.

  - ### Constructor Detail

    - #### public StaticTypesWriterController(WriterController controller)

      Creates a delegating writer controller that switches between dynamic and static code-generation strategies.

  - ### Method Detail

    - #### public BinaryExpressionHelper getBinaryExpressionHelper()

      * * Returns the appropriate BinaryExpressionHelper for the current code path. * Selects fast-path specialized handling when isFastPath() is true, * otherwise delegates to the general-purpose binary expression handler. * Fast-path optimization is controlled by optimizeForInt. * *

      Returns:
        the binary expression writer for the active compilation mode

    - #### public CallSiteWriter getCallSiteWriter()

      * * Returns the CallSiteWriter responsible for generating dynamic call site * infrastructure. Behavior depends on bytecode strategy: either invokedynamic * for modern JVMs or traditional call-site caching for broader compatibility.

    - #### public CallSiteWriter getCallSiteWriterFor(Expression expression)

      * * Returns the CallSiteWriter for a specific expression. * Currently delegates to the default CallSiteWriter; reserved for * future expression-specific optimization strategies. * *

      Parameters:
        `expression` - the expression being processed *
      Returns:
        the appropriate call site writer for this expression * *
      Since:
        6.0.0

    - #### public ClosureWriter getClosureWriter()

      * * Returns the ClosureWriter for compiling Groovy closure literals into * inner classes implementing GroovyObject and supporting variable capture.

    - #### public InvocationWriter getInvocationWriter()

      * * Returns the InvocationWriter for compiling method calls and dynamic * function invocations into appropriate bytecode patterns.

    - #### public LambdaWriter getLambdaWriter()

      * * Returns the LambdaWriter for compiling Java-style lambda expressions * (using the `->` operator) into functional interfaces.

    - #### public MethodReferenceExpressionWriter getMethodReferenceExpressionWriter()

      * * Returns the MethodReferenceExpressionWriter for compiling method reference * expressions compatible with Java functional interface targets.

    - #### public CallSiteWriter getRegularCallSiteWriter()

      Returns the regular dynamic call-site writer used for fallback expressions.

    - #### public InvocationWriter getRegularInvocationWriter()

      Returns the regular dynamic invocation writer used for fallback expressions.

    - #### public StatementWriter getStatementWriter()

      * * Returns the StatementWriter for compiling Groovy statements into bytecode. * Selection depends on optimization mode: OptimizingStatementWriter for * optimizeForInt, otherwise generic StatementWriter.

    - #### public TypeChooser getTypeChooser()

      * * Returns the TypeChooser used to select appropriate type representations * for expressions during compilation, supporting both dynamic and typed paths.

    - #### public UnaryExpressionHelper getUnaryExpressionHelper()

      * * Returns the appropriate UnaryExpressionHelper for the current code path. * Selects fast-path specialized handling when isFastPath() is true, * otherwise delegates to the general-purpose unary expression handler. * Fast-path optimization is controlled by optimizeForInt. * *

      Returns:
        the unary expression writer for the active compilation mode

    - #### public void init(AsmClassGenerator asmClassGenerator, GeneratorContext gcon, org.objectweb.asm.ClassVisitor cv, ClassNode cn)

      * * Initializes this controller with compilation context and ASM infrastructure. * Must be called exactly once before any bytecode generation operations. * Sets up all supporting writers (call site, closure, lambda, etc.) and * configures optimization strategies based on compiler configuration. * *

      Parameters:
        `asmClassGenerator` - the class generator managing the overall compilation *
        `gcon` - the compilation context tracking state across the compilation unit *
        `cv` - the ASM ClassVisitor for emitting bytecode directives *
        `cn` - the ClassNode being compiled

    - #### public boolean isFastPath()

      * * Returns true if the compiler is currently in fast-path mode, * emitting specialized bytecode for primitive type operations. * Use this to determine whether expression helpers should apply optimizations. * *

      Returns:
        true if fast-path compilation mode is active

    - #### public boolean methodHasDynamicResolution()

      GROOVY-11968: returns `true` when the current statically compiled method contains one or more sub-expressions that will be routed through the regular (non-static) call site writer via getCallSiteWriterFor. The regular writer's per-method state must then be initialized at method entry.

      Since:
        6.0.0

    - #### public void setConstructorNode(ConstructorNode cn)

      * * Sets the ConstructorNode for the constructor currently being compiled. * Automatically clears any active method node, since only one can be active. * Used during compilation to track which constructor's bytecode is being generated. * *

      Parameters:
        `constructorNode` - the ConstructorNode to compile, or null to deactivate

    - #### public void setMethodNode(MethodNode mn)

      * * Sets the MethodNode for the method currently being compiled. * Automatically clears any active constructor node, since only one can be active. * Used during compilation to track which method's bytecode is being generated. * *

      Parameters:
        `methodNode` - the MethodNode to compile, or null to deactivate