Class 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 Details

    • m_switch

      private final SwitchStatement m_switch
      Method invocation.
  • Constructor Details

    • SwitchBuilder

      public SwitchBuilder(ClassBuilder source, Expression expr)
      Constructor.
      Parameters:
      source -
      expr - expression
  • Method Details

    • getStatement

      Statement getStatement()
      Get the statement.
      Specified by:
      getStatement in class StatementBuilderBase
      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(String name, StatementBuilderBase stmt)
      Add case to switch statement with a named constant as the match value.
      Parameters:
      name - named constant
      stmt - statement to be executed
    • addNumberCase

      public void addNumberCase(String value, StatementBuilderBase stmt)
      Add case to switch statement with a number as the match value.
      Parameters:
      value - match value
      stmt - 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(String name)
      Add case to switch statement with returned block for code.
      Parameters:
      name - named constant
      Returns:
      block
    • newNumberCase

      public BlockBuilder newNumberCase(String value)
      Add case to switch statement with returned block for code.
      Parameters:
      value - match value
      Returns:
      block