# Class: com.pnfsoftware.jeb.core.units.code.java.JUtil

Collection of utility methods to manipulate [IJavaElement](IJavaElement).

## Static Method: canThrow
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Recursively determine whether a statement may throw.
parameter: stm: statement to inspect
return: true if the statement may throw

## Static Method: checkIfGoto
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaLabel`

Description: Check that the statement is a simple "if\(...\) { goto x; }" and if so, returns "x"
parameter: stm: statement to check
return: the label or null

## Static Method: findParent
- parameter: `root`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- parameter: `elt`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`

Description: Retrieve the parent of an AST element \(or first parent, if the element is reusable and has potentially multiple parents\).
parameter: root: a root element, typically, an [IJavaClass](IJavaClass)
parameter: elt: the element for which the first parent is to be found
return: the parent or null

## Static Method: generate
- parameter: `elt`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- return type: `java.lang.String`

Description: Generate an AST element as raw Java text.
parameter: elt: AST element to generate
return: generated text

## Static Method: getFirstRealStatement
- parameter: `b`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaBlock`
- parameter: `i`, type: `int`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`

Description: 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: 
 
- the "do {" part of a do\-while block
-  
- the "while\(true\) {" part of a while block
-  
- the "if\(true\) {" part of a conditional statement
-  
- the "try {" part of a try\-catch block
-
parameter: b: current block
parameter: i: current statement index in the block
return: the statement, or null if none were found

## Static Method: getGotoLabel
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaLabel`

Description: Retrieve the target label of a goto statement.
parameter: stm: statement to inspect
return: target label, or null

## Static Method: getGotos
- parameter: `targetLabel`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaLabel`
- parameter: `flatlist`, type: `java.util.List<com.pnfsoftware.jeb.core.units.code.java.IJavaStatement>`
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.code.java.IJavaStatement>`

Description: Retrieve goto statements targeting a label.
parameter: targetLabel: target label
parameter: flatlist: statement list to inspect
return: matching goto statements

## Static Method: getIdentifier
- parameter: `e`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaIdentifier`

Description: Retrieve the identifier represented by an expression.
parameter: e: expression to inspect
return: identifier, or null

## Static Method: getIdentifiers
- parameter: `e`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.code.java.IJavaIdentifier>`

Description: 
parameter: e: 
return: 

## Static Method: getMonitorEnter
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`

Description: Retrieve the lock expression from a monitor\-enter statement.
parameter: stm: statement to inspect
return: lock expression, or null

## Static Method: getMonitorExit
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`

Description: Retrieve the lock expression from a monitor\-exit statement.
parameter: stm: statement to inspect
return: lock expression, or null

## Static Method: getNegatedConstant
- parameter: `cst`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaConstant`
- parameter: `factory`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaConstantFactory`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaConstant`

Description: Get the negated value of a constant, if possible.
parameter: cst: a constant
parameter: factory: constant factory
return: null if the negative value cannot be represented \(e.g., constant type no fitting\) or         is the same as the provided constant

## Static Method: getStringConstant
- parameter: `e`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- return type: `java.lang.String`

Description: Retrieve the string value of a string constant element.
parameter: e: element to inspect
return: string value, or null

## Static Method: getVarLike
- parameter: `e`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaIdentifier`

Description: Detect: x, \(int\)x
parameter: e: 
return: x or null

## Static Method: isClassMethodField
- parameter: `e`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- return type: `boolean`

Description: Determine whether an element is a class, method, or field element.
parameter: e: element to test
return: true if the element is a class, method, or field

## Static Method: isDeclarationOrDefinition
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: 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\)
parameter: stm: 
return: 

## Static Method: isFlowBreaker
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Determine whether a statement interrupts regular control flow.
parameter: stm: statement to inspect
return: true if the statement is a flow breaker

## Static Method: isGotoTo
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- parameter: `target`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaLabel`
- return type: `boolean`

Description: Check that the statement is a "goto target;"
parameter: stm: the statement
parameter: target: the target
return: 

## Static Method: isIdentOrDefinition
- parameter: `e`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- parameter: `ident`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaIdentifier`
- return type: `boolean`

Description: Determine whether the elements is the provided identifier or a simple definition of the identifier.
parameter: e: 
parameter: ident: 
return: 

## Static Method: isIf
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Determine whether a statement is a simple if: if\(...\){...}.
parameter: stm: 
return: 

## Static Method: isIfContinue
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Determine whether a statement is an if statement whose only body statement is a simple continue.
parameter: stm: statement to inspect
return: true if the statement is an if\-continue pattern

## Static Method: isIfElse
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Determine whether a statement is like: if\(...\){...}else{...} which is the if\-statement with 2 blocks: the main case block and the default block.
parameter: stm: 
return: 

## Static Method: isIfGoto
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaLabel`

Description: Determine if the provided statement is like `if(COND){goto LABEL;}` and if so, return the label.
parameter: stm: statement to inspect
return: target label, or null

## Static Method: isIfNoElse
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Determine whether a statement is like: if\(...\){ }\[else if\(...\){}\]\* 

 ie, the if\-block can have multiple case\-blocks but NO default 'else' block
parameter: stm: 
return: 

## Static Method: isImmOrVarLike
- parameter: `e`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`
- return type: `boolean`

Description: Detect: 1, x, \(int\)x
parameter: e: 
return: true or false

## Static Method: isIntegerConstant
- parameter: `e`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- parameter: `expected`, type: `int`
- return type: `boolean`

Description: Determine whether an element is an integer constant with an expected value.
parameter: e: element to test
parameter: expected: expected integer value
return: true if the element is an integer constant with the expected value

## Static Method: isMonitorExit
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- return type: `boolean`

Description: Determine whether an element is a monitor\-exit statement.
parameter: stm: element to test
return: true if the element is a monitor\-exit statement

## Static Method: isMonitorExit
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- parameter: `expectedLock`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`
- return type: `boolean`

Description: 
parameter: stm: 
parameter: expectedLock: optional
return: 

## Static Method: isNonCompoundFlowBreaker
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Determine whether the provided statement is a return, throw, goto, break, or continue.
parameter: stm: 
return: 

## Static Method: isOrContainsLabel
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Recursively determine if the statement is or contains a Label. Can be called for any statement, including compound statements.
parameter: stm: 
return: 

## Static Method: isSimpleBreak
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Determine whether a statement is an unlabeled break.
parameter: stm: statement to inspect
return: true if the statement is an unlabeled break

## Static Method: isSimpleContinue
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- return type: `boolean`

Description: Determine whether a statement is an unlabeled continue.
parameter: stm: statement to inspect
return: true if the statement is an unlabeled continue

## Static Method: isStringConstant
- parameter: `e`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaElement`
- return type: `boolean`

Description: Determine whether an element is a string constant.
parameter: e: element to test
return: true if the element is a string constant

## Static Method: isThrow
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- parameter: `expectedThrown`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`
- return type: `boolean`

Description: Determine whether a statement throws a specific expression.
parameter: stm: statement to test
parameter: expectedThrown: expected thrown expression
return: true if the statement throws the expected expression

## Static Method: isThrowLike
- parameter: `stm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaStatement`
- parameter: `flatlist`, type: `java.util.List<com.pnfsoftware.jeb.core.units.code.java.IJavaStatement>`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`

Description: 
parameter: stm: a statement, that we want to be a THROW or a GOTO\-THROW
parameter: flatlist: 
return: on success, the THROWN expression; else, null

## Static Method: isTryCatchall
- parameter: `b`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaBlock`
- parameter: `i`, type: `int`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaCatchBlock`

Description: Determine whether the provided statement is a try\-catch\-all \(single catch block, that catches all exceptions\)
parameter: b: block
parameter: i: statement index in the block
return: the catch\-all block or null

## Static Method: isTryCatchall
- parameter: `trystm`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaTry`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaCatchBlock`

Description: 
parameter: trystm: a [IJavaTry](IJavaTry) statement
return: true if the try\-statement is a try\-catch\-all \(single catch block, that catches all         exceptions\)

## Static Method: moveStatements
- parameter: `src`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaBlock`
- parameter: `srcbegin`, type: `int`
- parameter: `srcend`, type: `int`
- parameter: `dst`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaBlock`
- parameter: `dstindex`, type: `int`

Description: 
parameter: src: 
parameter: srcbegin: 
parameter: srcend: 
parameter: dst: 
parameter: dstindex: 

## Static Method: removeStatementsDeep
- parameter: `b`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaBlock`
- parameter: `checker`, type: `java.util.function.Predicate<com.pnfsoftware.jeb.core.units.code.java.IJavaStatement>`
- return type: `int`

Description: Remove statements matching a predicate from a block and nested compound blocks.
parameter: b: block to modify
parameter: checker: statement predicate
return: number of removed statements

## Static Method: resolveLogicalNot
- parameter: `exp`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`
- parameter: `jctx`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaGlobalContext`
- return type: `com.pnfsoftware.jeb.core.units.code.java.IJavaExpression`

Description: 
parameter: exp: a LOG\_NOT operation
parameter: jctx: 
return: if the LOG\_NOT was simplified, a non\-null reference to the simplified IR \(may be the         same ref as the input expression, since modifications are also attempted in place\)

