1 30 31 package jbet; 32 33 34 35 public class Reflection 36 { 37 40 41 public static void descriptor2classes (Snippit out, Descriptor descriptor) 42 { 43 out.push (new Instruction().setIpush (descriptor.args.length)); 44 out.push (new Instruction().setANewArray ("java/lang/Class")); 45 46 for (int i = 0; i < descriptor.args.length; i++) { 47 out.push (new Instruction().setDup()); 48 out.push (new Instruction().setIpush (i)); 49 50 Type arg = descriptor.args[i]; 51 52 if (arg.base == 'L' || arg.arraydepth > 0) { 53 out.push (new Instruction().setSpush (arg.toClassRef().replace ('/', '.'))); 54 out.push (new Instruction().setInvokeStatic ("java/lang/Class", "forName", 55 new Descriptor (Type.STRING, Type.CLASS))); 56 } else 57 out.push (new Instruction().setGetstatic (arg.wrapperClass(), "TYPE", Type.CLASS)); 58 59 out.push (new Instruction().setAastore ()); 60 } 61 } 62 63 66 67 public static void arguments2array (Snippit out, Descriptor descriptor) 68 { 69 out.push (new Instruction().setIpush (descriptor.args.length)); 70 out.push (new Instruction().setANewArray ("java/lang/Object")); 71 72 for (int i = descriptor.args.length - 1; i >= 0; i--) { 73 Type arg = descriptor.args[i]; 74 75 out.push (new Instruction().setDup_x (Type.OBJECT, arg)); 76 if (arg.category() == 2) { 77 out.push (new Instruction().setDup_x2()); 78 out.push (new Instruction().setPop()); 79 } 80 else 81 out.push (new Instruction().setSwap()); 82 83 if (arg.base != 'L' && arg.arraydepth == 0) { 84 out.push (new Instruction().setNew (arg.wrapperClass())); 85 out.push (new Instruction().setDup_x (Type.OBJECT, arg)); 86 if (arg.category() == 2) { 87 out.push (new Instruction().setDup_x2()); 88 out.push (new Instruction().setPop()); 89 } 90 else 91 out.push (new Instruction().setSwap()); 92 out.push (new Instruction().setInvokeSpecial (arg.wrapperClass(), "<init>", new Descriptor (arg, Type.VOID))); 93 } 94 95 out.push (new Instruction().setIpush (i)); 96 out.push (new Instruction().setSwap()); 97 out.push (new Instruction().setAastore()); 98 } 99 } 100 101 102 103 public static void getReturn (Snippit out, Type ret) 104 { 105 if (ret.base != 'V') { 106 if (ret.base != 'L' && ret.arraydepth == 0) { 107 out.push (new Instruction().setCheckcast (ret.wrapperClass())); 108 out.push (new Instruction().setInvokeVirtual (ret.wrapperClass(), ret.unpackMethod(), 109 new Descriptor (ret))); 110 } else 111 out.push (new Instruction().setCheckcast (ret)); 112 } else 113 out.push (new Instruction().setPop()); 114 } 115 } 116 | Popular Tags |