1 18 19 package alt.jiapi.reflect.instruction; 20 21 import alt.jiapi.reflect.Instruction; 22 import alt.jiapi.file.ConstantPool; 23 import alt.jiapi.file.ConstantPool.NameAndTypeInfo; 24 25 33 public class ReferencingInstruction extends CPInstruction { 34 public ReferencingInstruction(byte[] bytes, ConstantPool cp) { 35 super(bytes, cp); 36 } 37 38 39 45 public String getReferencedTypeName() { 46 return getClassName(); 47 } 48 49 50 53 public String getClassName() { 54 return getInternalName().replace('/', '.'); 55 } 56 57 58 61 public String getInternalName() { 62 ConstantPool.Entry entry = cp.get(getIndex()); 63 64 if (entry instanceof ConstantPool.MethodRefInfo) { 65 ConstantPool.MethodRefInfo mri = (ConstantPool.MethodRefInfo)entry; 66 return mri.getClassInfo().getName(); 67 } 68 else if (entry instanceof ConstantPool.FieldRefInfo) { 69 ConstantPool.FieldRefInfo fri = (ConstantPool.FieldRefInfo)entry; 70 return fri.getClassInfo().getName(); 71 } 72 else if (entry instanceof ConstantPool.InterfaceMethodRefInfo) { 73 ConstantPool.InterfaceMethodRefInfo fri = (ConstantPool.InterfaceMethodRefInfo)entry; 74 return fri.getClassInfo().getName(); 75 } 76 else { 77 System.out.println("Don't know what to do with " + entry); 78 } 79 80 return null; 81 } 82 83 86 public String getName() { 87 ConstantPool.Entry entry = cp.get(getIndex()); 88 NameAndTypeInfo nti = null; 89 90 if (entry instanceof ConstantPool.MethodRefInfo) { 91 ConstantPool.MethodRefInfo mri = (ConstantPool.MethodRefInfo)entry; 92 nti = mri.getNameAndTypeInfo(); 93 } 94 else if (entry instanceof ConstantPool.FieldRefInfo) { 95 ConstantPool.FieldRefInfo fri = (ConstantPool.FieldRefInfo)entry; 96 nti = fri.getNameAndTypeInfo(); 97 } 98 else if (entry instanceof ConstantPool.InterfaceMethodRefInfo) { 99 ConstantPool.InterfaceMethodRefInfo fri = (ConstantPool.InterfaceMethodRefInfo)entry; 100 nti = fri.getNameAndTypeInfo(); 101 } 102 else { 103 System.out.println("Don't know what to do with " + entry); 104 } 105 106 return nti.getName(); 107 } 108 109 110 114 public String getDescriptor() { 115 ConstantPool.Entry entry = cp.get(getIndex()); 116 NameAndTypeInfo nti = null; 117 118 if (entry instanceof ConstantPool.MethodRefInfo) { 119 ConstantPool.MethodRefInfo mri = (ConstantPool.MethodRefInfo)entry; 120 nti = mri.getNameAndTypeInfo(); 121 } 122 else if (entry instanceof ConstantPool.FieldRefInfo) { 123 ConstantPool.FieldRefInfo fri = (ConstantPool.FieldRefInfo)entry; 124 nti = fri.getNameAndTypeInfo(); 125 } 126 else if (entry instanceof ConstantPool.InterfaceMethodRefInfo) { 127 ConstantPool.InterfaceMethodRefInfo fri = 128 (ConstantPool.InterfaceMethodRefInfo)entry; 129 nti = fri.getNameAndTypeInfo(); 130 } 131 else { 132 System.out.println(cp); 133 System.out.println("Failed to get (interface)Method/Field ref-info from index " + getIndex() + ": " + entry); 134 System.out.println("Instruction: " + 135 Opcodes.opcodeStrings[getOpcode()&0xff]); 136 } 137 return nti.getDescriptor(); 138 } 139 140 152 153 155 158 167 } 170 | Popular Tags |