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 SwitchStatement
m_switch
Method 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 void
addDefault(StatementBuilderBase stmt)
Add default case to switch statement.void
addNamedCase(java.lang.String name, StatementBuilderBase stmt)
Add case to switch statement with a named constant as the match value.void
addNumberCase(java.lang.String value, StatementBuilderBase stmt)
Add case to switch statement with a number as the match value.(package private) Statement
getStatement()
Get the statement.private static boolean
isBreakNeeded(Statement stmt)
Check if a break statement is needed following the statement for a particular case.private BlockBuilder
newCaseBlock(Expression expr)
Add case to switch statement with new block for case code.BlockBuilder
newNamedCase(java.lang.String name)
Add case to switch statement with returned block for code.BlockBuilder
newNumberCase(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:
getStatement
in 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:
true
if break needed,false
if 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
-
-