1 16 17 package org.cojen.classfile.constant; 18 19 import java.io.DataOutput ; 20 import java.io.IOException ; 21 import org.cojen.classfile.ConstantInfo; 22 import org.cojen.classfile.ConstantPool; 23 import org.cojen.classfile.Descriptor; 24 25 31 public class ConstantNameAndTypeInfo extends ConstantInfo { 32 private final ConstantUTFInfo mNameConstant; 33 private final ConstantUTFInfo mDescriptorConstant; 34 35 private final Descriptor mType; 36 37 public ConstantNameAndTypeInfo(ConstantUTFInfo nameConstant, 38 ConstantUTFInfo descConstant) { 39 super(TAG_NAME_AND_TYPE); 40 mNameConstant = nameConstant; 41 mDescriptorConstant = descConstant; 42 mType = Descriptor.parse(descConstant.getValue()); 43 } 44 45 public ConstantNameAndTypeInfo(ConstantPool cp, 46 String name, 47 Descriptor type) { 48 super(TAG_NAME_AND_TYPE); 49 mNameConstant = cp.addConstantUTF(name); 50 mDescriptorConstant = cp.addConstantUTF(type.getDescriptor()); 51 mType = type; 52 } 53 54 public String getName() { 55 return mNameConstant.getValue(); 56 } 57 58 public Descriptor getType() { 59 return mType; 60 } 61 62 public int hashCode() { 63 return mNameConstant.hashCode(); 64 } 65 66 public boolean equals(Object obj) { 67 if (obj instanceof ConstantNameAndTypeInfo) { 68 ConstantNameAndTypeInfo other = (ConstantNameAndTypeInfo)obj; 69 return mNameConstant.equals(other.mNameConstant) && 70 mType.getDescriptor().equals(other.mType.getDescriptor()); 71 } 72 73 return false; 74 } 75 76 public void writeTo(DataOutput dout) throws IOException { 77 super.writeTo(dout); 78 dout.writeShort(mNameConstant.getIndex()); 79 dout.writeShort(mDescriptorConstant.getIndex()); 80 } 81 82 public String toString() { 83 return "CONSTANT_NameAndType_info: " + getName() + ", " + getType(); 84 } 85 } 86 | Popular Tags |