|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.ibm.wala.shrikeBT.MethodEditor
public final class MethodEditor
The MethodEditor is the core of the ShrikeBT code rewriting mechanism. To rewrite code, construct a MethodEditor initialized with the intial code for the method. Then perform a series of passes. In each pass you call beginPass(), insert a number of patches using the insert...() or replace...() methods, then optionally call applyPatches() to update the code with your changes, then call endPass(). The end of each pass updates the code in the MethodData that you passed in, so the new code can be extracted from that MethodData object. Note that if applyPatches() is not called, or it is called but no patches had been inserted, then the code will not be updated and that pass is essentially aborted. A patch is simply a subclass of MethodEditor.Patch, representing a code sequence to insert into the method. Each patch class implements one method, emitTo(), which writes the patch code into the code stream using the provided MethodEditor.Output instance. Anonymous inner classes are very useful for writing patches. Patches can be inserted at the following points:
| Nested Class Summary | |
|---|---|
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 Summary | |
|---|---|
MethodEditor(Instruction[] instructions,
ExceptionHandler[][] handlers,
int[] instructionsToBytecodes)
Build an editor for specific method data. |
|
MethodEditor(MethodData info)
Build an editor for the given method. |
|
| Method Summary | |
|---|---|
void |
addInstructionExceptionHandler(int i,
java.lang.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(java.lang.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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MethodEditor(MethodData info)
java.lang.IllegalArgumentException - if info is null
public MethodEditor(Instruction[] instructions,
ExceptionHandler[][] handlers,
int[] instructionsToBytecodes)
| Method Detail |
|---|
public ExceptionHandler[][] getHandlers()
public IInstruction[] getInstructions()
public int[] getInstructionsToBytecodes()
public void beginPass()
public void endPass()
public int allocateLabel()
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic void insertAtStart(MethodEditor.Patch p)
java.lang.IllegalArgumentException - if p is null
public void insertBefore(int i,
MethodEditor.Patch p)
java.lang.IllegalArgumentException - if p is null
public void insertAfter(int i,
MethodEditor.Patch p)
public void replaceWith(int i,
MethodEditor.Patch p)
throws java.lang.NullPointerException
java.lang.NullPointerException - if p is null
java.lang.IllegalArgumentException - if p is null
public void addInstructionExceptionHandler(int i,
java.lang.String catchClass,
MethodEditor.Patch p)
public void addMethodExceptionHandler(java.lang.String catchClass,
MethodEditor.Patch p)
public void insertAfterBody(MethodEditor.Patch p)
java.lang.IllegalArgumentException - if p is nullpublic MethodData getData()
public boolean applyPatches()
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic void visitInstructions(MethodEditor.Visitor v)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||