1 17 package org.apache.bcel.generic; 18 19 import org.apache.bcel.classfile.ConstantCP; 20 import org.apache.bcel.classfile.ConstantNameAndType; 21 import org.apache.bcel.classfile.ConstantPool; 22 import org.apache.bcel.classfile.ConstantUtf8; 23 24 31 public abstract class FieldOrMethod extends CPInstruction implements LoadClass { 32 33 37 FieldOrMethod() { 38 } 39 40 41 44 protected FieldOrMethod(short opcode, int index) { 45 super(opcode, index); 46 } 47 48 49 51 public String getSignature( ConstantPoolGen cpg ) { 52 ConstantPool cp = cpg.getConstantPool(); 53 ConstantCP cmr = (ConstantCP) cp.getConstant(index); 54 ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex()); 55 return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes(); 56 } 57 58 59 61 public String getName( ConstantPoolGen cpg ) { 62 ConstantPool cp = cpg.getConstantPool(); 63 ConstantCP cmr = (ConstantCP) cp.getConstant(index); 64 ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex()); 65 return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes(); 66 } 67 68 69 78 public String getClassName( ConstantPoolGen cpg ) { 79 ConstantPool cp = cpg.getConstantPool(); 80 ConstantCP cmr = (ConstantCP) cp.getConstant(index); 81 String className = cp.getConstantString(cmr.getClassIndex(), 82 org.apache.bcel.Constants.CONSTANT_Class); 83 if (className.startsWith("[")) { 84 return "java.lang.Object"; 86 } 87 return className.replace('/', '.'); 88 } 89 90 91 96 public ObjectType getClassType( ConstantPoolGen cpg ) { 97 return new ObjectType(getClassName(cpg)); 98 } 99 100 101 109 public ReferenceType getReferenceType( ConstantPoolGen cpg ) { 110 ConstantPool cp = cpg.getConstantPool(); 111 ConstantCP cmr = (ConstantCP) cp.getConstant(index); 112 String className = cp.getConstantString(cmr.getClassIndex(), 113 org.apache.bcel.Constants.CONSTANT_Class); 114 if (className.startsWith("[")) { 115 return (ArrayType) Type.getType(className); 116 } else { 117 className = className.replace('/', '.'); 118 return new ObjectType(className); 119 } 120 } 121 122 123 125 public ObjectType getLoadClassType( ConstantPoolGen cpg ) { 126 return getClassType(cpg); 127 } 128 } 129 | Popular Tags |