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

Base class for `dexdec` \(DEX decompiler\) AST optimizer plugins. Those plugins can access and modify the AST of a class or method being decompiled. They can be used to implement simple code clean\-up and beautification/styling. 

 Optimizers are usually managed by [master optimizers](IJMasterOptimizer) \(also called `orchestrators`\). Third\-party optimizer plugins can be automatically registered when creating an orchestrator. 

 Life\-cycle information:
 \- plugins are reused \(i.e. the [#perform()](#perform()) method is called multiple times\)
 \- thread\-safety:
 \-\- Python script plugins must be thread\-safe: a plugin instance may be executed by multiple threads concurrently
 \-\- Java plugins \(including Java script plugins\) are not required to be thread\-safe: a plugin instance will not be executed by multiple threads concurrently

## Protected Constructor: AbstractJOptimizer

Description: Create a standard optimizer.

## Protected Constructor: AbstractJOptimizer
- parameter: `type`, type: `com.pnfsoftware.jeb.core.units.code.java.JOptimizerType`

Description: Create an optimizer.
parameter: type: optimizer type, or null to use [JOptimizerType#NORMAL](JOptimizerType#NORMAL)

## Protected Constructor: AbstractJOptimizer
- parameter: `type`, type: `com.pnfsoftware.jeb.core.units.code.java.JOptimizerType`
- parameter: `name`, type: `java.lang.String`

Description: Create an optimizer.
parameter: type: optimizer type, or null to use [JOptimizerType#NORMAL](JOptimizerType#NORMAL)
parameter: name: optimizer name, or null to derive one from the implementation class

## Field: c
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaClass`
Description: Target AST class to be optimized. May be null, in which case [#m](#m) is not.

## Field: cf
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaConstantFactory`
Description: AST constant factory \(for convenience \- referenced in [#jctx](#jctx)\).

## Field: decomp
Type: `com.pnfsoftware.jeb.core.units.code.android.IDexDecompilerUnit`
Description: Managing dex decompiler. May be null.

## Field: dex
Type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
Description: Underlying dex code. May be null.

## Field: drcollector
Type: `com.pnfsoftware.jeb.core.units.code.java.DeferredRequestsCollector`
Description: Collector for deferred requests. May be null. When non\-null, optimizers may file requests to decompile other classes, methods, or fields. It is useful for optimizers needing to examine AST code located in other classes or methods to operate. 

 How to use in your optimizer: 

```


 // do some work
 // ...

 // need access to the AST of some other class (CX) to continue the work
 IJavaClass ast_CX = jctx.getClassFactory().get(csig_CX);
 if(ast_CX == null || !ast_CX.isBuilt()) {
     // the AST of CX is not available at this time
     // if we can, request a decompilation
     if(drcollector != null) {
         drcollector.request(csig_MX);
     }
     return 0;  // done for now
 }

 // in a future call to this optimizer, the above check may pass, allowing further processing
 // ...
 // ...

 
```

## Field: jctx
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaGlobalContext`
Description: Java AST global context. This context holds AST element factory methods as well as references to important factories, such as the constant, type, and operator factories.

## Field: m
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaMethod`
Description: Target AST method to be optimized. May be null, in which case [#c](#c) is not.

## Field: of
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaOperatorFactory`
Description: AST operation factory \(for convenience \- referenced in [#jctx](#jctx)\).

## Field: tf
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaTypeFactory`
Description: AST type factory \(for convenience \- referenced in [#jctx](#jctx)\).

## Static Field: logger
Type: `com.pnfsoftware.jeb.util.logging.ILogger`
Description: Public logger accessible by the implementing optimizer. Writing to the logger should be favored over writing directly to `stdout`.

## Method: getName
- return type: `java.lang.String`


## Method: getPluginInformation
- return type: `com.pnfsoftware.jeb.core.EditablePluginInformation`


## Method: getPriority
- return type: `double`


## Method: getType
- return type: `com.pnfsoftware.jeb.core.units.code.java.JOptimizerType`


## Method: isEnabled
- return type: `boolean`


## Method: perform
- parameter: `elt`, type: `com.pnfsoftware.jeb.core.units.code.java.IJavaDecompilableElement`
- return type: `int`


## Method: perform
- return type: `int`

Description: An optimizer must implement this method. This method is called by a master optimizer to [perform](#perform(IJavaDecompilableElement)) the optimization on the selected target. 

 Note that the optimizer is responsible for returning a legal method context, e.g.: the method IR instructions must be consistent with the CFG; the CFG must adhere to certain rules \(see `cleanGraph`\); if the data flow analysis is no longer valid, it should be invalidated \(see [resetDFA](CFG#invalidateDataFlowAnalysis())\); etc.
return: the number of optimizations performed, 0 if none

## Method: setEnabled
- parameter: `enabled`, type: `boolean`

Description: Enable or disable this optimizer. This flag is checked by a [master optimizer](IJMasterOptimizer).
parameter: enabled: true to enable this optimizer

## Protected Method: setName
- parameter: `name`, type: `java.lang.String`

Description: Set the optimizer name. To be used by the constructor.
parameter: name: if null, a name will be auto\-generated

## Protected Method: setPriority
- parameter: `priority`, type: `double`

Description: Set the optimizer priority. To be used by the constructor.
parameter: priority: the new priority \(high means higher priority\). When optimizers are managed            and run by an orchestrator, the optimizers with a higher priority are run before            those having a lower priority. The default priority is 0.

## Protected Method: setType
- parameter: `type`, type: `com.pnfsoftware.jeb.core.units.code.java.JOptimizerType`

Description: Set the optimizer type. To be used by the constructor.
parameter: type: if null, a [standard](JOptimizerType#NORMAL) optimizer is assumed

