il = new InstructionList(); MethodGen writeReplace = new MethodGen(ACC_PRIVATE, Type.OBJECT, new Type[] {}, null, "writeReplace", cg.getClassName(), il, cp);  int wreplaceIndex ; if( wreplace == null ){ wreplaceIndex = addWriteReplace(cp); }else{  wreplaceIndex = cp.addMethodref( wreplace.getDeclaringClass().getName(),wreplace.getName(), "(Ljava/lang/Object;)Ljava/lang/Object;" ); }  il.append(new ALOAD(0)); il.append(new INVOKESTATIC( wreplaceIndex ) ); il.append(new ARETURN());  cg.addMethod(ClassFileUtils.getMethod(writeReplace));
    private static void addConstructor(ClassGen cg,                        java.lang.reflect.Method wreplace ) throws Throwable {                        //single arg constructor        String parentClass = cg.getSuperclassName();        InstructionFactory factory = new InstructionFactory(cg);        ConstantPoolGen cp = cg.getConstantPool(); // cg creates constant pool        InstructionList il = new InstructionList();        MethodGen costructor = new MethodGen(ACC_PUBLIC, // access flags        Type.VOID, // return type        new Type[] { // argument types            new ObjectType(INTERCEPTOR_CLASS_NAME)}, null, // arg names            CONSTRUCTOR_NAME, cg.getClassName(), il, cp);                                    il.append(new ALOAD(0));            il.append(            factory.createInvoke( parentClass,CONSTRUCTOR_NAME, Type.VOID,            new Type[] {},            INVOKESPECIAL));                                   il.append(new ALOAD(0));            il.append(new ALOAD(1));            il.append(            factory.createFieldAccess(            cg.getClassName(),            FIELD_NAME,            new ObjectType(INTERCEPTOR_CLASS_NAME),            PUTFIELD));            il.append(new RETURN());            cg.addMethod(ClassFileUtils.getMethod(costructor));                        //factory sometimes usefull and has meaning for performance                        il = new InstructionList();            MethodGen newInstance = ClassFileUtils.toMethodGen(            Factory.class.getMethod("newInstance",            new Class[]{ MethodInterceptor.class } ),            cg.getClassName(), il, cp );            il.append( new NEW(cp.addClass( new ObjectType(cg.getClassName()) )) );            il.append( new DUP());            il.append( new ALOAD(1) );            il.append( new INVOKESPECIAL( addNewInstanceRef(cp, cg.getClassName()) ) ) ;            il.append( new ARETURN());            cg.addMethod(ClassFileUtils.getMethod(newInstance));                                                il = new InstructionList();            MethodGen getInterceptor = ClassFileUtils.toMethodGen(            Factory.class.getMethod( "getInterceptor", new Class[0] ),            cg.getClassName(), il, cp );            il.append( new ALOAD(0));            il.append( new GETFIELD( cp.addFieldref( cg.getClassName(),            FIELD_NAME, "L" + INTERCEPTOR_CLASS_NAME.replace('.','/') + ";"  ) ) );            il.append( new ARETURN() );            cg.addMethod(ClassFileUtils.getMethod(getInterceptor));                        //serialization support            il = new InstructionList();            MethodGen writeReplace = new MethodGen(ACC_PRIVATE, // access flags            Type.OBJECT, // return type            new Type[] {}, null, // arg names            "writeReplace", cg.getClassName(), il, cp);                        int wreplaceIndex ;            if( wreplace == null ){               wreplaceIndex = addWriteReplace(cp);            }else{               //signature : "(Ljava/lang/Object;)Ljava/lang/Object;");               wreplaceIndex = cp.addMethodref(                  wreplace.getDeclaringClass().getName(),wreplace.getName(),                     "(Ljava/lang/Object;)Ljava/lang/Object;"                 );            }                        il.append(new ALOAD(0));            il.append(new INVOKESTATIC( wreplaceIndex ) );            il.append(new ARETURN());                        cg.addMethod(ClassFileUtils.getMethod(writeReplace));                                        }