Interface IJavaIf
- All Superinterfaces:
IJavaCompound,IJavaElement,IJavaExpression,IJavaStatement
Java AST interface to represent a conditional "if" statement.
An if-statement consists of one or more branches (if, else-if) followed by an optional default branch (else) block.
Example:
if(p) b else if(p1) b1 else b2
-
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 TypeMethodDescriptionvoidAdd an alternative block (if or else-if) to this element.Duplicate this element.getBranchBody(int index) Get a branch (if, else-if) body.getBranchPredicate(int index) Get a branch (if, else-if) predicate.Get the predicates.Get the default branch (else) body, if any.booleanDetermine whether that if-statement has a default block.voidinsertBranch(int index, IJavaPredicate p, IJavaBlock b) Insert a branch (if, else-if) to this statement.voidremoveBranch(int index) Remove a branch from this statement.voidsetBranchBody(int index, IJavaBlock b) Set a branch (if, else-if) body.voidsetBranchPredicate(int index, IJavaPredicate p) Set a branch (if, else-if) predicate.Set the default 'else' block.intsize()Get the number of branches, including the default (else) branch, if any.intReturn the number of blocks (if, else-ifs), NOT counting the else block if there is one.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, replaceSubElement, 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
-
size
int size()Get the number of branches, including the default (else) branch, if any.- Returns:
- the number of branches
-
sizeWithoutDefault
int sizeWithoutDefault()Return the number of blocks (if, else-ifs), NOT counting the else block if there is one.- Returns:
-
getBranchPredicate
Get a branch (if, else-if) predicate.- Parameters:
index- 0-based branch index (0 for 'if', 1... for subsequent else-ifs)- Returns:
- the predicate
-
getBranchPredicates
List<IJavaPredicate> getBranchPredicates()Get the predicates. Warning, this is the actual list of predicates, not a copy. Caution should be exercised when modifying it- Returns:
- the original list of predicates
-
getBranchBody
Get a branch (if, else-if) body.- Parameters:
index- 0-based branch index (0 for 'if', 1... for subsequent else-ifs)- Returns:
- the body
-
getDefaultBlock
IJavaBlock getDefaultBlock()Get the default branch (else) body, if any.- Returns:
- the default branch body, null if there is none
-
hasDefaultBlock
boolean hasDefaultBlock()Determine whether that if-statement has a default block.- Returns:
- true if the if-statement has an else block
-
setBranchPredicate
Set a branch (if, else-if) predicate.- Parameters:
index- 0-based branch indexp- mandatory predicate
-
setBranchBody
Set a branch (if, else-if) body.- Parameters:
index- 0-based branch indexb- mandatory body
-
setDefaultBlock
Set the default 'else' block.- Parameters:
b- new default block, null for none- Returns:
- the previous default block
-
addBranch
Add an alternative block (if or else-if) to this element.- Parameters:
p- mandatory predicateb- mandatory statement
-
insertBranch
Insert a branch (if, else-if) to this statement.- Parameters:
index- 0-based branch indexp- mandatory predicateb- mandatory body
-
removeBranch
void removeBranch(int index) Remove a branch from this statement.- Parameters:
index- 0-based branch index
-
duplicate
IJavaIf 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
-