1 4 package com.tc.object.bytecode; 5 6 import com.tc.asm.ClassAdapter; 7 import com.tc.asm.ClassVisitor; 8 import com.tc.asm.MethodAdapter; 9 import com.tc.asm.MethodVisitor; 10 import com.tc.asm.Opcodes; 11 12 import java.lang.reflect.Modifier ; 13 14 public class JavaUtilTreeMapAdapter extends ClassAdapter { 15 16 public JavaUtilTreeMapAdapter(ClassVisitor cv) { 17 super(cv); 18 } 19 20 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String [] exceptions) { 21 MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 22 if ("writeObject".equals(name) && Modifier.isPrivate(access)) { return new WriteObjectAdapter(mv); } 23 24 return mv; 25 } 26 27 private static class WriteObjectAdapter extends MethodAdapter implements Opcodes { 28 29 public WriteObjectAdapter(MethodVisitor mv) { 30 super(mv); 31 } 32 33 public void visitFieldInsn(int opcode, String owner, String name, String desc) { 34 if (opcode == GETFIELD) { 35 if ("java/util/TreeMap$Entry".equals(owner)) { 36 if ("key".equals(name)) { 37 mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map$Entry", "getKey", "()Ljava/lang/Object;"); 38 } else if ("value".equals(name)) { 39 mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map$Entry", "getValue", "()Ljava/lang/Object;"); 40 } else { 41 throw new AssertionError ("unknown field name: " + name); 42 } 43 return; 44 } 45 } 46 47 super.visitFieldInsn(opcode, owner, name, desc); 48 } 49 50 public void visitTypeInsn(int opcode, String desc) { 51 if (CHECKCAST == opcode) { 52 if ("java/util/TreeMap$Entry".equals(desc)) { 53 super.visitTypeInsn(opcode, "java/util/Map$Entry"); 54 return; 55 } 56 } 57 58 super.visitTypeInsn(opcode, desc); 59 } 60 61 } 62 63 } 64 | Popular Tags |