public class InvocationWriter
extends Object
Handles method and constructor invocations, generating appropriate bytecode.
| Modifiers | Name | Description |
|---|---|---|
static MethodCaller |
castToVargsArray |
Method caller for casting an array of arguments to a varargs array. |
protected WriterController |
controller |
The controller coordinating all bytecode writers for the current class. |
protected Expression |
currentCall |
The expression currently being compiled as a call, used for optimizations. |
static MethodCaller |
invokeClosureMethod |
|
static MethodCallerMultiAdapter |
invokeMethod |
Multi-adapter for generic invokeMethod call-site variants. |
static MethodCallerMultiAdapter |
invokeMethodOnCurrent |
Multi-adapter for invokeMethodOnCurrent call-site variants. |
static MethodCallerMultiAdapter |
invokeMethodOnSuper |
Multi-adapter for invokeMethodOnSuper call-site variants. |
static MethodCallerMultiAdapter |
invokeStaticMethod |
Multi-adapter for invokeStaticMethod call-site variants. |
| Constructor and description |
|---|
InvocationWriter(WriterController controller)Creates an invocation writer with the given controller. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
castNonPrimitiveToBool(ClassNode last)Unboxes a non-primitive value on the operand stack to a primitive boolean. |
|
public void |
castToNonPrimitiveIfNecessary(ClassNode sourceType, ClassNode targetType)Converts sourceType to a non-primitive by using Groovy casting. |
|
public void |
coerce(ClassNode from, ClassNode target)Emits a Groovy as coercion from from to target. |
|
protected void |
finnishConstructorCall(ConstructorNode cn, String ownerDescriptor, int argsToRemove)Emits the INVOKESPECIAL <init> instruction and updates the operand
stack after a constructor call set up by prepareConstructorCall. |
|
protected String |
getMethodName(Expression message)Extracts the constant method name string from a message expression. |
|
protected void |
loadArguments(List<Expression> arguments, Parameter[] parameters)Evaluates and loads each argument expression, handling varargs packing. |
|
public static ArgumentListExpression |
makeArgumentList(Expression arguments)Converts an expression to an argument list. |
|
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). |
|
public void |
makeCall(Expression origin, Expression receiver, Expression message, Expression arguments, MethodCallerMultiAdapter adapter, boolean safe, boolean spreadSafe, boolean implicitThis)Generates bytecode for a method call. |
|
protected void |
makeCall(Expression origin, ClassExpression sender, Expression receiver, Expression message, Expression arguments, MethodCallerMultiAdapter adapter, boolean safe, boolean spreadSafe, boolean implicitThis)Generates bytecode for a method invocation, choosing among direct call, call-site caching, and uncached (ScriptBytecodeAdapter) strategies. |
|
protected boolean |
makeClassForNameCall(Expression origin, Expression receiver, Expression message, Expression arguments)if Class.forName(x) is recognized, make a direct method call |
|
protected boolean |
makeDirectCall(Expression origin, Expression receiver, Expression message, Expression arguments, MethodCallerMultiAdapter adapter, boolean implicitThis, boolean containsSpreadExpression)Attempts to emit a direct (statically resolved) method call. |
|
public final void |
makeSingleArgumentCall(Expression receiver, String message, Expression arguments)Delegates to makeSingleArgumentCall(Expression, String, Expression, boolean) with safe = false. |
|
public void |
makeSingleArgumentCall(Expression receiver, String message, Expression arguments, boolean safe)Generates a single-argument method call via the call-site writer. |
|
protected void |
makeUncachedCall(Expression origin, ClassExpression sender, Expression receiver, Expression message, Expression arguments, MethodCallerMultiAdapter adapter, boolean safe, boolean spreadSafe, boolean implicitThis, boolean containsSpreadExpression)Emits an uncached invocation via ScriptBytecodeAdapter. |
|
protected String |
prepareConstructorCall(ConstructorNode cn)Emits the NEW and DUP instructions for a constructor call and
returns the internal class name of the type being constructed. |
|
protected boolean |
writeAICCall(ConstructorCallExpression call)Emits a constructor call for an anonymous inner class (AIC). |
|
protected boolean |
writeDirectMethodCall(MethodNode target, boolean implicitThis, Expression receiver, TupleExpression args)Emits a direct (INVOKE*) bytecode call to target when static type
information is available. |
|
public void |
writeInvokeConstructor(ConstructorCallExpression call)Generates bytecode for a constructor call expression, choosing the appropriate strategy (direct, AIC, or normal call-site). |
|
public void |
writeInvokeMethod(MethodCallExpression call)Generates bytecode for a standard (non-static, non-constructor) method call expression. |
|
public void |
writeInvokeStaticMethod(StaticMethodCallExpression call)Generates bytecode for a static method call expression. |
|
protected void |
writeNormalConstructorCall(ConstructorCallExpression call)Emits a normal (non-direct, non-AIC) constructor call via the call-site writer. |
|
public void |
writeSpecialConstructorCall(ConstructorCallExpression call)Generates bytecode for a this() or super() constructor
call at the start of a constructor body. |
Method caller for casting an array of arguments to a varargs array.
The controller coordinating all bytecode writers for the current class.
The expression currently being compiled as a call, used for optimizations.
Multi-adapter for generic invokeMethod call-site variants.
Multi-adapter for invokeMethodOnCurrent call-site variants.
Multi-adapter for invokeMethodOnSuper call-site variants.
Multi-adapter for invokeStaticMethod call-site variants.
Creates an invocation writer with the given controller.
controller - the writer controller Unboxes a non-primitive value on the operand stack to a primitive boolean.
last - the type currently on top of the operand stackConverts sourceType to a non-primitive by using Groovy casting. sourceType might be a primitive This might be done using SBA#castToType
Emits a Groovy as coercion from from to target.
from - the source type currently on the operand stacktarget - the target type to coerce to Emits the INVOKESPECIAL <init> instruction and updates the operand
stack after a constructor call set up by prepareConstructorCall.
cn - the constructor node being invokedownerDescriptor - the JVM internal name of the owning classargsToRemove - the number of argument entries to pop from the tracked stack Extracts the constant method name string from a message expression.
Returns null if the expression is not a constant string.
message - the method name expressionnull if not determinableEvaluates and loads each argument expression, handling varargs packing.
arguments - the argument expressions to evaluateparameters - the declared parameters of the target methodConverts an expression to an argument list.
arguments if already an argument list or an argument list
of the expression or expressions (in case of a tuple expression). 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.
origin - the original call expressionsender - the class from which the call is dispatchedreceiver - the receiver expressionmessage - the method name expressionarguments - the arguments expressionadapter - the method caller adaptersafe - whether to use safe navigationspreadSafe - whether to use spread-safe navigationimplicitThis - whether the receiver is implicit thiscontainsSpreadExpression - whether any argument uses spreadtrue if a cached call was emittedGenerates bytecode for a method call.
origin - the original expressionreceiver - the receiver expressionmessage - the method name expressionarguments - the arguments expressionadapter - the method caller adaptersafe - whether to use safe navigationspreadSafe - whether to use spread-safe navigationimplicitThis - whether the receiver is implicit 'this'Generates bytecode for a method invocation, choosing among direct call, call-site caching, and uncached (ScriptBytecodeAdapter) strategies.
origin - the original expression triggering this callsender - the class from which the call is dispatchedreceiver - the receiver expressionmessage - the method name expressionarguments - the arguments expressionadapter - the multi-adapter selecting the correct runtime methodsafe - whether to use safe navigation (?.)spreadSafe - whether to use spread-safe navigation (*?.)implicitThis - whether the receiver is implicit thisif Class.forName(x) is recognized, make a direct method call
Attempts to emit a direct (statically resolved) method call.
Returns false if no direct call is possible, causing the caller to
fall through to the cached or uncached path.
origin - the original call expressionreceiver - the receiver expressionmessage - the method name expressionarguments - the arguments expressionadapter - the method caller adapterimplicitThis - whether the receiver is implicit thiscontainsSpreadExpression - whether any argument uses spread (*)true if the call was emitted directly Delegates to makeSingleArgumentCall(Expression, String, Expression, boolean)
with safe = false.
receiver - the receiver expressionmessage - the method namearguments - the single argument expressionGenerates a single-argument method call via the call-site writer.
receiver - the receiver expressionmessage - the method namearguments - the single argument expressionsafe - whether to use safe navigation (?.)Emits an uncached invocation via ScriptBytecodeAdapter. Used as the fallback when neither direct nor cached dispatch is applicable.
origin - the original call expressionsender - the class from which the call is dispatchedreceiver - the receiver expressionmessage - the method name expressionarguments - the arguments expressionadapter - the method caller adaptersafe - whether to use safe navigationspreadSafe - whether to use spread-safe navigationimplicitThis - whether the receiver is implicit thiscontainsSpreadExpression - whether any argument uses spread Emits the NEW and DUP instructions for a constructor call and
returns the internal class name of the type being constructed.
cn - the constructor node whose declaring class is being instantiated Emits a constructor call for an anonymous inner class (AIC).
Returns false if the call is not for an AIC.
call - the constructor call expression to compiletrue if an AIC call was emitted Emits a direct (INVOKE*) bytecode call to target when static type
information is available. Returns false if a direct call cannot be made.
target - the resolved method node to call directlyimplicitThis - whether the receiver is implicit thisreceiver - the receiver expression (may be null)args - the argument tupletrue if the call was emitted, false otherwiseGenerates bytecode for a constructor call expression, choosing the appropriate strategy (direct, AIC, or normal call-site).
call - the constructor call expression to compileGenerates bytecode for a standard (non-static, non-constructor) method call expression.
call - the method call expression to compileGenerates bytecode for a static method call expression.
call - the static method call expression to compileEmits a normal (non-direct, non-AIC) constructor call via the call-site writer.
call - the constructor call expression to compile Generates bytecode for a this() or super() constructor
call at the start of a constructor body.
call - the constructor call expression representing this() or super()Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.