00001 package de.fub.bytecode.classfile;
00002
00003 import de.fub.bytecode.Constants;
00004 import java.io.*;
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 public final class LocalVariable implements Constants, Cloneable {
00015 private int start_pc;
00016 private int length;
00017 private int name_index;
00018 private int signature_index;
00019 private int index;
00020
00021
00022
00023 private ConstantPool constant_pool;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 public LocalVariable(int start_pc, int length, int name_index,
00034 int signature_index, int index,
00035 ConstantPool constant_pool)
00036 {
00037 this.start_pc = start_pc;
00038 this.length = length;
00039 this.name_index = name_index;
00040 this.signature_index = signature_index;
00041 this.index = index;
00042 this.constant_pool = constant_pool;
00043 }
00044
00045
00046
00047
00048 public LocalVariable(LocalVariable c) {
00049 this(c.getStartPC(), c.getLength(), c.getNameIndex(),
00050 c.getSignatureIndex(), c.getIndex(), c.getConstantPool());
00051 }
00052
00053
00054
00055
00056
00057 LocalVariable(DataInputStream file, ConstantPool constant_pool)
00058 throws IOException
00059 {
00060 this(file.readUnsignedShort(), file.readUnsignedShort(),
00061 file.readUnsignedShort(), file.readUnsignedShort(),
00062 file.readUnsignedShort(), constant_pool);
00063 }
00064
00065
00066
00067
00068
00069
00070
00071 public void accept(Visitor v) {
00072 v.visitLocalVariable(this);
00073 }
00074
00075
00076
00077 public LocalVariable copy() {
00078 try {
00079 return (LocalVariable)clone();
00080 } catch(CloneNotSupportedException e) {}
00081
00082 return null;
00083 }
00084
00085
00086
00087
00088
00089
00090 public final void dump(DataOutputStream file) throws IOException
00091 {
00092 file.writeShort(start_pc);
00093 file.writeShort(length);
00094 file.writeShort(name_index);
00095 file.writeShort(signature_index);
00096 file.writeShort(index);
00097 }
00098
00099
00100
00101
00102 public final ConstantPool getConstantPool() { return constant_pool; }
00103
00104
00105
00106 public final int getIndex() { return index; }
00107
00108
00109
00110 public final int getLength() { return length; }
00111
00112
00113
00114 public final String getName() {
00115 ConstantUtf8 c;
00116
00117 c = (ConstantUtf8)constant_pool.getConstant(name_index, CONSTANT_Utf8);
00118 return c.getBytes();
00119 }
00120
00121
00122
00123 public final int getNameIndex() { return name_index; }
00124
00125
00126
00127 public final String getSignature() {
00128 ConstantUtf8 c;
00129 c = (ConstantUtf8)constant_pool.getConstant(signature_index,
00130 CONSTANT_Utf8);
00131 return c.getBytes();
00132 }
00133
00134
00135
00136 public final int getSignatureIndex() { return signature_index; }
00137
00138
00139
00140 public final int getStartPC() { return start_pc; }
00141
00142
00143
00144
00145 public final void setConstantPool(ConstantPool constant_pool) {
00146 this.constant_pool = constant_pool;
00147 }
00148
00149
00150
00151 public final void setIndex(int index) { this.index = index; }
00152
00153
00154
00155 public final void setLength(int length) {
00156 this.length = length;
00157 }
00158
00159
00160
00161 public final void setNameIndex(int name_index) {
00162 this.name_index = name_index;
00163 }
00164
00165
00166
00167 public final void setSignatureIndex(int signature_index) {
00168 this.signature_index = signature_index;
00169 }
00170
00171
00172
00173 public final void setStartPC(int start_pc) {
00174 this.start_pc = start_pc;
00175 }
00176
00177
00178
00179 public final String toString() {
00180 String name = getName(), signature = Utility.signatureToString(getSignature());
00181
00182 return "LocalVariable(start_pc = " + start_pc + ", length = " + length +
00183 ", index = " + index + ":" + signature + " " + name + ")";
00184 }
00185 }