1 25 26 package org.netbeans.modules.classfile; 27 28 33 abstract class CPFieldMethodInfo extends CPNameAndTypeInfo { 34 int iClass; 35 int iNameAndType; 36 37 CPFieldMethodInfo(ConstantPool pool,int iClass,int iNameAndType) { 38 super(pool); 39 this.iClass = iClass; 40 this.iNameAndType = iNameAndType; 41 } 42 43 public final int getClassID() { 44 return iClass; 45 } 46 47 public final int getFieldID() { 48 return iNameAndType; 49 } 50 51 public final ClassName getClassName() { 52 return ClassName.getClassName( 53 ((CPName)pool.cpEntries[iClass]).getName()); 54 } 55 56 void setClassNameIndex(int index) { 57 iClass = index; 58 } 59 60 public final String getFieldName() { 61 return ((CPNameAndTypeInfo)pool.cpEntries[iNameAndType]).getName(); 62 } 63 64 public String toString() { 65 return getClass().getName() + ": class=" + getClassName() + ", name=" + getName() + ", descriptor=" + getDescriptor(); } 68 69 public final String getSignature() { 70 return getSignature(getDescriptor(), true); 71 } 72 73 static String getSignature(String s, boolean fullName) { 74 StringBuffer sb = new StringBuffer (); 75 int arrays = 0; 76 int i = 0; 77 while (i < s.length()) { 78 char ch = s.charAt(i++); 79 switch (ch) { 80 case 'B': sb.append("byte"); continue; case 'C': sb.append("char"); continue; case 'D': sb.append("double"); continue; case 'F': sb.append("float"); continue; case 'I': sb.append("int"); continue; case 'J': sb.append("long"); continue; case 'S': sb.append("short"); continue; case 'Z': sb.append("boolean"); continue; case 'V': sb.append("void"); continue; 90 case 'L': 91 int l = s.indexOf(';'); 92 String cls = s.substring(1, l).replace('/', '.'); 93 if (!fullName) { 94 int idx = cls.lastIndexOf('.'); 95 if (idx >= 0) 96 cls = cls.substring(idx+1); 97 } 98 sb.append(cls); 99 i = l + 1; 100 continue; 101 102 case '[': 103 arrays++; 104 continue; 105 default: 106 break; } 108 } 109 while (arrays-- > 0) 110 sb.append("[]"); 111 return sb.toString(); 112 } 113 114 void resolve(CPEntry[] cpEntries) { 115 CPNameAndTypeInfo nati = (CPNameAndTypeInfo)cpEntries[iNameAndType]; 117 setNameIndex(nati.iName); 118 setDescriptorIndex(nati.iDesc); 119 } 120 } 121 | Popular Tags |