Search in sources :

Example 1 with InstanceTracker

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();
        }
    }
}
Also used : InstanceTracker(org.fakereplace.data.InstanceTracker) CodeIterator(javassist.bytecode.CodeIterator) MethodInfo(javassist.bytecode.MethodInfo) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BadBytecode(javassist.bytecode.BadBytecode) Bytecode(javassist.bytecode.Bytecode)

Aggregations

List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 BadBytecode (javassist.bytecode.BadBytecode)1 Bytecode (javassist.bytecode.Bytecode)1 CodeIterator (javassist.bytecode.CodeIterator)1 MethodInfo (javassist.bytecode.MethodInfo)1 InstanceTracker (org.fakereplace.data.InstanceTracker)1