1 18 19 package alt.jiapi.reflect.instruction; 20 21 import alt.jiapi.reflect.SignatureUtil; 22 import alt.jiapi.reflect.Signature; 23 import alt.jiapi.file.ConstantPool; 24 25 32 public class Invocation extends ReferencingInstruction { 33 public Invocation(byte[] bytes, ConstantPool cp) { 34 super(bytes, cp); 35 } 36 37 38 41 public String getMethodName() { 42 return super.getName(); 43 } 44 45 48 public String getReturnType() { 49 Signature s = new Signature(getDescriptor()); 50 return s.getReturnType(); 51 } 52 53 56 public String [] getParameterTypes() { 57 Signature s = new Signature(getDescriptor()); 58 return s.getParameters(); 59 } 60 61 62 67 public short stackConsumption() { 68 short consumption = 0; 70 String [] paramTypes = getParameterTypes(); 71 for (int i = 0; i < paramTypes.length; i++) { 72 if ("long".equals(paramTypes[i]) || 73 "double".equals(paramTypes[i])) { 74 consumption += 2; 75 } 76 else { 77 consumption++; 78 } 79 } 80 81 if (getOpcode() != Opcodes.INVOKESTATIC) { 82 consumption++; } 84 85 return consumption; 86 } 87 88 89 92 public short stackUsage() { 93 int usage = 0; 94 String [] paramTypes = getParameterTypes(); 95 for (int i = 0; i < paramTypes.length; i++) { 96 if ("long".equals(paramTypes[i]) || 97 "double".equals(paramTypes[i])) { 98 usage -= 2; 99 } 100 else { 101 usage--; 102 } 103 } 104 105 107 if (getOpcode() != Opcodes.INVOKESTATIC) { 108 usage--; } 110 111 112 if (!"void".equals(getReturnType())) { 113 usage++; 114 } 115 116 if ("long".equals(getReturnType()) || 117 "double".equals(getReturnType())) { 118 usage++; 119 } 120 121 return (short)usage; 122 } 123 124 125 public String toString() { 126 StringBuffer sb = 127 new StringBuffer (Opcodes.opcodeStrings[0xff & getOpcode()]); 128 129 byte[] bytes = getBytes(); 130 for (int i = 1; i < bytes.length; i++) { 131 sb.append(" "); 132 sb.append(0xff & bytes[i]); 133 } 134 135 sb.append(" ; "); 136 sb.append(getClassName()); 137 sb.append("."); 138 sb.append(getMethodName()); 139 sb.append(getDescriptor()); 140 141 return sb.toString(); 142 } 143 } 144 145 | Popular Tags |