Interface IJavaSwitch

All Superinterfaces:
IJavaCompound, IJavaElement, IJavaExpression, IJavaStatement

@Ser public interface IJavaSwitch extends IJavaCompound
Java AST interface to represent switch statements. They support integer keys (standard switch), String keys, and Enum keys. Limitation: These objects do not support case-block replacement.

A switch-statement consists of an expression, zero or more cases and an optional default case.

Example:

 switch(exp)
   case c0: b0
   case c1: b1
   default: b2
 
See Also:
  • Method Details

    • getSwitchType

      int getSwitchType()
      Returns:
      0=switch-on-int, 1=switch-on-enum, 2=switch-on-string
    • isSwitchOnInteger

      boolean isSwitchOnInteger()
      Returns:
    • isSwitchOnString

      boolean isSwitchOnString()
      Returns:
    • isSwitchOnEnum

      boolean isSwitchOnEnum()
      Returns:
    • getStringMap

      Map<Integer,String> getStringMap()
      Returns:
    • getEnumMap

      Map<Integer,String> getEnumMap()
      Returns:
    • getSwitchedExpression

      IJavaExpression getSwitchedExpression()
      Get the expression being switched on.
      Returns:
      the switch expression, never null
    • setSwitchedExpression

      void setSwitchedExpression(IJavaExpression e)
      Set the switch expression.
      Parameters:
      e - mandatory expression
    • getCaseKeys

      SortedSet<Integer> getCaseKeys()
      Get the list of case keys.
      Returns:
      the list of case keys
    • getCaseBodies

      List<IJavaBlock> getCaseBodies()
      Get the case bodies.
      Returns:
      the list of case bodies
    • getCaseBody

      IJavaBlock getCaseBody(int key)
      Get a case body by key.
      Parameters:
      key - case key
      Returns:
      the case body, null if there is no case for the given key
    • getCaseBody

      IJavaBlock getCaseBody(String stringkey)
      Parameters:
      stringkey -
      Returns:
    • hasDefaultBlock

      boolean hasDefaultBlock()
      Determine if the switch block has a default case.
      Returns:
      true if there is a default case
    • getDefaultBlock

      IJavaBlock getDefaultBlock()
      Get the default case block.
      Returns:
      the default case body, null if there is no default case
    • addCase

      void addCase(List<Integer> keys, IJavaBlock b)
      Add a case to the switch
      Parameters:
      keys - mandatory list of keys, this list must contain at least one element
      b - the case body
    • addCase

      void addCase(Map<Integer,String> casekeymap, IJavaBlock b)
      Parameters:
      casekeymap -
      b -
    • setDefaultBlock

      void setDefaultBlock(IJavaBlock b)
      Set the default case block for the switch.
      Parameters:
      b - optional default case body, null to remove the default case
    • replaceSubElement

      boolean replaceSubElement(IJavaElement oldElement, IJavaElement newElement)
      Note: case-replacements are currently not supported.
      Specified by:
      replaceSubElement in interface IJavaElement
      Parameters:
      oldElement - the element to be replaced
      newElement - the new element
      Returns:
    • convertToSwitchOnInteger

      void convertToSwitchOnInteger(IJavaExpression updatedSwitchedOnValue)
      Parameters:
      updatedSwitchedOnValue -
    • convertToSwitchOnString

      void convertToSwitchOnString(IJavaExpression updatedSwitchedOnValue, Map<Integer,String> indexToStringMap)
      Parameters:
      updatedSwitchedOnValue -
      indexToStringMap -
    • convertToSwitchOnEnum

      void convertToSwitchOnEnum(IJavaExpression updatedSwitchedOnValue, Map<Integer,String> enummap)
      Parameters:
      updatedSwitchedOnValue -
      enummap -
    • duplicate

      IJavaSwitch duplicate()
      Description copied from interface: IJavaElement
      Duplicate this element.
      Specified by:
      duplicate in interface IJavaCompound
      Specified by:
      duplicate in interface IJavaElement
      Specified by:
      duplicate in interface IJavaExpression
      Specified by:
      duplicate in interface IJavaStatement
      Returns:
      a (possibly) duplicated object of the same type
    • reset

      void reset(int type)
      Reset this switch to a potentially different switch type. This is a specialized version of IJavaCompound.reset().
      Parameters:
      type - 0=switch-on-int; 1=switch-on-enum; 2=switch-on-string