Package org.jibx.schema.codegen
Class SwitchBuilder
- java.lang.Object
-
- org.jibx.schema.codegen.ASTBuilderBase
-
- org.jibx.schema.codegen.StatementBuilderBase
-
- org.jibx.schema.codegen.SwitchBuilder
-
public class SwitchBuilder extends StatementBuilderBase
Switch statement builder. This wraps the AST switch representation with convenience methods and added control information.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description private SwitchStatementm_switchMethod invocation.-
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 SwitchBuilder(ClassBuilder source, Expression expr)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDefault(StatementBuilderBase stmt)Add default case to switch statement.voidaddNamedCase(java.lang.String name, StatementBuilderBase stmt)Add case to switch statement with a named constant as the match value.voidaddNumberCase(java.lang.String value, StatementBuilderBase stmt)Add case to switch statement with a number as the match value.(package private) StatementgetStatement()Get the statement.private static booleanisBreakNeeded(Statement stmt)Check if a break statement is needed following the statement for a particular case.private BlockBuildernewCaseBlock(Expression expr)Add case to switch statement with new block for case code.BlockBuildernewNamedCase(java.lang.String name)Add case to switch statement with returned block for code.BlockBuildernewNumberCase(java.lang.String value)Add case to switch statement with returned block for code.-
Methods inherited from class org.jibx.schema.codegen.ASTBuilderBase
numberLiteral, setFinal, setPrivate, setPrivateFinal, setPrivateStaticFinal, setPublic, setPublicStatic, setPublicStaticFinal, setStatic, stringLiteral
-
-
-
-
Constructor Detail
-
SwitchBuilder
public SwitchBuilder(ClassBuilder source, Expression expr)
Constructor.- Parameters:
source-expr- expression
-
-
Method Detail
-
getStatement
Statement getStatement()
Get the statement.- Specified by:
getStatementin classStatementBuilderBase- Returns:
- statement
-
isBreakNeeded
private static boolean isBreakNeeded(Statement stmt)
Check if a break statement is needed following the statement for a particular case.- Parameters:
stmt-- Returns:
trueif break needed,falseif not
-
addNamedCase
public void addNamedCase(java.lang.String name, StatementBuilderBase stmt)Add case to switch statement with a named constant as the match value.- Parameters:
name- named constantstmt- statement to be executed
-
addNumberCase
public void addNumberCase(java.lang.String value, StatementBuilderBase stmt)Add case to switch statement with a number as the match value.- Parameters:
value- match valuestmt- statement to be executed
-
addDefault
public void addDefault(StatementBuilderBase stmt)
Add default case to switch statement.- Parameters:
stmt- statement to be executed
-
newCaseBlock
private BlockBuilder newCaseBlock(Expression expr)
Add case to switch statement with new block for case code.- Parameters:
expr-- Returns:
- block
-
newNamedCase
public BlockBuilder newNamedCase(java.lang.String name)
Add case to switch statement with returned block for code.- Parameters:
name- named constant- Returns:
- block
-
newNumberCase
public BlockBuilder newNumberCase(java.lang.String value)
Add case to switch statement with returned block for code.- Parameters:
value- match value- Returns:
- block
-
-