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

# Class StaticTypesSwitchExpressionWriter

java.lang.Object
org.codehaus.groovy.classgen.asm.SwitchExpressionWriter
org.codehaus.groovy.classgen.asm.sc.StaticTypesSwitchExpressionWriter

public class StaticTypesSwitchExpressionWriter extends SwitchExpressionWriter
Static-compilation writer for `SwitchExpression`. Emits `tableswitch` / `lookupswitch` when the selector and labels are constants of a type `javac` would switch on, and otherwise the `isCase` method selected by the type checker as a direct call.

Since:
  6.0.0

- ## Field Summary

  ### Fields inherited from class org.codehaus.groovy.classgen.asm.SwitchExpressionWriter

  `controller`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StaticTypesSwitchExpressionWriter(StaticTypesWriterController controller)`
  Creates a switch-expression writer for statically compiled methods.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected ClassNode`
  `prepareSelectorType(OperandStack operandStack)`
  Keeps the selector as visited — boxing is deferred until a path actually needs a reference (isCase or a null check on a wrapper).
  `protected void`
  `writeIsCaseComparison(CaseStatement caseStatement, int selectorIndex, ClassNode selectorType)`
  Emits the `isCase` call selected by the type checker as a direct method call via `AsmClassGenerator.visitMethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression)`, which reaches `StaticInvocationWriter.writeDirectMethodCall`.
  `protected boolean`
  `writeOptimizedSwitch(SwitchExpression expression, int selectorIndex, ClassNode selectorType)`
  Attempts a specialized dispatch (tableswitch / lookupswitch).

  ### Methods inherited from class org.codehaus.groovy.classgen.asm.SwitchExpressionWriter

  `enumConstantCount, enumConstantName, intConstant, isIntegralType, isIntegralWrapper, resolveResultType, stringConstant, throwIncompatibleClassChangeError, throwUnmatchedSelector, unwrapEnumType, writeDefaultOrThrow, writeSwitchExpression, writeYield`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### StaticTypesSwitchExpressionWriter

    public StaticTypesSwitchExpressionWriter(StaticTypesWriterController controller)
    Creates a switch-expression writer for statically compiled methods.
    Parameters:
      `controller` - the static types writer controller

- ## Method Details

  - ### prepareSelectorType

    protected ClassNode prepareSelectorType(OperandStack operandStack)
    Keeps the selector as visited — boxing is deferred until a path actually needs a reference (isCase or a null check on a wrapper).
    Overrides:
      `prepareSelectorType` in class `SwitchExpressionWriter`

  - ### writeOptimizedSwitch

    protected boolean writeOptimizedSwitch(SwitchExpression expression, int selectorIndex, ClassNode selectorType)
    Description copied from class: `SwitchExpressionWriter`
    Attempts a specialized dispatch (tableswitch / lookupswitch). The base writer has none; static compilation overrides this.
    Overrides:
      `writeOptimizedSwitch` in class `SwitchExpressionWriter`
    Returns:
      `true` if specialized bytecode was emitted

  - ### writeIsCaseComparison

    protected void writeIsCaseComparison(CaseStatement caseStatement, int selectorIndex, ClassNode selectorType)
    Emits the `isCase` call selected by the type checker as a direct method call via `AsmClassGenerator.visitMethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression)`, which reaches `StaticInvocationWriter.writeDirectMethodCall`. A literal `case null` is identity, not `DGM.isCase(Object,Object)` (which NPEs). Any other arm must already carry `StaticTypesMarker.DIRECT_METHOD_CALL_TARGET` on the `CaseStatement`; missing targets are a type-checking error except under `TypeCheckingMode.SKIP`.
    Overrides:
      `writeIsCaseComparison` in class `SwitchExpressionWriter`