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
-
public class BlockBuilder extends StatementBuilderBase
Block builder. This wraps the AST block representation with convenience methods and added control information.
-
-
Field Summary
Fields Modifier and Type Field Description private Blockm_blockCompilation unit.-
Fields inherited from class org.jibx.schema.codegen.StatementBuilderBase
m_source
-
Fields inherited from class org.jibx.schema.codegen.ASTBuilderBase
m_ast
-
-
Constructor Summary
Constructors Constructor Description BlockBuilder(ClassBuilder source, Block block)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAssignToName(Expression expr, java.lang.String name)Append an assignment from an expression to a field or local variable.voidaddAssignVariableToField(java.lang.String vname, java.lang.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.voidaddExpressionStatement(ExpressionBuilderBase expr)Append an expression statement.private voidaddForStatement(java.lang.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(java.lang.String name, java.lang.String array, BlockBuilder block)Append a standard 'for' statement using an index variable over an array.voidaddIteratedForStatement(java.lang.String name, Type type, ExpressionBuilderBase init, BlockBuilder block)Append a standard 'for' statement using an iterator.voidaddLocalVariableDeclaration(java.lang.String type, java.lang.String vname)Append a local variable declaration.voidaddLocalVariableDeclaration(Type type, java.lang.String vname, ExpressionBuilderBase expr)Append a local variable declaration with initializer expression.voidaddReturnExpression(ExpressionBuilderBase expr)Append a statement returning the value of an expression.voidaddReturnNamed(java.lang.String name)Append a statement returning the value of a field or local variable.voidaddReturnNull()Append a statement returningnull.voidaddStatement(StatementBuilderBase stmt)Append a constructed statement.voidaddSugaredForStatement(java.lang.String name, java.lang.String type, ExpressionBuilderBase expr, BlockBuilder block)Append a Java 5 "enhanced" 'for' statement.SwitchBuilderaddSwitch(java.lang.String name)Append a 'switch' statement using a local variable or field name as the switch value.SwitchBuilderaddSwitch(ExpressionBuilderBase expr)Append a 'switch' statement using a constructed expression as the switch value.voidaddThrowException(java.lang.String type, java.lang.String text)Append a throw new exception statement.voidaddThrowException(java.lang.String type, ExpressionBuilderBase expr)Append a throw new exception statement.(package private) StatementgetStatement()Get the statement.-
Methods inherited from class org.jibx.schema.codegen.ASTBuilderBase
numberLiteral, setFinal, setPrivate, setPrivateFinal, setPrivateStaticFinal, setPublic, setPublicStatic, setPublicStaticFinal, setStatic, stringLiteral
-
-
-
-
Constructor Detail
-
BlockBuilder
public BlockBuilder(ClassBuilder source, Block block)
Constructor.- Parameters:
source-block-
-
-
Method Detail
-
getStatement
Statement getStatement()
Get the statement.- Specified by:
getStatementin classStatementBuilderBase- Returns:
- statement
-
addAssignToName
public void addAssignToName(Expression expr, java.lang.String name)Append an assignment from an expression to a field or local variable.- Parameters:
expr-name-
-
addAssignVariableToField
public void addAssignVariableToField(java.lang.String vname, java.lang.String fname)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
public void addLocalVariableDeclaration(java.lang.String type, java.lang.String vname)Append a local variable declaration.- Parameters:
type-vname-
-
addLocalVariableDeclaration
public void addLocalVariableDeclaration(Type type, java.lang.String vname, ExpressionBuilderBase expr)Append a local variable declaration with initializer expression. This variation takes the actual type as a parameter.- Parameters:
type-vname-expr- initializer expression
-
addIfStatement
public void addIfStatement(ExpressionBuilderBase expr, BlockBuilder ifblock)
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(java.lang.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(java.lang.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
public void addIndexedForStatement(java.lang.String name, java.lang.String array, BlockBuilder block)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(java.lang.String name, java.lang.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
public void addReturnExpression(ExpressionBuilderBase expr)
Append a statement returning the value of an expression.- Parameters:
expr- expression
-
addReturnNamed
public void addReturnNamed(java.lang.String name)
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
public void addThrowException(java.lang.String type, java.lang.String text)Append a throw new exception statement.- Parameters:
type- exception typetext-
-
addThrowException
public void addThrowException(java.lang.String type, ExpressionBuilderBase expr)Append a throw new exception statement.- Parameters:
type- exception typeexpr- initializer expression
-
addCall
public void addCall(InvocationBuilder call)
Append a method call statement.- Parameters:
call-
-
addBreak
public void addBreak()
Append a 'break' statement.
-
addSwitch
public SwitchBuilder addSwitch(java.lang.String name)
Append a 'switch' statement using a local variable or field name as the switch value.- Parameters:
name-- Returns:
- statement builder
-
addSwitch
public SwitchBuilder addSwitch(ExpressionBuilderBase expr)
Append a 'switch' statement using a constructed expression as the switch value.- Parameters:
expr-- Returns:
- statement builder
-
addExpressionStatement
public void addExpressionStatement(ExpressionBuilderBase expr)
Append an expression statement.- Parameters:
expr-
-
addStatement
public void addStatement(StatementBuilderBase stmt)
Append a constructed statement.- Parameters:
stmt-
-
-