Package org.jibx.schema.codegen
Class BlockBuilder
java.lang.Object
org.jibx.schema.codegen.ASTBuilderBase
org.jibx.schema.codegen.StatementBuilderBase
org.jibx.schema.codegen.BlockBuilder
Block builder. This wraps the AST block representation with convenience methods and added control information.
-
Field Summary
FieldsFields inherited from class org.jibx.schema.codegen.StatementBuilderBase
m_sourceFields inherited from class org.jibx.schema.codegen.ASTBuilderBase
m_ast -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAssignToName(Expression expr, String name) Append an assignment from an expression to a field or local variable.voidaddAssignVariableToField(String vname, String fname) Append an assignment from a local variable to a field.voidaddBreak()Append a 'break' statement.voidaddCall(InvocationBuilder call) Append a method call statement.voidAppend an expression statement.private voidaddForStatement(String name, Type type, Expression init, Expression test, Expression post, BlockBuilder block) Append a three-part 'for' statement with an associated variable.voidaddIfElseIfStatement(ExpressionBuilderBase ifexpr, ExpressionBuilderBase elsexpr, BlockBuilder ifblock, BlockBuilder elseblock) Append an 'if-else-if' statement.voidaddIfElseStatement(ExpressionBuilderBase expr, BlockBuilder ifblock, BlockBuilder elseblock) Append an 'if-else' statement.voidaddIfStatement(ExpressionBuilderBase expr, BlockBuilder ifblock) Append a simple 'if' statement (no else).voidaddIndexedForStatement(String name, String array, BlockBuilder block) Append a standard 'for' statement using an index variable over an array.voidaddIteratedForStatement(String name, Type type, ExpressionBuilderBase init, BlockBuilder block) Append a standard 'for' statement using an iterator.voidaddLocalVariableDeclaration(String type, String vname) Append a local variable declaration.voidaddLocalVariableDeclaration(Type type, String vname, ExpressionBuilderBase expr) Append a local variable declaration with initializer expression.voidAppend a statement returning the value of an expression.voidaddReturnNamed(String name) Append a statement returning the value of a field or local variable.voidAppend a statement returningnull.voidAppend a constructed statement.voidaddSugaredForStatement(String name, String type, ExpressionBuilderBase expr, BlockBuilder block) Append a Java 5 "enhanced" 'for' statement.Append a 'switch' statement using a local variable or field name as the switch value.Append a 'switch' statement using a constructed expression as the switch value.voidaddThrowException(String type, String text) Append a throw new exception statement.voidaddThrowException(String type, ExpressionBuilderBase expr) Append a throw new exception statement.(package private) StatementGet the statement.Methods inherited from class org.jibx.schema.codegen.ASTBuilderBase
numberLiteral, setFinal, setPrivate, setPrivateFinal, setPrivateStaticFinal, setPublic, setPublicStatic, setPublicStaticFinal, setStatic, stringLiteral
-
Field Details
-
m_block
private final Block m_blockCompilation unit.
-
-
Constructor Details
-
BlockBuilder
Constructor.- Parameters:
source-block-
-
-
Method Details
-
getStatement
Statement getStatement()Get the statement.- Specified by:
getStatementin classStatementBuilderBase- Returns:
- statement
-
addAssignToName
Append an assignment from an expression to a field or local variable.- Parameters:
expr-name-
-
addAssignVariableToField
Append an assignment from a local variable to a field. This handles the case where the local variable name is the same as the field name.- Parameters:
vname-fname-
-
addLocalVariableDeclaration
Append a local variable declaration.- Parameters:
type-vname-
-
addLocalVariableDeclaration
Append a local variable declaration with initializer expression. This variation takes the actual type as a parameter.- Parameters:
type-vname-expr- initializer expression
-
addIfStatement
Append a simple 'if' statement (no else).- Parameters:
expr- conditional expressionifblock- block executed when conditiontrue
-
addIfElseStatement
public void addIfElseStatement(ExpressionBuilderBase expr, BlockBuilder ifblock, BlockBuilder elseblock) Append an 'if-else' statement.- Parameters:
expr- conditional expressionifblock- block executed when conditiontrueelseblock- block executed when conditionfalse
-
addIfElseIfStatement
public void addIfElseIfStatement(ExpressionBuilderBase ifexpr, ExpressionBuilderBase elsexpr, BlockBuilder ifblock, BlockBuilder elseblock) Append an 'if-else-if' statement.- Parameters:
ifexpr- if conditional expressionelsexpr- if conditional expressionifblock- block executed when conditiontrueelseblock- block executed when conditionfalse
-
addForStatement
private void addForStatement(String name, Type type, Expression init, Expression test, Expression post, BlockBuilder block) Append a three-part 'for' statement with an associated variable. This assumes the first part is a local variable declaration with an initializer expression, while the other two parts are just expressions.- Parameters:
name- iteration variable nametype- variable typeinit- variable initialization expressiontest- loop test expression (second part of 'for')post- post-loop expression (optional third part of 'for',nullif none)block- statement body block
-
addIteratedForStatement
public void addIteratedForStatement(String name, Type type, ExpressionBuilderBase init, BlockBuilder block) Append a standard 'for' statement using an iterator.- Parameters:
name- iteration variable nametype- variable type (must be an iterator subclass or generic type)init- variable initialization expressionblock- statement body block
-
addIndexedForStatement
Append a standard 'for' statement using an index variable over an array. The index is always initialized to '0', and incremented each time the loop is executed until the size of the array is reached.- Parameters:
name- index variable namearray- array nameblock- statement body block
-
addSugaredForStatement
public void addSugaredForStatement(String name, String type, ExpressionBuilderBase expr, BlockBuilder block) Append a Java 5 "enhanced" 'for' statement.- Parameters:
name- iteration variable nametype- iteration variable typeexpr- iteration source expressionblock- statement body block
-
addReturnExpression
Append a statement returning the value of an expression.- Parameters:
expr- expression
-
addReturnNamed
Append a statement returning the value of a field or local variable.- Parameters:
name- field name
-
addReturnNull
public void addReturnNull()Append a statement returningnull. -
addThrowException
Append a throw new exception statement.- Parameters:
type- exception typetext-
-
addThrowException
Append a throw new exception statement.- Parameters:
type- exception typeexpr- initializer expression
-
addCall
Append a method call statement.- Parameters:
call-
-
addBreak
public void addBreak()Append a 'break' statement. -
addSwitch
Append a 'switch' statement using a local variable or field name as the switch value.- Parameters:
name-- Returns:
- statement builder
-
addSwitch
Append a 'switch' statement using a constructed expression as the switch value.- Parameters:
expr-- Returns:
- statement builder
-
addExpressionStatement
Append an expression statement.- Parameters:
expr-
-
addStatement
Append a constructed statement.- Parameters:
stmt-
-