Package asteroid
Class Statements
- java.lang.Object
-
- asteroid.Statements
-
public final class Statements extends Object
This class hides the different implementations to create expressions through the Groovy api to provide a unified an easier way to create statements when coding an AST transformation.- Since:
- 0.1.0
-
-
Constructor Summary
Constructors Constructor Description Statements()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static AssertStatementassertS(BooleanExpression booleanExpr)static AssertStatementassertS(BooleanExpression booleanExpr, String errorMessage)static BlockStatementblockS(List<Statement> statements)Returns an instance ofBlockStatement.static BlockStatementblockS(Statement... statements)Returns an instance ofBlockStatement.static BlockStatementblockS(VariableScope variableScope, List<Statement> statements)Returns an instance ofBlockStatement.static BlockStatementblockS(VariableScope variableScope, Statement... statements)Returns an instance ofBlockStatement.static BlockStatementblockSFromString(String code)Returns an instance ofBlockStatement.static StatementctorSuperS(Expression... args)Returns an instance ofStatement.static DoWhileStatementdoWhileS(BooleanExpression booleanExpr, Statement loopBlock)Represents a do-while statement.static DoWhileStatementdoWhileStatement(BooleanExpression booleanExpr, Statement loopBlock)Deprecated.As of release 2.4.7, replaced bydoWhileS(BooleanExpression, Statement)static StatementemptyS()Represents an empty statement.static StatementemptyStatement()Deprecated.As of release 2.4.7, replaced byemptyS()static IfStatementifElseS(BooleanExpression booleanExpr, Statement ifStmt, Statement elseStmt)Builds a if-else statement.static IfStatementifS(BooleanExpression booleanExpr, Statement ifStmt)Builds a if statement, without the else part.static ReturnStatementreturnS(Expression expression)static Statementstmt(Expression expression)Returns an instance ofStatement.static ThrowStatementthrowS(Expression expression)Represents how to throw an exception ASTstatic TryCatchStatementBuildertryCatchSBuilder()Returns an instance ofTryCatchStatementBuilderto build complex try/catch statements the easy way.static WhileStatementwhileS(BooleanExpression booleanExpr, Statement loopBlock)Represents a while statement.
-
-
-
Method Detail
-
returnS
public static ReturnStatement returnS(Expression expression)
- Parameters:
expression-- Returns:
- an instance of
ReturnStatement - Since:
- 0.1.0
-
stmt
public static Statement stmt(Expression expression)
Returns an instance ofStatement. When declaring aMethodNodethe body is always whether aReturnStatementif it returns something or just aStatementif it's void.
AST
Result// body of a void method stmt(callThisX("println", constX("1")));println "1"- Parameters:
expression-- Returns:
- an instance of
Statement - Since:
- 0.1.0
-
ctorSuperS
public static Statement ctorSuperS(Expression... args)
Returns an instance ofStatement. This normally will be used to call to a super constructor from the current class:
AST
ResultStatement callSuper = A.STMT .ctorSuperS( A.EXPR.constX(1), A.EXPR.constX(2));super(1,2)- Parameters:
args-- Returns:
- an instance of type
Statement - Since:
- 0.1.0
-
blockS
public static BlockStatement blockS(List<Statement> statements)
Returns an instance ofBlockStatement.- Parameters:
statements- a list of type Statement- Returns:
- an instance of
BlockStatement - Since:
- 0.1.0
-
blockS
public static BlockStatement blockS(Statement... statements)
Returns an instance ofBlockStatement.- Parameters:
statements- a varargs of type Statement- Returns:
- an instance of
BlockStatement - Since:
- 0.1.0
-
blockS
public static BlockStatement blockS(VariableScope variableScope, Statement... statements)
Returns an instance ofBlockStatement.- Parameters:
variableScope- scope containing ref/local variablesstatements- a varargs of type Statement- Returns:
- an instance of
BlockStatement - Since:
- 0.1.5
-
blockS
public static BlockStatement blockS(VariableScope variableScope, List<Statement> statements)
Returns an instance ofBlockStatement.- Parameters:
variableScope- scope containing ref/local variablesstatements- a list of type Statement- Returns:
- an instance of
BlockStatement - Since:
- 0.1.5
-
blockSFromString
public static BlockStatement blockSFromString(String code)
Returns an instance ofBlockStatement. The code contained in the string passed as argument will be parsed and converted to aBlockStatement- Parameters:
code- the string representation of the code- Returns:
- an instance of
BlockStatement - Since:
- 0.1.0
-
assertS
public static AssertStatement assertS(BooleanExpression booleanExpr)
- Parameters:
booleanExpr- the expression we want to check- Returns:
- an instance of
AssertStatement - Since:
- 0.1.5
-
assertS
public static AssertStatement assertS(BooleanExpression booleanExpr, String errorMessage)
Returns an instance ofAssertStatement
AST
ResultassertS(booleanExpr, "checking something important")assert 1 == 1 : "checking something important"- Parameters:
booleanExpr- the expression we want to checkerrorMessage- the error message in case assertion fails- Returns:
- an instance of
AssertStatement - Since:
- 0.1.5
-
tryCatchSBuilder
public static TryCatchStatementBuilder tryCatchSBuilder()
Returns an instance ofTryCatchStatementBuilderto build complex try/catch statements the easy way. CheckTryCatchStatementBuilderjavadoc to know how to use it.- Returns:
- an instance of
TryCatchStatementBuilder - Since:
- 0.2.3
- See Also:
TryCatchStatementBuilder
-
ifS
public static IfStatement ifS(BooleanExpression booleanExpr, Statement ifStmt)
Builds a if statement, without the else part. It receives a boolean expression and the code executed in case the boolean expression evaluates to true
AST
ResultifS(boolX('a', Types.COMPARE_GREATER_THAN, 'b'), codeStmt)if (a > b) { // content of the codeStmt statement }- Parameters:
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- Since:
- 0.2.4
-
doWhileStatement
@Deprecated public static DoWhileStatement doWhileStatement(BooleanExpression booleanExpr, Statement loopBlock)
Deprecated.As of release 2.4.7, replaced bydoWhileS(BooleanExpression, Statement)Represents a do-while statement. A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block- Parameters:
booleanExpr- boolean conditionloopBlock- the block that could be repeated- Returns:
- an instance of type
DoWhileStatement - Since:
- 0.2.6
-
doWhileS
public static DoWhileStatement doWhileS(BooleanExpression booleanExpr, Statement loopBlock)
Represents a do-while statement. A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block- Parameters:
booleanExpr- boolean conditionloopBlock- the block that could be repeated- Returns:
- an instance of type
DoWhileStatement - Since:
- 0.2.7
-
whileS
public static WhileStatement whileS(BooleanExpression booleanExpr, Statement loopBlock)
Represents a while statement. A while loop is a control flow statement that executes maybe repeatedly a code block, depending on a given boolean condition.- Parameters:
booleanExpr- boolean conditionloopBlock- the block that could be repeated- Returns:
- an instance of type
DoWhileStatement - Since:
- 0.2.7
-
emptyStatement
public static Statement emptyStatement()
Deprecated.As of release 2.4.7, replaced byemptyS()Represents an empty statement. It could be used when building anIfStatementwith an empty else part.- Returns:
- an empty
Statement - Since:
- 0.2.4
-
emptyS
public static Statement emptyS()
Represents an empty statement. It could be used when building anIfStatementwith an empty else part.- Returns:
- an empty
Statement - Since:
- 0.2.7
-
ifElseS
public static IfStatement ifElseS(BooleanExpression booleanExpr, Statement ifStmt, Statement elseStmt)
Builds a if-else statement. It receives a boolean expression and two statements corresponding to the both if and else parts
AST
ResultifElseS(boolX('a', Types.COMPARE_GREATER_THAN, 'b'), ifStmt, elseStmt)if (a > b) { // ifStmt code } else { // elseStmt }- Parameters:
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- Since:
- 0.2.4
-
throwS
public static ThrowStatement throwS(Expression expression)
Represents how to throw an exception AST
ResultthrowS(newX(IllegalStateException, constX('wrong value')))throw new IllegalStateException('wrong value')- Parameters:
expression- it will be normally a representation of a new instance of a given Throwable type- Returns:
- an instance of
ThrowStatement - Since:
- 0.2.4
-
-