1 30 31 41 package jbet; 42 import java.io.*; 43 44 class CpMethodRef extends CpEntry { 45 47 String cname; 48 String mname; 49 Descriptor t; 50 51 53 public int classIndex = -1; 54 public int nameAndTypeIndex = -1; 55 56 61 CpMethodRef(int i, CPInterface cp, boolean iface) { 62 super(i, (iface ? 63 CPInterface.CONSTANT_InterfaceMethodref : 64 CPInterface.CONSTANT_Methodref), cp); 65 } 66 67 74 CpMethodRef(CPInterface cp, boolean iface, 75 String cname, String mname, Descriptor t) { 76 super(cp.poolCount(), (iface ? 77 CPInterface.CONSTANT_InterfaceMethodref : 78 CPInterface.CONSTANT_Methodref), cp); 79 this.cname = cname; 80 this.mname = mname; 81 this.t = t; 82 } 83 84 87 public String toString() { 88 return classname() + " " + name() + " " + descriptor(); 89 } 90 91 String classname() { return cname; } 92 String name() { return mname; } 93 Descriptor descriptor() { return t; } 94 95 100 void setup() throws ClassFileException { 101 if (cname == null || mname == null || t == null) { 102 CpClass cpc = constantPool.cpClassAt(classIndex); 103 cpc.setup(); 104 CpNameAndType cpnat = constantPool.cpNameAndTypeAt(nameAndTypeIndex); 105 cpnat.setup(); 106 cname = cpc.string(); 107 mname = cpnat.name(); 108 t = cpnat.descriptor(); 109 } 110 } 111 112 115 public int hashCode() { 116 return cname.hashCode() + mname.hashCode() + t.hashCode(); 117 } 118 119 123 public boolean equals(Object o) { 124 if (!(o instanceof CpMethodRef)) return false; 125 CpMethodRef cp = (CpMethodRef) o; 126 return cp.cname.equals(cname) && cp.mname.equals(mname) && 127 cp.t.equals(t); 128 } 129 130 133 void write(DataOutputStream dataOut) throws IOException { 134 dataOut.writeByte(tag); 135 dataOut.writeShort(classIndex); 136 dataOut.writeShort(nameAndTypeIndex); 137 } 138 } 139 | Popular Tags |