Package org.codehaus.groovy.ast.stmt

# Class AssertStatement

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.stmt.Statement
org.codehaus.groovy.ast.stmt.AssertStatement

All Implemented Interfaces:
  `NodeMetaDataHandler`

public class AssertStatement extends Statement
Represents an assert statement that enforces a condition with an optional error message. An assert statement evaluates a boolean condition and throws an `AssertionError` if the condition is false. An optional message expression may be provided to customize the error message. Assert statements are typically used to verify invariants and debug assumptions.

Example: `assert i != 0 : "should never be zero"`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AssertStatement(BooleanExpression booleanExpression)`
  Constructs an assert statement with the given condition and no message.
  `AssertStatement(BooleanExpression booleanExpression, Expression messageExpression)`
  Constructs an assert statement with the given condition and message expression.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `BooleanExpression`
  `getBooleanExpression()`
  Returns the boolean condition to be asserted.
  `Expression`
  `getMessageExpression()`
  Returns the message expression that provides an optional error message.
  `void`
  `setBooleanExpression(BooleanExpression booleanExpression)`
  Sets the boolean condition to be asserted.
  `void`
  `setMessageExpression(Expression messageExpression)`
  Sets the message expression that provides an optional error message.
  `void`
  `visit(GroovyCodeVisitor visitor)`
  Accepts a code visitor for AST traversal and transformation.

  ### Methods inherited from class org.codehaus.groovy.ast.stmt.Statement

  `addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabel`

  ### Methods inherited from class org.codehaus.groovy.ast.ASTNode

  `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

- ## Constructor Details

  - ### AssertStatement

    public AssertStatement(BooleanExpression booleanExpression)
    Constructs an assert statement with the given condition and no message.
    Parameters:
      `booleanExpression` - the `BooleanExpression` condition to assert

  - ### AssertStatement

    public AssertStatement(BooleanExpression booleanExpression, Expression messageExpression)
    Constructs an assert statement with the given condition and message expression.
    Parameters:
      `booleanExpression` - the `BooleanExpression` condition to assert
      `messageExpression` - the `Expression` that evaluates to an optional error message; if null or a null expression, no custom message is used

- ## Method Details

  - ### visit

    public void visit(GroovyCodeVisitor visitor)
    Description copied from class: `ASTNode`
    Accepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.
    Overrides:
      `visit` in class `ASTNode`
    Parameters:
      `visitor` - the `GroovyCodeVisitor` to process this node

  - ### getMessageExpression

    public Expression getMessageExpression()
    Returns the message expression that provides an optional error message.
    Returns:
      the `Expression` that evaluates to the error message, or a null expression if not provided

  - ### getBooleanExpression

    public BooleanExpression getBooleanExpression()
    Returns the boolean condition to be asserted.
    Returns:
      the `BooleanExpression` to evaluate

  - ### setBooleanExpression

    public void setBooleanExpression(BooleanExpression booleanExpression)
    Sets the boolean condition to be asserted.
    Parameters:
      `booleanExpression` - the `BooleanExpression` to evaluate

  - ### setMessageExpression

    public void setMessageExpression(Expression messageExpression)
    Sets the message expression that provides an optional error message.
    Parameters:
      `messageExpression` - the `Expression` that evaluates to the error message