1 26 package net.sf.javaguard.classfile; 27 28 import java.io.*; 29 30 31 36 abstract public class RefCpInfo extends CpInfo { 37 38 private int classIndex; 39 40 private int nameAndTypeIndex; 41 42 43 44 45 48 protected RefCpInfo(int tag) { 49 super(tag); 50 } 51 52 53 54 55 59 protected int getClassIndex() { 60 return classIndex; 61 } 62 63 64 68 protected void setClassIndex(int index) { 69 classIndex = index; 70 } 71 72 73 74 75 79 protected int getNameAndTypeIndex() { 80 return nameAndTypeIndex; 81 } 82 83 84 88 protected void setNameAndTypeIndex(int index) { 89 nameAndTypeIndex = index; 90 } 91 92 93 94 95 98 protected void markNTRefs(ConstantPool pool) { 99 pool.incRefCount(getNameAndTypeIndex()); 100 } 101 102 103 104 105 109 protected void readInfo(DataInput din) 110 throws IOException { 111 setClassIndex(din.readUnsignedShort()); 112 setNameAndTypeIndex(din.readUnsignedShort()); 113 } 114 115 116 120 protected void writeInfo(DataOutput dout) 121 throws IOException { 122 dout.writeShort(getClassIndex()); 123 dout.writeShort(getNameAndTypeIndex()); 124 } 125 126 127 128 129 134 public void dump(PrintWriter pw, ClassFile cf, int index) { 135 pw.print('['); pw.print(index); pw.print("]: "); 136 String name = getClass().getName(); 137 pw.println(name.substring(name.lastIndexOf('.')+1)); 138 pw.print(" -> class index: "); 139 pw.println(getClassIndex()); 140 pw.print(" class name: "); 141 pw.println( ((Utf8CpInfo) cf.getCpEntry(((ClassCpInfo) cf.getCpEntry(getClassIndex())).getClassNameIndex())).getString()); 142 pw.print(" -> name and type index: "); 143 pw.println(getNameAndTypeIndex()); 144 NameAndTypeCpInfo cpInfo = (NameAndTypeCpInfo) cf.getCpEntry(getNameAndTypeIndex()); 145 pw.print(" name: '"); 146 pw.print( ((Utf8CpInfo) cf.getCpEntry(cpInfo.getNameIndex())).getString()); 147 pw.println('\''); 148 pw.print(" descriptor: '"); 149 pw.print( ((Utf8CpInfo) cf.getCpEntry(cpInfo.getDescriptorIndex())).getString()); 150 pw.println('\''); 151 } 152 } 153 | Popular Tags |