1 52 53 package com.go.trove.classfile; 54 55 import java.io.*; 56 57 65 public class ConstantFieldInfo extends ConstantInfo { 66 private ConstantClassInfo mParentClass; 67 private ConstantNameAndTypeInfo mNameAndType; 68 69 74 static ConstantFieldInfo make(ConstantPool cp, 75 ConstantClassInfo parentClass, 76 ConstantNameAndTypeInfo nameAndType) { 77 ConstantInfo ci = new ConstantFieldInfo(parentClass, nameAndType); 78 return (ConstantFieldInfo)cp.addConstant(ci); 79 } 80 81 ConstantFieldInfo(ConstantClassInfo parentClass, 82 ConstantNameAndTypeInfo nameAndType) { 83 super(TAG_FIELD); 84 85 mParentClass = parentClass; 86 mNameAndType = nameAndType; 87 } 88 89 public ConstantClassInfo getParentClass() { 90 return mParentClass; 91 } 92 93 public ConstantNameAndTypeInfo getNameAndType() { 94 return mNameAndType; 95 } 96 97 public int hashCode() { 98 return mNameAndType.hashCode(); 99 } 100 101 public boolean equals(Object obj) { 102 if (obj instanceof ConstantFieldInfo) { 103 ConstantFieldInfo other = (ConstantFieldInfo)obj; 104 return (mParentClass.equals(other.mParentClass) && 105 mNameAndType.equals(other.mNameAndType)); 106 } 107 108 return false; 109 } 110 111 public void writeTo(DataOutput dout) throws IOException { 112 super.writeTo(dout); 113 dout.writeShort(mParentClass.getIndex()); 114 dout.writeShort(mNameAndType.getIndex()); 115 } 116 117 public String toString() { 118 StringBuffer buf = new StringBuffer ("CONSTANT_Fieldref_info: "); 119 120 ConstantClassInfo parent = getParentClass(); 121 122 buf.append(parent.getClassName()); 123 for (int i = parent.getDimensions(); i > 0; i--) { 124 buf.append('['); 125 buf.append(']'); 126 } 127 128 ConstantNameAndTypeInfo cnati = getNameAndType(); 129 130 buf.append(' '); 131 buf.append(cnati.getName()); 132 buf.append(' '); 133 buf.append(cnati.getType()); 134 135 return buf.toString(); 136 } 137 } 138 | Popular Tags |