Interface IJavaSwitch
- All Superinterfaces:
IJavaCompound,IJavaElement,IJavaExpression,IJavaStatement
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:
-
Field Summary
Fields inherited from interface com.pnfsoftware.jeb.core.units.code.java.IJavaElement
FLAG_BUILT, FLAG_FIELD_REFERENCES_OUTERCLASS, FLAG_LAMBDA_CLASS, FLAG_LAMBDA_IMPL, FLAG_OPTIONAL_RENDERING, FLAG_SECOND_PARAMETER_IS_OUTER_REF, FLAG_STICKY -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCase(List<Integer> keys, IJavaBlock b) Add a case to the switchvoidaddCase(Map<Integer, String> casekeymap, IJavaBlock b) voidconvertToSwitchOnEnum(IJavaExpression updatedSwitchedOnValue, Map<Integer, String> enummap) voidconvertToSwitchOnInteger(IJavaExpression updatedSwitchedOnValue) voidconvertToSwitchOnString(IJavaExpression updatedSwitchedOnValue, Map<Integer, String> indexToStringMap) Duplicate this element.Get the case bodies.getCaseBody(int key) Get a case body by key.getCaseBody(String stringkey) Get the list of case keys.Get the default case block.Get the expression being switched on.intbooleanDetermine if the switch block has a default case.booleanbooleanbooleanbooleanreplaceSubElement(IJavaElement oldElement, IJavaElement newElement) Note: case-replacements are currently not supported.voidreset(int type) Reset this switch to a potentially different switch type.voidSet the default case block for the switch.voidSet the switch expression.Methods inherited from interface com.pnfsoftware.jeb.core.units.code.java.IJavaCompound
generateFlatList, getBlocks, getSubElements, insertAt, resetMethods inherited from interface com.pnfsoftware.jeb.core.units.code.java.IJavaElement
addFlags, addTag, canCauseException, collectAllPhysicalOffsets, generate, getData, getElementType, getFlags, getOrigin, getPhysicalMethodIndex, getPhysicalOffset, getReconAnon, getReconEnum, getReconEnummap, getReconLambda, getSubElements, getTags, hasFlags, hasPhysicalMethodIndex, hasPhysicalOffset, isReconArtifact, removeFlags, removeTag, setData, setFlags, setLambdaRecon, setOrigin, setPhysicalMethodIndex, setPhysicalOffset, setReconAnon, setReconEnum, setReconEnummap, toShortString, visitDepthPost, visitDepthPost, visitDepthPost, visitDepthPost, visitDepthPre, visitDepthPre, visitDepthPreMethods inherited from interface com.pnfsoftware.jeb.core.units.code.java.IJavaStatement
getIntermediateOffset, setIntermediateOffset
-
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
- Returns:
-
getEnumMap
- Returns:
-
getSwitchedExpression
IJavaExpression getSwitchedExpression()Get the expression being switched on.- Returns:
- the switch expression, never null
-
setSwitchedExpression
Set the switch expression.- Parameters:
e- mandatory expression
-
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
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
- 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
Add a case to the switch- Parameters:
keys- mandatory list of keys, this list must contain at least one elementb- the case body
-
addCase
- Parameters:
casekeymap-b-
-
setDefaultBlock
Set the default case block for the switch.- Parameters:
b- optional default case body, null to remove the default case
-
replaceSubElement
Note: case-replacements are currently not supported.- Specified by:
replaceSubElementin interfaceIJavaElement- Parameters:
oldElement- the element to be replacednewElement- the new element- Returns:
-
convertToSwitchOnInteger
- Parameters:
updatedSwitchedOnValue-
-
convertToSwitchOnString
void convertToSwitchOnString(IJavaExpression updatedSwitchedOnValue, Map<Integer, String> indexToStringMap) - Parameters:
updatedSwitchedOnValue-indexToStringMap-
-
convertToSwitchOnEnum
- Parameters:
updatedSwitchedOnValue-enummap-
-
duplicate
IJavaSwitch duplicate()Description copied from interface:IJavaElementDuplicate this element.- Specified by:
duplicatein interfaceIJavaCompound- Specified by:
duplicatein interfaceIJavaElement- Specified by:
duplicatein interfaceIJavaExpression- Specified by:
duplicatein interfaceIJavaStatement- 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 ofIJavaCompound.reset().- Parameters:
type- 0=switch-on-int; 1=switch-on-enum; 2=switch-on-string
-