1 17 package org.apache.bcel.classfile; 18 19 import java.io.DataInputStream ; 20 import java.io.DataOutputStream ; 21 import java.io.IOException ; 22 import org.apache.bcel.Constants; 23 24 34 public final class ConstantNameAndType extends Constant { 35 36 private int name_index; private int signature_index; 39 40 43 public ConstantNameAndType(ConstantNameAndType c) { 44 this(c.getNameIndex(), c.getSignatureIndex()); 45 } 46 47 48 54 ConstantNameAndType(DataInputStream file) throws IOException { 55 this(file.readUnsignedShort(), file.readUnsignedShort()); 56 } 57 58 59 63 public ConstantNameAndType(int name_index, int signature_index) { 64 super(Constants.CONSTANT_NameAndType); 65 this.name_index = name_index; 66 this.signature_index = signature_index; 67 } 68 69 70 77 public void accept( Visitor v ) { 78 v.visitConstantNameAndType(this); 79 } 80 81 82 88 public final void dump( DataOutputStream file ) throws IOException { 89 file.writeByte(tag); 90 file.writeShort(name_index); 91 file.writeShort(signature_index); 92 } 93 94 95 98 public final int getNameIndex() { 99 return name_index; 100 } 101 102 103 105 public final String getName( ConstantPool cp ) { 106 return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8); 107 } 108 109 110 113 public final int getSignatureIndex() { 114 return signature_index; 115 } 116 117 118 120 public final String getSignature( ConstantPool cp ) { 121 return cp.constantToString(getSignatureIndex(), Constants.CONSTANT_Utf8); 122 } 123 124 125 128 public final void setNameIndex( int name_index ) { 129 this.name_index = name_index; 130 } 131 132 133 136 public final void setSignatureIndex( int signature_index ) { 137 this.signature_index = signature_index; 138 } 139 140 141 144 public final String toString() { 145 return super.toString() + "(name_index = " + name_index + ", signature_index = " 146 + signature_index + ")"; 147 } 148 } 149 | Popular Tags |