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
Switch statement builder. This wraps the AST switch representation with convenience methods and added control
information.
- Author:
- Dennis M. Sosnoski
-
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 TypeMethodDescriptionvoidAdd default case to switch statement.voidaddNamedCase(String name, StatementBuilderBase stmt) Add case to switch statement with a named constant as the match value.voidaddNumberCase(String value, StatementBuilderBase stmt) Add case to switch statement with a number as the match value.(package private) StatementGet 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.newNamedCase(String name) Add case to switch statement with returned block for code.newNumberCase(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
-
Field Details
-
m_switch
private final SwitchStatement m_switchMethod invocation.
-
-
Constructor Details
-
SwitchBuilder
Constructor.- Parameters:
source-expr- expression
-
-
Method Details
-
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
Add case to switch statement with a named constant as the match value.- Parameters:
name- named constantstmt- statement to be executed
-
addNumberCase
Add case to switch statement with a number as the match value.- Parameters:
value- match valuestmt- statement to be executed
-
addDefault
Add default case to switch statement.- Parameters:
stmt- statement to be executed
-
newCaseBlock
Add case to switch statement with new block for case code.- Parameters:
expr-- Returns:
- block
-
newNamedCase
Add case to switch statement with returned block for code.- Parameters:
name- named constant- Returns:
- block
-
newNumberCase
Add case to switch statement with returned block for code.- Parameters:
value- match value- Returns:
- block
-