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 68 public abstract class Constant implements Cloneable , Node { 69 77 protected byte tag; 78 79 Constant(byte tag) { this.tag = tag; } 80 81 88 public abstract void accept(Visitor v); 89 90 public abstract void dump(DataOutputStream file) throws IOException; 91 92 96 public final byte getTag() { return tag; } 97 98 101 public String toString() { 102 return Constants.CONSTANT_NAMES[tag] + "[" + tag + "]"; 103 } 104 105 108 public Constant copy() { 109 try { 110 return (Constant)super.clone(); 111 } catch(CloneNotSupportedException e) {} 112 113 return null; 114 } 115 116 public Object clone() throws CloneNotSupportedException { 117 return super.clone(); 118 } 119 120 126 static final Constant readConstant(DataInputStream file) 127 throws IOException, ClassFormatError 128 { 129 byte b = file.readByte(); 131 switch(b) { 132 case Constants.CONSTANT_Class: return new ConstantClass(file); 133 case Constants.CONSTANT_Fieldref: return new ConstantFieldref(file); 134 case Constants.CONSTANT_Methodref: return new ConstantMethodref(file); 135 case Constants.CONSTANT_InterfaceMethodref: return new 136 ConstantInterfaceMethodref(file); 137 case Constants.CONSTANT_String: return new ConstantString(file); 138 case Constants.CONSTANT_Integer: return new ConstantInteger(file); 139 case Constants.CONSTANT_Float: return new ConstantFloat(file); 140 case Constants.CONSTANT_Long: return new ConstantLong(file); 141 case Constants.CONSTANT_Double: return new ConstantDouble(file); 142 case Constants.CONSTANT_NameAndType: return new ConstantNameAndType(file); 143 case Constants.CONSTANT_Utf8: return new ConstantUtf8(file); 144 default: 145 throw new ClassFormatError ("Invalid byte tag in constant pool: " + b); 146 } 147 } 148 } 149 | Popular Tags |