Package: org.codehaus.groovy.ast.expr

## [Java] Class BinaryExpression

- org.codehaus.groovy.ast.expr.BinaryExpression

-     public class BinaryExpression
      extends Expression

  Represents a binary operation between two expressions, such as addition, subtraction, comparison, or array/map access. The operation is specified by a Token indicating the operation type (e.g., `+`, `-`, `==`, `[]`). Supports safe operations where null objects are handled gracefully, returning null instead of throwing an exception.

  See Also:
    Expression
    VariableExpression
    MethodCallExpression

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

  - ### Constructor Summary

    Constructors
    Constructor and description
    `BinaryExpression(Expression leftExpression, Token operation, Expression rightExpression)` Creates a binary expression with the given left operand, operation, and right operand.
    `BinaryExpression(Expression leftExpression, Token operation, Expression rightExpression, boolean safe)` Creates a binary expression with optional safe navigation support.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Expression` | `getLeftExpression()` Returns the left operand of this binary expression.
    `` | `public Token` | `getOperation()` Returns the operation token representing the binary operation.
    `` | `public Expression` | `getRightExpression()` Returns the right operand of this binary expression.
    `` | `public String` | `getText()`
    `` | `public boolean` | `isSafe()` Indicates whether this binary expression uses safe navigation.
    `` | `public static BinaryExpression` | `newAssignmentExpression(Variable variable, Expression rhs)` Creates an assignment expression in which the specified expression is written into the specified variable.
    `` | `public static BinaryExpression` | `newInitializationExpression(String variable, ClassNode type, Expression rhs)` Creates a variable initialization expression in which the specified expression is written into the specified variable name with an optional type annotation.
    `` | `public void` | `setLeftExpression(Expression leftExpression)` Sets the left operand of this binary expression.
    `` | `public void` | `setRightExpression(Expression rightExpression)` Sets the right operand of this binary expression.
    `` | `public void` | `setSafe(boolean safe)` Sets whether this binary expression should use 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`

- - ### Constructor Detail

    - #### public BinaryExpression(Expression leftExpression, Token operation, Expression rightExpression)

      Creates a binary expression with the given left operand, operation, and right operand.

      Parameters:
        `leftExpression` - the left operand of the binary operation; must not be null
        `operation` - the operation token (e.g., Types.PLUS, Types.MINUS); may not be null
        `rightExpression` - the right operand of the binary operation; must not be null

    - #### public BinaryExpression(Expression leftExpression, Token operation, Expression rightExpression, boolean safe)

      Creates a binary expression with optional safe navigation support.

      Parameters:
        `leftExpression` - the left operand of the binary operation; must not be null
        `operation` - the operation token; may not be null
        `rightExpression` - the right operand of the binary operation; must not be null
        `safe` - if true, enables safe navigation (e.g., null-safe array access with `?[]`)

  - ### Method Detail

    - #### public Expression getLeftExpression()

      Returns the left operand of this binary expression.

      Returns:
        the left operand Expression; never null

    - #### public Token getOperation()

      Returns the operation token representing the binary operation.

      Returns:
        the operation Token (e.g., Types.PLUS, Types.EQUAL); never null

    - #### public Expression getRightExpression()

      Returns the right operand of this binary expression.

      Returns:
        the right operand Expression; never null

    - #### public String getText()

    - #### public boolean isSafe()

      Indicates whether this binary expression uses safe navigation. Safe operations return null instead of throwing a NullPointerException when the left operand is null (e.g., `obj?.property`).

      Returns:
        true if safe navigation is enabled; false otherwise

    - #### public static BinaryExpression newAssignmentExpression(Variable variable, Expression rhs)

      Creates an assignment expression in which the specified expression is written into the specified variable. This is a factory method for constructing assignment operations like `x = value`.

      Parameters:
        `variable` - the target variable for assignment; must not be null
        `rhs` - the right-hand side expression to assign; must not be null
      Returns:
        a new BinaryExpression representing the assignment

    - #### public static BinaryExpression newInitializationExpression(String variable, ClassNode type, Expression rhs)

      Creates a variable initialization expression in which the specified expression is written into the specified variable name with an optional type annotation. This is a factory method for constructing typed variable declarations like `String x = value`.

      Parameters:
        `variable` - the variable name to initialize; must not be null
        `type` - the type annotation for the variable; may be null for untyped variables
        `rhs` - the right-hand side expression to assign; must not be null
      Returns:
        a new BinaryExpression representing the initialization

    - #### public void setLeftExpression(Expression leftExpression)

      Sets the left operand of this binary expression.

      Parameters:
        `leftExpression` - the new left operand; must not be null

    - #### public void setRightExpression(Expression rightExpression)

      Sets the right operand of this binary expression.

      Parameters:
        `rightExpression` - the new right operand; must not be null

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

      Sets whether this binary expression should use safe navigation.

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

    - #### public String toString()

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

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