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
00015 public class LocalVariableTable extends Attribute {
00016 private int local_variable_table_length;
00017 private LocalVariable[] local_variable_table;
00018
00019
00020
00021
00022
00023
00024
00025 public LocalVariableTable(int name_index, int length,
00026 LocalVariable[] local_variable_table,
00027 ConstantPool constant_pool)
00028 {
00029 super(ATTR_LOCAL_VARIABLE_TABLE, name_index, length, constant_pool);
00030 setLocalVariableTable(local_variable_table);
00031 }
00032
00033
00034
00035
00036
00037
00038
00039
00040 LocalVariableTable(int name_index, int length, DataInputStream file,
00041 ConstantPool constant_pool) throws IOException
00042 {
00043 this(name_index, length, (LocalVariable[])null, constant_pool);
00044
00045 local_variable_table_length = (file.readUnsignedShort());
00046 local_variable_table = new LocalVariable[local_variable_table_length];
00047
00048 for(int i=0; i < local_variable_table_length; i++)
00049 local_variable_table[i] = new LocalVariable(file, constant_pool);
00050 }
00051
00052
00053
00054
00055 public LocalVariableTable(LocalVariableTable c) {
00056 this(c.getNameIndex(), c.getLength(), c.getLocalVariableTable(),
00057 c.getConstantPool());
00058 }
00059
00060
00061
00062
00063
00064
00065
00066 public void accept(Visitor v) {
00067 v.visitLocalVariableTable(this);
00068 }
00069
00070
00071
00072 public Attribute copy(ConstantPool constant_pool) {
00073 LocalVariableTable c = (LocalVariableTable)clone();
00074
00075 c.local_variable_table = new LocalVariable[local_variable_table_length];
00076 for(int i=0; i < local_variable_table_length; i++)
00077 c.local_variable_table[i] = local_variable_table[i].copy();
00078
00079 c.constant_pool = constant_pool;
00080 return c;
00081 }
00082
00083
00084
00085
00086
00087
00088 public final void dump(DataOutputStream file) throws IOException
00089 {
00090 super.dump(file);
00091 file.writeShort(local_variable_table_length);
00092 for(int i=0; i < local_variable_table_length; i++)
00093 local_variable_table[i].dump(file);
00094 }
00095
00096
00097
00098 public final LocalVariable[] getLocalVariableTable() {
00099 return local_variable_table;
00100 }
00101 public final int getTableLength() { return local_variable_table_length; }
00102 public final void setLocalVariableTable(LocalVariable[] local_variable_table)
00103 {
00104 this.local_variable_table = local_variable_table;
00105 local_variable_table_length = (local_variable_table == null)? 0 :
00106 local_variable_table.length;
00107 }
00108
00109
00110
00111 public final String toString() {
00112 StringBuffer buf = new StringBuffer("");
00113
00114 for(int i=0; i < local_variable_table_length; i++) {
00115 buf.append(local_variable_table[i].toString());
00116
00117 if(i < local_variable_table_length - 1)
00118 buf.append('\n');
00119 }
00120
00121 return buf.toString();
00122 }
00123 }