java.lang.Object | |
↳ | com.pnfsoftware.jeb.core.units.code.java.JUtil |
Collection of utility methods to manipulate IJavaElement
.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
JUtil() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static boolean | canThrow(IJavaStatement stm) | ||||||||||
static IJavaLabel |
checkIfGoto(IJavaStatement stm)
Check that the statement is a simple "if(...) { goto x; }" and if so, returns "x"
| ||||||||||
static IJavaElement |
findParent(IJavaElement root, IJavaElement elt)
Retrieve the parent of an AST element (or first parent, if the element is reusable and has
potentially multiple parents).
| ||||||||||
static String | generate(IJavaElement elt) | ||||||||||
static IJavaStatement |
getFirstRealStatement(IJavaBlock b, int i)
This convenience method attempts to determine the next "real" statement to be executed in the
block, starting at the provided index 'i'.
| ||||||||||
static IJavaLabel | getGotoLabel(IJavaStatement stm) | ||||||||||
static List<IJavaStatement> | getGotos(IJavaLabel targetLabel, List<IJavaStatement> flatlist) | ||||||||||
static IJavaIdentifier | getIdentifier(IJavaExpression e) | ||||||||||
static List<IJavaIdentifier> | getIdentifiers(IJavaElement e) | ||||||||||
static IJavaExpression | getMonitorEnter(IJavaStatement stm) | ||||||||||
static IJavaExpression | getMonitorExit(IJavaStatement stm) | ||||||||||
static IJavaConstant |
getNegatedConstant(IJavaConstant cst, IJavaConstantFactory factory)
Get the negated value of a constant, if possible.
| ||||||||||
static IJavaExpression | getSimplePredicate(IJavaPredicate p) | ||||||||||
static String | getStringConstant(IJavaElement e) | ||||||||||
static IJavaIdentifier |
getVarLike(IJavaExpression e)
Detect: x, (int)x
| ||||||||||
static boolean | isClassMethodField(IJavaElement e) | ||||||||||
static boolean |
isDeclarationOrDefinition(IJavaStatement stm)
Determine whether the statement defines an identifier.
| ||||||||||
static boolean | isFlowBreaker(IJavaStatement stm) | ||||||||||
static boolean |
isGotoTo(IJavaStatement stm, IJavaLabel target)
Check that the statement is a "goto target;"
| ||||||||||
static boolean |
isIdentOrDefinition(IJavaElement e, IJavaIdentifier ident)
Determine whether the elements is the provided identifier or a simple definition of the
identifier.
| ||||||||||
static boolean |
isIf(IJavaStatement stm)
Determine whether a statement is a simple if: if(...){...}.
| ||||||||||
static boolean | isIfContinue(IJavaStatement stm) | ||||||||||
static boolean |
isIfElse(IJavaStatement stm)
Determine whether a statement is like: if(...){...}else{...} which is the if-statement with 2
blocks: the main case block and the default block.
| ||||||||||
static IJavaLabel |
isIfGoto(IJavaStatement stm)
Determine if the provided statement is like
if(COND){goto LABEL;} and if so,
return the label. | ||||||||||
static boolean |
isIfNoElse(IJavaStatement stm)
Determine whether a statement is like: if(...){ }[else if(...){}]*
ie, the if-block can have multiple case-blocks but NO default 'else' block | ||||||||||
static boolean |
isImmOrVarLike(IJavaExpression e)
Detect: 1, x, (int)x
| ||||||||||
static boolean | isIntegerConstant(IJavaElement e, int expected) | ||||||||||
static boolean | isMonitorExit(IJavaElement stm) | ||||||||||
static boolean | isMonitorExit(IJavaElement stm, IJavaExpression expectedLock) | ||||||||||
static boolean |
isNonCompoundFlowBreaker(IJavaStatement stm)
Determine whether the provided statement is a return, throw, goto, break, or continue.
| ||||||||||
static boolean |
isOrContainsLabel(IJavaStatement stm)
Recursively determine if the statement is or contains a Label.
| ||||||||||
static boolean | isSimpleBreak(IJavaStatement stm) | ||||||||||
static boolean | isSimpleContinue(IJavaStatement stm) | ||||||||||
static boolean | isStringConstant(IJavaElement e) | ||||||||||
static boolean | isThrow(IJavaStatement stm, IJavaExpression expectedThrown) | ||||||||||
static IJavaExpression | isThrowLike(IJavaStatement stm, List<IJavaStatement> flatlist) | ||||||||||
static IJavaCatchBlock |
isTryCatchall(IJavaBlock b, int i)
Determine whether the provided statement is a try-catch-all (single catch block, that catches
all exceptions)
| ||||||||||
static IJavaCatchBlock | isTryCatchall(IJavaTry trystm) | ||||||||||
static void | moveStatements(IJavaBlock src, int srcbegin, int srcend, IJavaBlock dst, int dstindex) | ||||||||||
static int | removeStatementsDeep(IJavaBlock b, Predicate<IJavaStatement> checker) |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Check that the statement is a simple "if(...) { goto x; }" and if so, returns "x"
stm | statement to check |
---|
Retrieve the parent of an AST element (or first parent, if the element is reusable and has potentially multiple parents).
root | a root element, typically, an IJavaClass |
---|---|
elt | the element for which the first parent is to be found |
This convenience method attempts to determine the next "real" statement to be executed in the block, starting at the provided index 'i'.
This method can only go "deeper" (forward). It cannot go "up", which would require keeping
track of parents. Use a PStmManager
to do that.
Important: Label statements are not skipped over. This method skips over:
b | current block |
---|---|
i | current statement index in the block |
Get the negated value of a constant, if possible.
cst | a constant |
---|---|
factory | constant factory |
Determine whether the statement defines an identifier.
Currently, definitions should only be found in four types of statements:
- pure decl: "int x;"
- decl + init: "int x = 0;"
- in top-level Method elements (NOT CHECKED HERE)
- in compound Try elements (NOT CHECKED HERE)
Check that the statement is a "goto target;"
stm | the statement |
---|---|
target | the target |
Determine whether the elements is the provided identifier or a simple definition of the identifier.
Determine whether a statement is a simple if: if(...){...}.
Determine whether a statement is like: if(...){...}else{...} which is the if-statement with 2 blocks: the main case block and the default block.
Determine if the provided statement is like if(COND){goto LABEL;}
and if so,
return the label.
Determine whether a statement is like: if(...){ }[else if(...){}]*
ie, the if-block can have multiple case-blocks but NO default 'else' block
expectedLock | optional |
---|
Determine whether the provided statement is a return, throw, goto, break, or continue.
Recursively determine if the statement is or contains a Label. Can be called for any statement, including compound statements.
stm | a statement, that we want to be a THROW or a GOTO-THROW |
---|
Determine whether the provided statement is a try-catch-all (single catch block, that catches all exceptions)
b | block |
---|---|
i | statement index in the block |
trystm | a IJavaTry statement |
---|