Package: org.codehaus.groovy.ast.stmt

## [Java] Class IfStatement

- org.codehaus.groovy.ast.stmt.IfStatement

-     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.

  See Also:
    Statement
    BooleanExpression
    BlockStatement
    EmptyStatement

- - ### Constructor Summary

    Constructors
    Constructor and description
    `IfStatement(BooleanExpression booleanExpression, Statement ifBlock, Statement elseBlock)` Constructs an IfStatement with a condition and then/else code blocks.

  - ### Methods Summary

    Methods
    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)`

  - ### Inherited Methods Summary

    Inherited Methods
    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`

- - ### Constructor Detail

    - #### public IfStatement(BooleanExpression booleanExpression, Statement ifBlock, Statement elseBlock)

      Constructs an IfStatement with a condition and then/else code blocks.

      Parameters:
        `booleanExpression` - the BooleanExpression to evaluate; must not be null
        `ifBlock` - the Statement to execute if the condition is true; must not be null
        `elseBlock` - the Statement to execute if the condition is false, or null for no else clause

  - ### Method Detail

    - #### public BooleanExpression getBooleanExpression()

      Returns the BooleanExpression that is evaluated to determine which code path to execute.

      Returns:
        the BooleanExpression representing the condition

    - #### public Statement getElseBlock()

      Returns the Statement to execute when the condition is false. Returns EmptyStatement.INSTANCE if no else clause was specified.

      Returns:
        the else-block Statement

    - #### public Statement getIfBlock()

      Returns the Statement to execute when the condition is true.

      Returns:
        the then-block Statement

    - #### public String getText()

    - #### public void setBooleanExpression(BooleanExpression booleanExpression)

      Sets the BooleanExpression that is evaluated to determine control flow.

      throws:
        NullPointerException if booleanExpression is null
      Parameters:
        `booleanExpression` - the BooleanExpression to evaluate; must not be null

    - #### public void setElseBlock(Statement statement)

      Sets the Statement to execute when the condition is false. If null is provided, the else block is replaced with an empty statement.

      Parameters:
        `statement` - the else-block Statement, or null for no else clause

    - #### public void setIfBlock(Statement statement)

      Sets the Statement to execute when the condition is true.

      throws:
        NullPointerException if statement is null
      Parameters:
        `statement` - the then-block Statement; must not be null

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