public final class ClassInstrumenter
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
ClassInstrumenter.MethodExaminer
Implement this interface to instrument every method of a class using visitMethods() below.
|
| Constructor and Description |
|---|
ClassInstrumenter(java.lang.String inputName,
byte[] bytes,
ClassHierarchyProvider cha)
Create a class instrumenter from raw bytes.
|
ClassInstrumenter(java.lang.String inputName,
ClassReader cr,
ClassHierarchyProvider cha)
Create a class instrumenter from a preinitialized class reader.
|
| Modifier and Type | Method and Description |
|---|---|
MethodData |
createEmptyMethodData(java.lang.String name,
java.lang.String sig,
int access) |
void |
deleteMethod(int i)
Indicate that the method should be deleted from the class.
|
ClassWriter |
emitClass()
Create a class which is a copy of the original class but with the new method code.
|
ClassWriter |
emitClass(ClassWriter w) |
void |
enableFakeLineNumbers(int offset)
Calling this means that methods without line numbers get fake line numbers added: each bytecode
instruction is treated as at line 'offset' + the offset of the instruction.
|
java.lang.String |
getInputName() |
CodeReader |
getMethodCode(int i)
Get the original code resource for the method.
|
ClassReader |
getReader() |
boolean |
isChanged()
Check whether any methods in the class have actually been changed.
|
void |
replaceMethod(int i,
MethodData md)
Replace the code for method i with new code.
|
void |
resetMethod(int i)
Reset method i back to the code from the original class, and "undelete" it if it was marked for
deletion.
|
MethodData |
visitMethod(int i)
Get the current state of method i.
|
void |
visitMethods(ClassInstrumenter.MethodExaminer me)
Do something to every method in the class.
|
public ClassInstrumenter(java.lang.String inputName,
byte[] bytes,
ClassHierarchyProvider cha)
throws InvalidClassFileException
InvalidClassFileExceptionpublic ClassInstrumenter(java.lang.String inputName,
ClassReader cr,
ClassHierarchyProvider cha)
java.lang.IllegalArgumentException - if cr is nullpublic java.lang.String getInputName()
public void enableFakeLineNumbers(int offset)
public ClassReader getReader()
public void deleteMethod(int i)
i - the index of the method to deletepublic MethodData createEmptyMethodData(java.lang.String name, java.lang.String sig, int access)
public void visitMethods(ClassInstrumenter.MethodExaminer me) throws InvalidClassFileException
me - the visitor to apply to each methodInvalidClassFileExceptionpublic MethodData visitMethod(int i) throws InvalidClassFileException
i - the index of the method to inspectInvalidClassFileExceptionpublic CodeReader getMethodCode(int i) throws InvalidClassFileException
i - the index of the method to inspectInvalidClassFileExceptionpublic void resetMethod(int i)
i - the index of the method to resetpublic void replaceMethod(int i,
MethodData md)
i - the index of the method to replacejava.lang.IllegalArgumentException - if md is nullpublic boolean isChanged()
public ClassWriter emitClass() throws InvalidClassFileException
We fix up any debug information to be consistent with the changes to the code.
InvalidClassFileExceptionpublic ClassWriter emitClass(ClassWriter w) throws InvalidClassFileException
InvalidClassFileException