Package org.codehaus.groovy.classgen.asm.indy

# Class InvokeDynamicWriter

java.lang.Object
org.codehaus.groovy.classgen.asm.InvocationWriter
org.codehaus.groovy.classgen.asm.indy.InvokeDynamicWriter

public class InvokeDynamicWriter extends InvocationWriter
This Writer is used to generate the call invocation byte codes for usage by invokedynamic.

- ## Field Summary

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

  `castToVargsArray, controller, currentCall, invokeClosureMethod, invokeMethod, invokeMethodOnCurrent, invokeMethodOnSuper, invokeStaticMethod`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `InvokeDynamicWriter(WriterController controller)`
  Creates an invocation writer that emits `invokedynamic` call sites.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `castNonPrimitiveToBool(ClassNode sourceType)`
  Unboxes a non-primitive value on the operand stack to a primitive `boolean`.
  `void`
  `castToNonPrimitiveIfNecessary(ClassNode sourceType, ClassNode targetType)`
  Converts sourceType to a non-primitive by using Groovy casting.
  `void`
  `coerce(ClassNode from, ClassNode target)`
  Emits a Groovy `as` coercion from `from` to `target`.
  `protected boolean`
  `makeCachedCall(Expression origin, ClassExpression sender, Expression receiver, Expression message, Expression arguments, MethodCallerMultiAdapter adapter, boolean safe, boolean spreadSafe, boolean implicitThis, boolean containsSpreadExpression)`
  Attempts to emit a call-site-cached invocation (or invokedynamic).
  `void`
  `makeSingleArgumentCall(Expression receiver, String message, Expression arguments, boolean safe)`
  Generates a single-argument method call via the call-site writer.
  `protected void`
  `writeGetProperty(Expression receiver, String propertyName, boolean safe, boolean implicitThis, boolean groovyObject)`
  Emits an `invokedynamic` property-get call site with the given flags.
  `protected void`
  `writeNormalConstructorCall(ConstructorCallExpression call)`
  Emits a normal (non-direct, non-AIC) constructor call via the call-site writer.
  `protected void`
  `writeSetProperty(Expression receiver, String propertyName, boolean implicitThis, boolean groovyObject)`
  Emits an `invokedynamic` property-write call site (GROOVY-12138).

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

  `finnishConstructorCall, getMethodName, loadArguments, makeArgumentList, makeCall, makeCall, makeClassForNameCall, makeDirectCall, makeSingleArgumentCall, makeUncachedCall, prepareConstructorCall, writeAICCall, writeDirectMethodCall, writeInvokeConstructor, writeInvokeMethod, writeInvokeStaticMethod, writeSpecialConstructorCall`

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

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

- ## Constructor Details

  - ### InvokeDynamicWriter

    public InvokeDynamicWriter(WriterController controller)
    Creates an invocation writer that emits `invokedynamic` call sites.

- ## Method Details

  - ### makeCachedCall

    protected boolean makeCachedCall(Expression origin, ClassExpression sender, Expression receiver, Expression message, Expression arguments, MethodCallerMultiAdapter adapter, boolean safe, boolean spreadSafe, boolean implicitThis, boolean containsSpreadExpression)
    Attempts to emit a call-site-cached invocation (or invokedynamic). Returns `false` if the call cannot be cached, causing the caller to fall through to the uncached path.
    Overrides:
      `makeCachedCall` in class `InvocationWriter`
    Parameters:
      `origin` - the original call expression
      `sender` - the class from which the call is dispatched
      `receiver` - the receiver expression
      `message` - the method name expression
      `arguments` - the arguments expression
      `adapter` - the method caller adapter
      `safe` - whether to use safe navigation
      `spreadSafe` - whether to use spread-safe navigation
      `implicitThis` - whether the receiver is implicit `this`
      `containsSpreadExpression` - whether any argument uses spread
    Returns:
      `true` if a cached call was emitted

  - ### makeSingleArgumentCall

    public void makeSingleArgumentCall(Expression receiver, String message, Expression arguments, boolean safe)
    Generates a single-argument method call via the call-site writer.
    Overrides:
      `makeSingleArgumentCall` in class `InvocationWriter`
    Parameters:
      `receiver` - the receiver expression
      `message` - the method name
      `arguments` - the single argument expression
      `safe` - whether to use safe navigation (`?.`)

  - ### writeGetProperty

    protected void writeGetProperty(Expression receiver, String propertyName, boolean safe, boolean implicitThis, boolean groovyObject)
    Emits an `invokedynamic` property-get call site with the given flags.

  - ### writeSetProperty

    protected void writeSetProperty(Expression receiver, String propertyName, boolean implicitThis, boolean groovyObject)
    Emits an `invokedynamic` property-write call site (GROOVY-12138). On entry, the assigned value sits on the operand stack (the assignment machinery evaluates the RHS before visiting the LHS). The value is boxed, the receiver pushed, and the two swapped so the call-site shape is receiver-first — `(ReceiverType, ValueType)void` — preserving the runtime invariant that `arguments[0]` is the receiver. The void return means no operand-stack result to clean up, matching the classic adapter path's accounting.

  - ### writeNormalConstructorCall

    protected void writeNormalConstructorCall(ConstructorCallExpression call)
    Emits a normal (non-direct, non-AIC) constructor call via the call-site writer.
    Overrides:
      `writeNormalConstructorCall` in class `InvocationWriter`
    Parameters:
      `call` - the constructor call expression to compile

  - ### coerce

    public void coerce(ClassNode from, ClassNode target)
    Emits a Groovy `as` coercion from `from` to `target`.
    Overrides:
      `coerce` in class `InvocationWriter`
    Parameters:
      `from` - the source type currently on the operand stack
      `target` - the target type to coerce to

  - ### castToNonPrimitiveIfNecessary

    public void castToNonPrimitiveIfNecessary(ClassNode sourceType, ClassNode targetType)
    Converts sourceType to a non-primitive by using Groovy casting. sourceType might be a primitive This might be done using SBA#castToType
    Overrides:
      `castToNonPrimitiveIfNecessary` in class `InvocationWriter`

  - ### castNonPrimitiveToBool

    public void castNonPrimitiveToBool(ClassNode sourceType)
    Unboxes a non-primitive value on the operand stack to a primitive `boolean`.
    Overrides:
      `castNonPrimitiveToBool` in class `InvocationWriter`
    Parameters:
      `sourceType` - the type currently on top of the operand stack