public interface

IJavaSwitch

implements IJavaCompound
com.pnfsoftware.jeb.core.units.code.java.IJavaSwitch

Class Overview

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

Summary

[Expand]
Inherited Constants
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaElement
Public Methods
abstract void addCase(List<Integer> keys, IJavaBlock b)
Add a case to the switch
abstract void addCase(Map<Integer, String> casekeymap, IJavaBlock b)
abstract void convertToSwitchOnEnum(IJavaExpression updatedSwitchedOnValue, Map<Integer, String> enummap)
abstract void convertToSwitchOnInteger(IJavaExpression updatedSwitchedOnValue)
abstract void convertToSwitchOnString(IJavaExpression updatedSwitchedOnValue, Map<Integer, String> indexToStringMap)
abstract IJavaSwitch duplicate()
Duplicate this element.
abstract List<IJavaBlock> getCaseBodies()
Get the case bodies.
abstract IJavaBlock getCaseBody(String stringkey)
abstract IJavaBlock getCaseBody(int key)
Get a case body by key.
abstract SortedSet<Integer> getCaseKeys()
Get the list of case keys.
abstract IJavaBlock getDefaultBlock()
Get the default case block.
abstract IJavaBlock getDefaultBody()
This method is deprecated. use getDefaultBlock()
abstract Map<Integer, String> getEnumMap()
abstract Map<Integer, String> getStringMap()
abstract int getSwitchType()
abstract IJavaExpression getSwitchedExpression()
Get the expression being switched on.
abstract boolean hasDefaultBlock()
Determine if the switch block has a default case.
abstract boolean hasDefaultBody()
This method is deprecated. use hasDefaultBlock()
abstract boolean isSwitchOnEnum()
abstract boolean isSwitchOnInteger()
abstract boolean isSwitchOnString()
abstract boolean replaceSubElement(IJavaElement oldElement, IJavaElement newElement)
Note: case-replacements are currently not supported.
abstract void setDefaultBlock(IJavaBlock b)
Set the default case block for the switch.
abstract void setDefaultBody(IJavaBlock b)
This method is deprecated. use setDefaultBlock(IJavaBlock)
abstract void setSwitchedExpression(IJavaExpression e)
Set the switch expression.
[Expand]
Inherited Methods
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaCompound
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaElement
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaExpression
From interface com.pnfsoftware.jeb.core.units.code.java.IJavaStatement

Public Methods

public abstract 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

public abstract void addCase (Map<Integer, String> casekeymap, IJavaBlock b)

public abstract void convertToSwitchOnEnum (IJavaExpression updatedSwitchedOnValue, Map<Integer, String> enummap)

public abstract void convertToSwitchOnInteger (IJavaExpression updatedSwitchedOnValue)

public abstract void convertToSwitchOnString (IJavaExpression updatedSwitchedOnValue, Map<Integer, String> indexToStringMap)

public abstract IJavaSwitch duplicate ()

Duplicate this element.

Returns
  • a (possibly) duplicated object of the same type

public abstract List<IJavaBlock> getCaseBodies ()

Get the case bodies.

Returns
  • the list of case bodies

public abstract IJavaBlock getCaseBody (String stringkey)

public abstract 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

public abstract SortedSet<Integer> getCaseKeys ()

Get the list of case keys.

Returns
  • the list of case keys

public abstract IJavaBlock getDefaultBlock ()

Get the default case block.

Returns
  • the default case body, null if there is no default case

public abstract IJavaBlock getDefaultBody ()

This method is deprecated.
use getDefaultBlock()

public abstract Map<Integer, String> getEnumMap ()

public abstract Map<Integer, String> getStringMap ()

public abstract int getSwitchType ()

Returns
  • 0=switch-on-int, 1=switch-on-enum, 2=switch-on-string

public abstract IJavaExpression getSwitchedExpression ()

Get the expression being switched on.

Returns
  • the switch expression, never null

public abstract boolean hasDefaultBlock ()

Determine if the switch block has a default case.

Returns
  • true if there is a default case

public abstract boolean hasDefaultBody ()

This method is deprecated.
use hasDefaultBlock()

public abstract boolean isSwitchOnEnum ()

public abstract boolean isSwitchOnInteger ()

public abstract boolean isSwitchOnString ()

public abstract boolean replaceSubElement (IJavaElement oldElement, IJavaElement newElement)

Note: case-replacements are currently not supported.

Parameters
oldElement the element to be replaced
newElement the new element

public abstract void setDefaultBlock (IJavaBlock b)

Set the default case block for the switch.

Parameters
b optional default case body, null to remove the default case

public abstract void setDefaultBody (IJavaBlock b)

This method is deprecated.
use setDefaultBlock(IJavaBlock)

public abstract void setSwitchedExpression (IJavaExpression e)

Set the switch expression.

Parameters
e mandatory expression