public final class ClassInstrumenter extends 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(String inputName,
byte[] bytes,
ClassHierarchyProvider cha,
boolean reuseStackMaps)
Create a class instrumenter from raw bytes.
|
ClassInstrumenter(String inputName,
ClassReader cr,
ClassHierarchyProvider cha,
boolean reuseStackMaps)
Create a class instrumenter from a preinitialized class reader.
|
Modifier and Type | Method and Description |
---|---|
MethodData |
createEmptyMethodData(String name,
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.
|
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(String inputName, byte[] bytes, ClassHierarchyProvider cha, boolean reuseStackMaps) throws InvalidClassFileException
InvalidClassFileException
public ClassInstrumenter(String inputName, ClassReader cr, ClassHierarchyProvider cha, boolean reuseStackMaps) throws InvalidClassFileException
IllegalArgumentException
- if cr is nullInvalidClassFileException
public 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(String name, String sig, int access)
public void visitMethods(ClassInstrumenter.MethodExaminer me) throws InvalidClassFileException
me
- the visitor to apply to each methodInvalidClassFileException
public MethodData visitMethod(int i) throws InvalidClassFileException
i
- the index of the method to inspectInvalidClassFileException
public CodeReader getMethodCode(int i) throws InvalidClassFileException
i
- the index of the method to inspectInvalidClassFileException
public 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 replaceIllegalArgumentException
- if md is nullpublic boolean isChanged()
public ClassWriter emitClass() throws InvalidClassFileException
InvalidClassFileException
public ClassWriter emitClass(ClassWriter w) throws InvalidClassFileException
InvalidClassFileException