use of org.fakereplace.data.InstanceTracker in project fakereplace by fakereplace.
the class IntegrationActivationTransformer method makeTrackedInstance.
/**
* modifies a class so that all created instances are registered with
* InstanceTracker
*/
private void makeTrackedInstance(ClassFile file) throws BadBytecode {
for (MethodInfo m : (List<MethodInfo>) file.getMethods()) {
if (m.getName().equals("<init>")) {
Bytecode code = new Bytecode(file.getConstPool());
code.addLdc(file.getName());
code.addAload(0);
code.addInvokestatic(InstanceTracker.class.getName(), "add", "(Ljava/lang/String;Ljava/lang/Object;)V");
CodeIterator it = m.getCodeAttribute().iterator();
it.skipConstructor();
it.insert(code.get());
m.getCodeAttribute().computeMaxStack();
}
}
}
Aggregations