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
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
ConstructorsConstructorDescriptionAssertStatement(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 TypeMethodDescriptionReturns the boolean condition to be asserted.Returns the message expression that provides an optional error message.voidsetBooleanExpression(BooleanExpression booleanExpression) Sets the boolean condition to be asserted.voidsetMessageExpression(Expression messageExpression) Sets the message expression that provides an optional error message.voidvisit(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, setStatementLabelMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePositionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Constructor Details
-
AssertStatement
Constructs an assert statement with the given condition and no message.- Parameters:
booleanExpression- theBooleanExpressioncondition to assert
-
AssertStatement
Constructs an assert statement with the given condition and message expression.- Parameters:
booleanExpression- theBooleanExpressioncondition to assertmessageExpression- theExpressionthat evaluates to an optional error message; if null or a null expression, no custom message is used
-
-
Method Details
-
visit
Description copied from class:ASTNodeAccepts 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:
visitin classASTNode- Parameters:
visitor- theGroovyCodeVisitorto process this node
-
getMessageExpression
Returns the message expression that provides an optional error message.- Returns:
- the
Expressionthat evaluates to the error message, or a null expression if not provided
-
getBooleanExpression
Returns the boolean condition to be asserted.- Returns:
- the
BooleanExpressionto evaluate
-
setBooleanExpression
Sets the boolean condition to be asserted.- Parameters:
booleanExpression- theBooleanExpressionto evaluate
-
setMessageExpression
Sets the message expression that provides an optional error message.- Parameters:
messageExpression- theExpressionthat evaluates to the error message
-