1 package com.sun.org.apache.bcel.internal.classfile; 2 3 56 57 import com.sun.org.apache.bcel.internal.Constants; 58 import java.io.*; 59 60 69 public final class ConstantClass extends Constant implements ConstantObject { 70 private int name_index; 72 75 public ConstantClass(ConstantClass c) { 76 this(c.getNameIndex()); 77 } 78 79 85 ConstantClass(DataInputStream file) throws IOException 86 { 87 this(file.readUnsignedShort()); 88 } 89 90 93 public ConstantClass(int name_index) { 94 super(Constants.CONSTANT_Class); 95 this.name_index = name_index; 96 } 97 98 105 public void accept(Visitor v) { 106 v.visitConstantClass(this); 107 } 108 109 115 public final void dump(DataOutputStream file) throws IOException 116 { 117 file.writeByte(tag); 118 file.writeShort(name_index); 119 } 120 121 124 public final int getNameIndex() { return name_index; } 125 126 129 public final void setNameIndex(int name_index) { 130 this.name_index = name_index; 131 } 132 133 134 136 public Object getConstantValue(ConstantPool cp) { 137 Constant c = cp.getConstant(name_index, Constants.CONSTANT_Utf8); 138 return ((ConstantUtf8)c).getBytes(); 139 } 140 141 143 public String getBytes(ConstantPool cp) { 144 return (String )getConstantValue(cp); 145 } 146 147 150 public final String toString() { 151 return super.toString() + "(name_index = " + name_index + ")"; 152 } 153 } 154 | Popular Tags |