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 ConstantStringInfo extends CPInfo { 22 23 24 public static final int SIZE = 2; 25 26 private int stringIndex; 27 28 public byte getTag() { 29 return CONSTANT_STRING; 30 } 31 32 public String getTagVerbose() { 33 return CONSTANT_STRING_VERBOSE; 34 } 35 36 public String getVerbose() throws InvalidByteCodeException { 37 return classFile.getConstantPoolEntryName(stringIndex); 38 } 39 40 45 public int getStringIndex() { 46 return stringIndex; 47 } 48 49 54 public void setStringIndex(int stringIndex) { 55 this.stringIndex = stringIndex; 56 } 57 58 public void read(DataInput in) 59 throws InvalidByteCodeException, IOException { 60 61 stringIndex = in.readUnsignedShort(); 62 if (debug) debug("read "); 63 } 64 65 public void write(DataOutput out) 66 throws InvalidByteCodeException, IOException { 67 68 out.writeByte(CONSTANT_STRING); 69 out.writeShort(stringIndex); 70 if (debug) debug("wrote "); 71 } 72 73 protected void debug(String message) { 74 super.debug(message + getTagVerbose() + " with string_index " + stringIndex); 75 } 76 77 public boolean equals(Object object) { 78 if (!(object instanceof ConstantStringInfo)) { 79 return false; 80 } 81 ConstantStringInfo constantStringInfo = (ConstantStringInfo)object; 82 return super.equals(object) && constantStringInfo.stringIndex == stringIndex; 83 } 84 85 public int hashCode() { 86 return super.hashCode() ^ stringIndex; 87 } 88 89 } 90 | Popular Tags |