1 7 8 package org.gjt.jclasslib.structures.constants; 9 10 import org.gjt.jclasslib.structures.CPInfo; 11 import org.gjt.jclasslib.structures.InvalidByteCodeException; 12 13 import java.io.*; 14 15 21 public class ConstantNameAndTypeInfo extends CPInfo { 22 23 24 public static final int SIZE = 4; 25 26 private int nameIndex; 27 private int descriptorIndex; 28 29 public byte getTag() { 30 return CONSTANT_NAME_AND_TYPE; 31 } 32 33 public String getTagVerbose() { 34 return CONSTANT_NAME_AND_TYPE_VERBOSE; 35 } 36 37 public String getVerbose() throws InvalidByteCodeException { 38 return getName() + getDescriptor(); 39 } 40 41 45 public int getNameIndex() { 46 return nameIndex; 47 } 48 49 53 public void setNameIndex(int nameIndex) { 54 this.nameIndex = nameIndex; 55 } 56 57 61 public int getDescriptorIndex() { 62 return descriptorIndex; 63 } 64 65 69 public void setDescriptorIndex(int descriptorIndex) { 70 this.descriptorIndex = descriptorIndex; 71 } 72 73 78 public String getName() throws InvalidByteCodeException { 79 return classFile.getConstantPoolEntryName(nameIndex); 80 } 81 82 87 public String getDescriptor() throws InvalidByteCodeException { 88 return classFile.getConstantPoolEntryName(descriptorIndex); 89 } 90 91 public void read(DataInput in) 92 throws InvalidByteCodeException, IOException { 93 94 nameIndex = in.readUnsignedShort(); 95 descriptorIndex = in.readUnsignedShort(); 96 97 if (debug) debug("read "); 98 } 99 100 public void write(DataOutput out) 101 throws InvalidByteCodeException, IOException { 102 103 out.writeByte(CONSTANT_NAME_AND_TYPE); 104 out.writeShort(nameIndex); 105 out.writeShort(descriptorIndex); 106 if (debug) debug("wrote "); 107 } 108 109 protected void debug(String message) { 110 super.debug(message + getTagVerbose() + " with name_index " + nameIndex + 111 " and descriptor_index " + descriptorIndex); 112 } 113 114 public boolean equals(Object object) { 115 if (!(object instanceof ConstantNameAndTypeInfo)) { 116 return false; 117 } 118 ConstantNameAndTypeInfo constantNameAndTypeInfo = (ConstantNameAndTypeInfo)object; 119 return super.equals(object) && 120 constantNameAndTypeInfo.nameIndex == nameIndex && 121 constantNameAndTypeInfo.descriptorIndex == descriptorIndex; 122 } 123 124 public int hashCode() { 125 return super.hashCode() ^ nameIndex ^ descriptorIndex; 126 } 127 128 } 129 | Popular Tags |