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.
| Fields inherited from class | Fields |
|---|---|
class Expression |
EMPTY_ARRAY |
| 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. |
| 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) |
| 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 |
Creates a binary expression with the given left operand, operation, and right operand.
leftExpression - the left operand of the binary operation; must not be nulloperation - the operation token (e.g., Types.PLUS, Types.MINUS);
may not be nullrightExpression - the right operand of the binary operation; must not be nullCreates a binary expression with optional safe navigation support.
leftExpression - the left operand of the binary operation; must not be nulloperation - the operation token; may not be nullrightExpression - the right operand of the binary operation; must not be nullsafe - if true, enables safe navigation (e.g., null-safe array access with ?[])Returns the left operand of this binary expression.
Returns the operation token representing the binary operation.
Returns the right operand of this binary expression.
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).
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.
variable - the target variable for assignment; must not be nullrhs - the right-hand side expression to assign; must not be null 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.
variable - the variable name to initialize; must not be nulltype - the type annotation for the variable; may be null for untyped variablesrhs - the right-hand side expression to assign; must not be nullSets the left operand of this binary expression.
leftExpression - the new left operand; must not be nullSets the right operand of this binary expression.
rightExpression - the new right operand; must not be nullSets whether this binary expression should use safe navigation.
safe - true to enable safe navigation; false otherwiseCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.