public final class MethodEditor extends Object
Modifier and Type | Class and Description |
---|---|
static class |
MethodEditor.Output
Output is the interface that patches use to emit their code into a method body.
|
static class |
MethodEditor.Patch
This class is subclassed for each kind of patch that you want to apply.
|
static class |
MethodEditor.Visitor
A specialized Instruction.Visitor providing convenience methods for inserting patches.
|
Constructor and Description |
---|
MethodEditor(Instruction[] instructions,
ExceptionHandler[][] handlers,
int[] instructionsToBytecodes)
Build an editor for specific method data.
|
MethodEditor(MethodData info)
Build an editor for the given method.
|
Modifier and Type | Method and Description |
---|---|
void |
addInstructionExceptionHandler(int i,
String catchClass,
MethodEditor.Patch p)
An "instruction exception handler" handles exceptions generated by a specific instruction (including patch code that may be
inserted before, after, or instead of the instruction in this pass).
|
void |
addMethodExceptionHandler(String catchClass,
MethodEditor.Patch p)
A "method exception handler" handles exceptions generated anywhere in the method.
|
int |
allocateLabel()
Allocate a fresh label.
|
boolean |
applyPatches()
This method finishes a pass.
|
void |
beginPass()
This must be called before inserting any patches.
|
void |
endPass()
This must be called after inserting any patches.
|
MethodData |
getData() |
ExceptionHandler[][] |
getHandlers() |
IInstruction[] |
getInstructions() |
int[] |
getInstructionsToBytecodes() |
void |
insertAfter(int i,
MethodEditor.Patch p)
Insert code to be executed after the instruction.
|
void |
insertAfterBody(MethodEditor.Patch p)
This method inserts code that will be placed after the method body.
|
void |
insertAtStart(MethodEditor.Patch p)
Insert code to be executed whenever the method is entered.
|
void |
insertBefore(int i,
MethodEditor.Patch p)
Insert code to be executed before the instruction.
|
void |
replaceWith(int i,
MethodEditor.Patch p)
Insert code to replace the instruction.
|
void |
visitInstructions(MethodEditor.Visitor v)
Apply Visitor v to each instruction in the code, for the purpose of patching the code.
|
public MethodEditor(MethodData info)
IllegalArgumentException
- if info is nullpublic MethodEditor(Instruction[] instructions, ExceptionHandler[][] handlers, int[] instructionsToBytecodes)
public ExceptionHandler[][] getHandlers()
public IInstruction[] getInstructions()
public int[] getInstructionsToBytecodes()
public void beginPass()
public void endPass()
public int allocateLabel() throws IllegalArgumentException
IllegalArgumentException
public void insertAtStart(MethodEditor.Patch p)
IllegalArgumentException
- if p is nullpublic void insertBefore(int i, MethodEditor.Patch p)
IllegalArgumentException
- if p is nullpublic void insertAfter(int i, MethodEditor.Patch p)
public void replaceWith(int i, MethodEditor.Patch p) throws NullPointerException
NullPointerException
- if p is nullIllegalArgumentException
- if p is nullpublic void addInstructionExceptionHandler(int i, String catchClass, MethodEditor.Patch p)
public void addMethodExceptionHandler(String catchClass, MethodEditor.Patch p)
public void insertAfterBody(MethodEditor.Patch p)
IllegalArgumentException
- if p is nullpublic MethodData getData()
public boolean applyPatches() throws IllegalArgumentException
IllegalArgumentException
public void visitInstructions(MethodEditor.Visitor v)