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 33 public abstract class ConstantCP extends Constant { 34 35 37 protected int class_index, name_and_type_index; 38 39 40 43 public ConstantCP(ConstantCP c) { 44 this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex()); 45 } 46 47 48 55 ConstantCP(byte tag, DataInputStream file) throws IOException { 56 this(tag, file.readUnsignedShort(), file.readUnsignedShort()); 57 } 58 59 60 64 protected ConstantCP(byte tag, int class_index, int name_and_type_index) { 65 super(tag); 66 this.class_index = class_index; 67 this.name_and_type_index = name_and_type_index; 68 } 69 70 71 77 public final void dump( DataOutputStream file ) throws IOException { 78 file.writeByte(tag); 79 file.writeShort(class_index); 80 file.writeShort(name_and_type_index); 81 } 82 83 84 87 public final int getClassIndex() { 88 return class_index; 89 } 90 91 92 95 public final int getNameAndTypeIndex() { 96 return name_and_type_index; 97 } 98 99 100 103 public final void setClassIndex( int class_index ) { 104 this.class_index = class_index; 105 } 106 107 108 111 public String getClass( ConstantPool cp ) { 112 return cp.constantToString(class_index, Constants.CONSTANT_Class); 113 } 114 115 116 119 public final void setNameAndTypeIndex( int name_and_type_index ) { 120 this.name_and_type_index = name_and_type_index; 121 } 122 123 124 127 public final String toString() { 128 return super.toString() + "(class_index = " + class_index + ", name_and_type_index = " 129 + name_and_type_index + ")"; 130 } 131 } 132 | Popular Tags |