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