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

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

## Constructor: JUtil


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


## 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`


## 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`


## 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>`


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


## 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`


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


## 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: 
parameter: e: 
return: 

## 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: 
parameter: e: 
return: 

## 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`


## 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`


## 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.

## 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: 
parameter: e: 
return: 

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


## 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`


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


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

Description: 
return: 

## 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`


## 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`


## 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\)

