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 abstract class ConstantReference extends CPInfo { 22 23 24 public static final int SIZE = 4; 25 26 27 protected int classIndex; 28 29 protected int nameAndTypeIndex; 30 31 public String getVerbose() throws InvalidByteCodeException { 32 33 ConstantNameAndTypeInfo nameAndType = getNameAndTypeInfo(); 34 35 return classFile.getConstantPoolEntryName(classIndex) + "." + 36 classFile.getConstantPoolEntryName(nameAndType.getNameIndex()); 37 } 38 39 44 public int getClassIndex() { 45 return classIndex; 46 } 47 48 53 public void setClassIndex(int classIndex) { 54 this.classIndex = classIndex; 55 } 56 57 62 public int getNameAndTypeIndex() { 63 return nameAndTypeIndex; 64 } 65 66 71 public void setNameAndTypeIndex(int nameAndTypeIndex) { 72 this.nameAndTypeIndex = nameAndTypeIndex; 73 } 74 75 80 public ConstantClassInfo getClassInfo() throws InvalidByteCodeException { 81 return (ConstantClassInfo)getClassFile().getConstantPoolEntry(classIndex, ConstantClassInfo.class); 82 } 83 84 89 public ConstantNameAndTypeInfo getNameAndTypeInfo() throws InvalidByteCodeException { 90 return (ConstantNameAndTypeInfo)classFile.getConstantPoolEntry( 91 nameAndTypeIndex, 92 ConstantNameAndTypeInfo.class); 93 } 94 95 public void read(DataInput in) 96 throws InvalidByteCodeException, IOException { 97 98 classIndex = in.readUnsignedShort(); 99 nameAndTypeIndex = in.readUnsignedShort(); 100 } 101 102 public void write(DataOutput out) 103 throws InvalidByteCodeException, IOException { 104 105 out.writeShort(classIndex); 106 out.writeShort(nameAndTypeIndex); 107 } 108 109 public boolean equals(Object object) { 110 if (!(object instanceof ConstantReference)) { 111 return false; 112 } 113 ConstantReference constantReference = (ConstantReference)object; 114 return super.equals(object) && 115 constantReference.classIndex == classIndex && 116 constantReference.nameAndTypeIndex == nameAndTypeIndex; 117 } 118 119 public int hashCode() { 120 return super.hashCode() ^ classIndex ^ nameAndTypeIndex; 121 } 122 123 } 124 | Popular Tags |