1 4 package com.tc.object.bytecode; 5 6 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 import com.tcclient.util.MapEntrySetWrapper; 12 13 public class HashMapAdapter { 14 15 public static class EntrySetAdapter extends AbstractMethodAdapter { 16 17 public MethodVisitor adapt(ClassVisitor classVisitor) { 18 MethodVisitor mv = visitOriginal(classVisitor); 19 if ("entrySet".equals(methodName)) { 20 return new Adapter(mv); 21 } 22 return mv; 23 } 24 25 public boolean doesOriginalNeedAdapting() { 26 return false; 27 } 28 29 private static class Adapter extends MethodAdapter implements Opcodes { 30 31 public Adapter(MethodVisitor mv) { 32 super(mv); 33 } 34 35 public void visitMethodInsn(int opcode, String owner, String name, String desc) { 36 super.visitMethodInsn(opcode, owner, name, desc); 37 38 if ((opcode == INVOKESPECIAL)) { 39 mv.visitVarInsn(ASTORE, 1); 40 mv.visitTypeInsn(NEW, MapEntrySetWrapper.CLASS_SLASH); 41 mv.visitInsn(DUP); 42 mv.visitVarInsn(ALOAD, 0); 43 mv.visitVarInsn(ALOAD, 1); 44 mv.visitMethodInsn(INVOKESPECIAL, MapEntrySetWrapper.CLASS_SLASH, "<init>", 45 "(Ljava/util/Map;Ljava/util/Set;)V"); 46 } 47 } 48 49 } 50 51 } 52 53 } 54 | Popular Tags |