public final class Statements
extends java.lang.Object
| Constructor and Description |
|---|
Statements() |
| Modifier and Type | Method and Description |
|---|---|
static AssertStatement |
assertS(BooleanExpression booleanExpr)
|
static AssertStatement |
assertS(BooleanExpression booleanExpr,
java.lang.String errorMessage)
|
static BlockStatement |
blockS(java.util.List<Statement> statements)
Returns an instance of
BlockStatement. |
static BlockStatement |
blockS(Statement... statements)
Returns an instance of
BlockStatement. |
static BlockStatement |
blockS(VariableScope variableScope,
java.util.List<Statement> statements)
Returns an instance of
BlockStatement. |
static BlockStatement |
blockS(VariableScope variableScope,
Statement... statements)
Returns an instance of
BlockStatement. |
static BlockStatement |
blockSFromString(java.lang.String code)
Returns an instance of
BlockStatement. |
static Statement |
ctorSuperS(Expression... args)
Returns an instance of
Statement. |
static DoWhileStatement |
doWhileS(BooleanExpression booleanExpr,
Statement loopBlock)
Represents a do-while statement.
|
static DoWhileStatement |
doWhileStatement(BooleanExpression booleanExpr,
Statement loopBlock)
Deprecated.
As of release 2.4.7, replaced by
doWhileS(BooleanExpression, Statement) |
static Statement |
emptyS()
Represents an empty statement.
|
static Statement |
emptyStatement()
Deprecated.
As of release 2.4.7, replaced by
emptyS() |
static IfStatement |
ifElseS(BooleanExpression booleanExpr,
Statement ifStmt,
Statement elseStmt)
Builds a if-else statement.
|
static IfStatement |
ifS(BooleanExpression booleanExpr,
Statement ifStmt)
Builds a if statement, without the else part.
|
static ReturnStatement |
returnS(Expression expression)
|
static Statement |
stmt(Expression expression)
Returns an instance of
Statement. |
static ThrowStatement |
throwS(Expression expression)
Represents how to throw an exception
AST
|
static TryCatchStatementBuilder |
tryCatchSBuilder()
Returns an instance of
TryCatchStatementBuilder to
build complex try/catch statements the easy way. |
static WhileStatement |
whileS(BooleanExpression booleanExpr,
Statement loopBlock)
Represents a while statement.
|
public static ReturnStatement returnS(Expression expression)
expression - ReturnStatementpublic static Statement stmt(Expression expression)
Statement. When declaring a MethodNode
the body is always whether a ReturnStatement if it returns something or just a Statement
if it's void.
// body of a void method
stmt(callThisX("println", constX("1")));
Result
println "1"expression - Statementpublic static Statement ctorSuperS(Expression... args)
Statement. This normally will be used to call to a super constructor
from the current class:
Statement callSuper = A.STMT
.ctorSuperS(
A.EXPR.constX(1),
A.EXPR.constX(2));
Result
super(1,2)args - Statementpublic static BlockStatement blockS(java.util.List<Statement> statements)
BlockStatement.statements - a list of type StatementBlockStatementpublic static BlockStatement blockS(Statement... statements)
BlockStatement.statements - a varargs of type StatementBlockStatementpublic static BlockStatement blockS(VariableScope variableScope, Statement... statements)
BlockStatement.variableScope - scope containing ref/local variablesstatements - a varargs of type StatementBlockStatementpublic static BlockStatement blockS(VariableScope variableScope, java.util.List<Statement> statements)
BlockStatement.variableScope - scope containing ref/local variablesstatements - a list of type StatementBlockStatementpublic static BlockStatement blockSFromString(java.lang.String code)
BlockStatement. The code contained
in the string passed as argument will be parsed and converted
to a BlockStatementcode - the string representation of the codeBlockStatementpublic static AssertStatement assertS(BooleanExpression booleanExpr)
booleanExpr - the expression we want to checkAssertStatementpublic static AssertStatement assertS(BooleanExpression booleanExpr, java.lang.String errorMessage)
AssertStatement
assertS(booleanExpr, "checking something important")
Result
assert 1 == 1 : "checking something important"booleanExpr - the expression we want to checkerrorMessage - the error message in case assertion failsAssertStatementpublic static TryCatchStatementBuilder tryCatchSBuilder()
TryCatchStatementBuilder to
build complex try/catch statements the easy way. Check TryCatchStatementBuilder javadoc to know how to use it.TryCatchStatementBuilderTryCatchStatementBuilderpublic static IfStatement ifS(BooleanExpression booleanExpr, Statement ifStmt)
ifS(boolX('a', Types.COMPARE_GREATER_THAN, 'b'), codeStmt)
Result
if (a > b) {
// content of the codeStmt statement
}booleanExpr - the boolean expression used to decide
whether the next statement will be executed or notifStmt - code that will be executed if the boolean
expression evaluates to true@Deprecated public static DoWhileStatement doWhileStatement(BooleanExpression booleanExpr, Statement loopBlock)
doWhileS(BooleanExpression, Statement)booleanExpr - boolean conditionloopBlock - the block that could be repeatedDoWhileStatementpublic static DoWhileStatement doWhileS(BooleanExpression booleanExpr, Statement loopBlock)
booleanExpr - boolean conditionloopBlock - the block that could be repeatedDoWhileStatementpublic static WhileStatement whileS(BooleanExpression booleanExpr, Statement loopBlock)
booleanExpr - boolean conditionloopBlock - the block that could be repeatedDoWhileStatementpublic static Statement emptyStatement()
emptyS()IfStatement with an empty else part.Statementpublic static Statement emptyS()
IfStatement with an empty else part.Statementpublic static IfStatement ifElseS(BooleanExpression booleanExpr, Statement ifStmt, Statement elseStmt)
ifElseS(boolX('a', Types.COMPARE_GREATER_THAN, 'b'), ifStmt, elseStmt)
Result
if (a > b) {
// ifStmt code
} else {
// elseStmt
}booleanExpr - the boolean expression used to decide
whether the next statement will be executed or notifStmt - code that will be executed if the boolean
expression evaluates to truepublic static ThrowStatement throwS(Expression expression)
throwS(newX(IllegalStateException, constX('wrong value')))
Result
throw new IllegalStateException('wrong value')expression - it will be normally a representation of a new
instance of a given Throwable typeThrowStatement