1 52 53 package com.go.trove.classfile; 54 55 import java.io.*; 56 57 65 public class ConstantNameAndTypeInfo extends ConstantInfo { 66 private String mName; 67 private Descriptor mType; 68 69 private ConstantUTFInfo mNameConstant; 70 private ConstantUTFInfo mDescriptorConstant; 71 72 78 static ConstantNameAndTypeInfo make(ConstantPool cp, 79 String name, 80 Descriptor type) { 81 ConstantInfo ci = new ConstantNameAndTypeInfo(cp, name, type); 82 return (ConstantNameAndTypeInfo)cp.addConstant(ci); 83 } 84 85 ConstantNameAndTypeInfo(ConstantUTFInfo nameConstant, 86 ConstantUTFInfo descConstant) { 87 super(TAG_NAME_AND_TYPE); 88 mNameConstant = nameConstant; 89 mDescriptorConstant = descConstant; 90 91 mName = nameConstant.getValue(); 92 mType = Descriptor.parse(descConstant.getValue()); 93 } 94 95 private ConstantNameAndTypeInfo(ConstantPool cp, 96 String name, 97 Descriptor type) { 98 super(TAG_NAME_AND_TYPE); 99 mName = name; 100 mType = type; 101 102 mNameConstant = ConstantUTFInfo.make(cp, name); 103 mDescriptorConstant = ConstantUTFInfo.make(cp, mType.toString()); 104 } 105 106 public String getName() { 107 return mName; 108 } 109 110 public Descriptor getType() { 111 return mType; 112 } 113 114 public int hashCode() { 115 return mName.hashCode(); 116 } 117 118 public boolean equals(Object obj) { 119 if (obj instanceof ConstantNameAndTypeInfo) { 120 ConstantNameAndTypeInfo other = (ConstantNameAndTypeInfo)obj; 121 return mName.equals(other.mName) && 122 mType.toString().equals(other.mType.toString()); 123 } 124 125 return false; 126 } 127 128 public void writeTo(DataOutput dout) throws IOException { 129 super.writeTo(dout); 130 dout.writeShort(mNameConstant.getIndex()); 131 dout.writeShort(mDescriptorConstant.getIndex()); 132 } 133 134 public String toString() { 135 return "CONSTANT_NameAndType_info: " + getName() + ", " + getType(); 136 } 137 } 138 | Popular Tags |