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_source
Fields inherited from class org.jibx.schema.codegen.ASTBuilderBase
m_ast
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAssignToName
(Expression expr, String name) Append an assignment from an expression to a field or local variable.void
addAssignVariableToField
(String vname, String fname) Append an assignment from a local variable to a field.void
addBreak()
Append a 'break' statement.void
addCall
(InvocationBuilder call) Append a method call statement.void
Append an expression statement.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.void
addIfElseIfStatement
(ExpressionBuilderBase ifexpr, ExpressionBuilderBase elsexpr, BlockBuilder ifblock, BlockBuilder elseblock) Append an 'if-else-if' statement.void
addIfElseStatement
(ExpressionBuilderBase expr, BlockBuilder ifblock, BlockBuilder elseblock) Append an 'if-else' statement.void
addIfStatement
(ExpressionBuilderBase expr, BlockBuilder ifblock) Append a simple 'if' statement (no else).void
addIndexedForStatement
(String name, String array, BlockBuilder block) Append a standard 'for' statement using an index variable over an array.void
addIteratedForStatement
(String name, Type type, ExpressionBuilderBase init, BlockBuilder block) Append a standard 'for' statement using an iterator.void
addLocalVariableDeclaration
(String type, String vname) Append a local variable declaration.void
addLocalVariableDeclaration
(Type type, String vname, ExpressionBuilderBase expr) Append a local variable declaration with initializer expression.void
Append a statement returning the value of an expression.void
addReturnNamed
(String name) Append a statement returning the value of a field or local variable.void
Append a statement returningnull
.void
Append a constructed statement.void
addSugaredForStatement
(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.void
addThrowException
(String type, String text) Append a throw new exception statement.void
addThrowException
(String type, ExpressionBuilderBase expr) Append a throw new exception statement.(package private) Statement
Get 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:
getStatement
in 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 conditiontrue
elseblock
- 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 conditiontrue
elseblock
- 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',null
if 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
-
-