1 package com.sun.org.apache.bcel.internal.classfile; 2 3 56 import java.io.*; 57 import com.sun.org.apache.bcel.internal.Constants; 58 59 68 public abstract class ConstantCP extends Constant { 69 71 protected int class_index, name_and_type_index; 72 73 76 public ConstantCP(ConstantCP c) { 77 this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex()); 78 } 79 80 87 ConstantCP(byte tag, DataInputStream file) throws IOException 88 { 89 this(tag, file.readUnsignedShort(), file.readUnsignedShort()); 90 } 91 92 96 protected ConstantCP(byte tag, int class_index, 97 int name_and_type_index) { 98 super(tag); 99 this.class_index = class_index; 100 this.name_and_type_index = name_and_type_index; 101 } 102 103 109 public final void dump(DataOutputStream file) throws IOException 110 { 111 file.writeByte(tag); 112 file.writeShort(class_index); 113 file.writeShort(name_and_type_index); 114 } 115 116 119 public final int getClassIndex() { return class_index; } 120 121 124 public final int getNameAndTypeIndex() { return name_and_type_index; } 125 126 129 public final void setClassIndex(int class_index) { 130 this.class_index = class_index; 131 } 132 133 136 public String getClass(ConstantPool cp) { 137 return cp.constantToString(class_index, Constants.CONSTANT_Class); 138 } 139 140 143 public final void setNameAndTypeIndex(int name_and_type_index) { 144 this.name_and_type_index = name_and_type_index; 145 } 146 147 150 public final String toString() { 151 return super.toString() + "(class_index = " + class_index + 152 ", name_and_type_index = " + name_and_type_index + ")"; 153 } 154 } 155 | Popular Tags |