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 and 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. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public BooleanExpression |
getBooleanExpression()Returns the boolean condition to be asserted. |
|
public Expression |
getMessageExpression()Returns the message expression that provides an optional error message. |
|
public void |
setBooleanExpression(BooleanExpression booleanExpression)Sets the boolean condition to be asserted. |
|
public void |
setMessageExpression(Expression messageExpression)Sets the message expression that provides an optional error message. |
|
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 assert statement with the given condition and no message.
booleanExpression - the BooleanExpression condition to assertConstructs an assert statement with the given condition and message expression.
booleanExpression - the BooleanExpression condition to assertmessageExpression - the Expression that evaluates to an optional error message;
if null or a null expression, no custom message is usedReturns the boolean condition to be asserted.
Returns the message expression that provides an optional error message.
Sets the boolean condition to be asserted.
booleanExpression - the BooleanExpression to evaluateSets the message expression that provides an optional error message.
messageExpression - the Expression that evaluates to the error messageCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.