public class IfStatement
extends Statement
Represents an if (condition) { then-block } else { else-block } conditional statement in Groovy. The if statement evaluates a boolean BooleanExpression and executes one of two code paths: the if block if the condition is true, or the else block (if present) if the condition is false. The else block defaults to an empty statement if not explicitly provided.
| Constructor and description |
|---|
IfStatement(BooleanExpression booleanExpression, Statement ifBlock, Statement elseBlock)Constructs an IfStatement with a condition and then/else code blocks. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public BooleanExpression |
getBooleanExpression()Returns the BooleanExpression that is evaluated to determine which code path to execute. |
|
public Statement |
getElseBlock()Returns the Statement to execute when the condition is false. |
|
public Statement |
getIfBlock()Returns the Statement to execute when the condition is true. |
|
public String |
getText() |
|
public void |
setBooleanExpression(BooleanExpression booleanExpression)Sets the BooleanExpression that is evaluated to determine control flow. |
|
public void |
setElseBlock(Statement statement)Sets the Statement to execute when the condition is false. |
|
public void |
setIfBlock(Statement statement)Sets the Statement to execute when the condition is true. |
|
public void |
visit(GroovyCodeVisitor visitor) |
| Methods inherited from class | Name |
|---|---|
class Statement |
addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabel |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Constructs an IfStatement with a condition and then/else code blocks.
booleanExpression
- the BooleanExpression to evaluate; must not be nullifBlock
- the Statement to execute if the condition is true; must not be nullelseBlock
- the Statement to execute if the condition is false, or null for no else clauseReturns the BooleanExpression that is evaluated to determine which code path to execute.
Returns the Statement to execute when the condition is false. Returns EmptyStatement.INSTANCE if no else clause was specified.
Returns the Statement to execute when the condition is true.
Sets the BooleanExpression that is evaluated to determine control flow.
booleanExpression
- the BooleanExpression to evaluate; must not be nullSets the Statement to execute when the condition is false. If null is provided, the else block is replaced with an empty statement.
statement
- the else-block Statement, or null for no else clauseSets the Statement to execute when the condition is true.
statement
- the then-block Statement; must not be nullCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.