1 26 package net.sf.javaguard.classfile; 27 28 import java.io.*; 29 30 31 36 public class NameAndTypeCpInfo extends CpInfo implements Cloneable { 37 38 private int nameIndex; 39 41 private int descriptorIndex; 42 43 44 45 46 48 protected NameAndTypeCpInfo() { 49 super(CONSTANT_NameAndType); 50 } 51 52 53 54 55 58 public Object clone() { 59 NameAndTypeCpInfo cloneInfo = new NameAndTypeCpInfo(); 60 cloneInfo.setNameIndex(getNameIndex()); 61 cloneInfo.setDescriptorIndex(getDescriptorIndex()); 62 cloneInfo.resetRefCount(); 63 return cloneInfo; 64 } 65 66 67 68 69 73 protected int getNameIndex() { 74 return nameIndex; 75 } 76 77 78 82 protected void setNameIndex(int index) { 83 nameIndex = index; 84 } 85 86 87 88 89 93 protected int getDescriptorIndex() { 94 return descriptorIndex; 95 } 96 97 98 102 protected void setDescriptorIndex(int index) { 103 descriptorIndex = index; 104 } 105 106 107 108 109 112 protected void markUtf8Refs(ConstantPool pool) { 113 pool.incRefCount(getNameIndex()); 114 pool.incRefCount(getDescriptorIndex()); 115 } 116 117 118 119 120 124 protected void readInfo(DataInput din) 125 throws IOException { 126 setNameIndex(din.readUnsignedShort()); 127 setDescriptorIndex(din.readUnsignedShort()); 128 } 129 130 131 135 protected void writeInfo(DataOutput dout) 136 throws IOException { 137 dout.writeShort(getNameIndex()); 138 dout.writeShort(getDescriptorIndex()); 139 } 140 141 142 143 144 149 public void dump(PrintWriter pw, ClassFile cf, int index) { 150 pw.print('['); pw.print(index); pw.println("]: NameAndTypeCpInfo"); 151 pw.print(" -> name index: "); 152 pw.println(getNameIndex()); 153 pw.print(" name: '"); 154 pw.print( ((Utf8CpInfo) cf.getCpEntry(getNameIndex())).getString()); 155 pw.println('\''); 156 pw.print(" -> descriptor index: "); 157 pw.println(getDescriptorIndex()); 158 pw.print(" descriptor: '"); 159 pw.print( ((Utf8CpInfo) cf.getCpEntry(getDescriptorIndex())).getString()); 160 pw.println('\''); 161 } 162 } 163 | Popular Tags |