Package: org.codehaus.groovy.ast.expr

## [Java] Class MethodCallExpression

- org.codehaus.groovy.ast.expr.MethodCallExpression

- All Implemented Interfaces and Traits:
    MethodCall

      public class MethodCallExpression
      extends Expression
      implements MethodCall

  Represents a method call on an object or class, including receiver object, method name/expression, and arguments. Supports safe navigation (null-safe calls with `?`), spread-safe operations, implicit this, and direct method targets for optimization. Method names can be constant strings or dynamic expressions (e.g., computed method names).

  See Also:
    Expression
    MethodCall
    VariableExpression
    ClosureExpression

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static Expression` | `NO_ARGUMENTS` |

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class Expression` | `EMPTY_ARRAY`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `MethodCallExpression(Expression objectExpression, String method, Expression arguments)` Creates a method call with a string method name.
    `MethodCallExpression(Expression objectExpression, Expression method, Expression arguments)` Creates a method call with an expression-based method name (supports dynamic method names).

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Expression` | `getArguments()` Returns the method arguments as a TupleExpression.
    `` | `public GenericsType[]` | `getGenericsTypes()` Returns the generic type parameters for this method call, if specified.
    `` | `public Expression` | `getMethod()` Returns the method name or reference expression.
    `` | `public String` | `getMethodAsString()` Returns the method name as a string if it is a constant static name, or null if the method name is computed dynamically.
    `` | `public MethodNode` | `getMethodTarget()` Returns the target MethodNode if this method call has been resolved to a specific method.
    `` | `public Expression` | `getObjectExpression()` Returns the object (receiver) on which this method is invoked.
    `` | `public ASTNode` | `getReceiver()` Returns the receiver as an ASTNode.
    `` | `public String` | `getText()`
    `` | `public boolean` | `isImplicitThis()` Indicates whether this method call implicitly refers to the current object (`this`).
    `` | `public boolean` | `isSafe()` Indicates whether this is a safe method call.
    `` | `public boolean` | `isSpreadSafe()` Indicates whether this method call uses spread-safe navigation.
    `` | `public boolean` | `isUsingGenerics()` Indicates whether generic type parameters are specified for this method call.
    `` | `public void` | `setArguments(Expression arguments)` Sets the method arguments.
    `` | `public void` | `setGenericsTypes(GenericsType[] genericsTypes)` Sets the generic type parameters for this method call.
    `` | `public void` | `setImplicitThis(boolean implicitThis)` Sets whether this method call implicitly refers to the current object.
    `` | `public void` | `setMethod(Expression method)` Sets the method name or reference expression.
    `` | `public void` | `setMethodTarget(MethodNode mn)` Sets a direct method target for this method call.
    `` | `public void` | `setObjectExpression(Expression objectExpression)` Sets the object (receiver) on which this method is invoked.
    `` | `public void` | `setSafe(boolean safe)` Sets whether this should be a safe method call.
    `` | `public void` | `setSourcePosition(ASTNode node)`
    `` | `public void` | `setSpreadSafe(boolean value)` Sets whether this method call should use spread-safe navigation.
    `` | `public String` | `toString()`
    `` | `public Expression` | `transformExpression(ExpressionTransformer transformer)`
    `` | `public void` | `visit(GroovyCodeVisitor visitor)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Expression` | `getType, setType, transformExpression, transformExpressions, transformExpressions`
    `class AnnotatedNode` | `addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic`
    `class ASTNode` | `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

- - ### Field Detail

    - #### public static final Expression NO_ARGUMENTS

  - ### Constructor Detail

    - #### public MethodCallExpression(Expression objectExpression, String method, Expression arguments)

      Creates a method call with a string method name.

      Parameters:
        `objectExpression` - the receiver object on which the method is invoked; must not be null
        `method` - the name of the method as a String; must not be null
        `arguments` - the method arguments as an Expression; will be wrapped in a TupleExpression if not already one

    - #### public MethodCallExpression(Expression objectExpression, Expression method, Expression arguments)

      Creates a method call with an expression-based method name (supports dynamic method names).

      Parameters:
        `objectExpression` - the receiver object on which the method is invoked; must not be null
        `method` - the method name as an Expression, which may be a ConstantExpression for static names or other expression types for dynamic names; must not be null
        `arguments` - the method arguments as an Expression; will be wrapped in a TupleExpression if not already one

  - ### Method Detail

    - #### public Expression getArguments()

      Returns the method arguments as a TupleExpression.

      Returns:
        the method arguments; typically a TupleExpression, never null

    - #### public GenericsType[] getGenericsTypes()

      Returns the generic type parameters for this method call, if specified. Used for generic method invocations like `obj.<String>method()`.

      Returns:
        an array of GenericsType parameters, or null if no generics are specified

    - #### public Expression getMethod()

      Returns the method name or reference expression. This may be a ConstantExpression for static method names or other expression types for dynamically computed names.

      Returns:
        the method name Expression; never null

    - #### public String getMethodAsString()

      Returns the method name as a string if it is a constant static name, or null if the method name is computed dynamically.

      Returns:
        the method name as a String if this is a static method call, or null if the method name is a dynamic expression

    - #### public MethodNode getMethodTarget()

      Returns the target MethodNode if this method call has been resolved to a specific method. When a target is set, the method call will execute the direct target outside of the MOP (method resolution order), enabling direct method invocation for optimization.

      Returns:
        the target MethodNode, or null if no specific target is set

    - #### public Expression getObjectExpression()

      Returns the object (receiver) on which this method is invoked.

      Returns:
        the receiver Expression; never null

    - #### public ASTNode getReceiver()

      Returns the receiver as an ASTNode. This is used by the MethodCall interface.

      Returns:
        the receiver ASTNode

    - #### public String getText()

    - #### public boolean isImplicitThis()

      Indicates whether this method call implicitly refers to the current object (`this`). If true, no explicit receiver object was specified (e.g., `method()` vs `obj.method()`).

      Returns:
        true if the method call implicitly refers to this; false if an explicit receiver object was specified

    - #### public boolean isSafe()

      Indicates whether this is a safe method call. In a safe call, if the receiver object is null, the method call returns null instead of throwing a NullPointerException (e.g., `obj?.method()`).

      Returns:
        true if this is a safe method call; false otherwise

    - #### public boolean isSpreadSafe()

      Indicates whether this method call uses spread-safe navigation. Spread-safe operations iterate over collection elements and apply the method call to each element safely.

      Returns:
        true if spread-safe navigation is enabled; false otherwise

    - #### public boolean isUsingGenerics()

      Indicates whether generic type parameters are specified for this method call.

      Returns:
        true if generic type parameters are present; false otherwise

    - #### public void setArguments(Expression arguments)

      Sets the method arguments. If the provided expression is not a TupleExpression, it will be automatically wrapped in one for internal consistency.

      Parameters:
        `arguments` - the method arguments as an Expression; must not be null

    - #### public void setGenericsTypes(GenericsType[] genericsTypes)

      Sets the generic type parameters for this method call.

      Parameters:
        `genericsTypes` - an array of GenericsType parameters; may be null

    - #### public void setImplicitThis(boolean implicitThis)

      Sets whether this method call implicitly refers to the current object.

      Parameters:
        `implicitThis` - true if this is an implicit this call; false otherwise

    - #### public void setMethod(Expression method)

      Sets the method name or reference expression.

      Parameters:
        `method` - the method name as an Expression; must not be null

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

      Sets a direct method target for this method call. When set, the method call will invoke the specified target directly, bypassing the MOP (method resolution order) for efficiency. WARNING: A method call made this way will run outside of the MOP and may not respect dynamic dispatch or meta-programming extensions.

      Parameters:
        `mn` - the target MethodNode; may be null to clear the target

    - #### public void setObjectExpression(Expression objectExpression)

      Sets the object (receiver) on which this method is invoked.

      Parameters:
        `objectExpression` - the receiver Expression; must not be null

    - #### public void setSafe(boolean safe)

      Sets whether this should be a safe method call.

      Parameters:
        `safe` - true for safe navigation; false otherwise

    - #### public void setSourcePosition(ASTNode node)

    - #### public void setSpreadSafe(boolean value)

      Sets whether this method call should use spread-safe navigation.

      Parameters:
        `value` - true to enable spread-safe navigation; false otherwise

    - #### public String toString()

    - #### public Expression transformExpression(ExpressionTransformer transformer)

    - #### public void visit(GroovyCodeVisitor visitor)