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 class LocalVariableTable extends Attribute { 70 private int local_variable_table_length; private LocalVariable[] local_variable_table; 73 77 public LocalVariableTable(LocalVariableTable c) { 78 this(c.getNameIndex(), c.getLength(), c.getLocalVariableTable(), 79 c.getConstantPool()); 80 } 81 82 88 public LocalVariableTable(int name_index, int length, 89 LocalVariable[] local_variable_table, 90 ConstantPool constant_pool) 91 { 92 super(Constants.ATTR_LOCAL_VARIABLE_TABLE, name_index, length, constant_pool); 93 setLocalVariableTable(local_variable_table); 94 } 95 96 104 LocalVariableTable(int name_index, int length, DataInputStream file, 105 ConstantPool constant_pool) throws IOException 106 { 107 this(name_index, length, (LocalVariable[])null, constant_pool); 108 109 local_variable_table_length = (file.readUnsignedShort()); 110 local_variable_table = new LocalVariable[local_variable_table_length]; 111 112 for(int i=0; i < local_variable_table_length; i++) 113 local_variable_table[i] = new LocalVariable(file, constant_pool); 114 } 115 116 123 public void accept(Visitor v) { 124 v.visitLocalVariableTable(this); 125 } 126 127 133 public final void dump(DataOutputStream file) throws IOException 134 { 135 super.dump(file); 136 file.writeShort(local_variable_table_length); 137 for(int i=0; i < local_variable_table_length; i++) 138 local_variable_table[i].dump(file); 139 } 140 141 144 public final LocalVariable[] getLocalVariableTable() { 145 return local_variable_table; 146 } 147 148 150 public final LocalVariable getLocalVariable(int index) { 151 for(int i=0; i < local_variable_table_length; i++) 152 if(local_variable_table[i].getIndex() == index) 153 return local_variable_table[i]; 154 155 return null; 156 } 157 158 public final void setLocalVariableTable(LocalVariable[] local_variable_table) 159 { 160 this.local_variable_table = local_variable_table; 161 local_variable_table_length = (local_variable_table == null)? 0 : 162 local_variable_table.length; 163 } 164 165 168 public final String toString() { 169 StringBuffer buf = new StringBuffer (""); 170 171 for(int i=0; i < local_variable_table_length; i++) { 172 buf.append(local_variable_table[i].toString()); 173 174 if(i < local_variable_table_length - 1) 175 buf.append('\n'); 176 } 177 178 return buf.toString(); 179 } 180 181 184 public Attribute copy(ConstantPool constant_pool) { 185 LocalVariableTable c = (LocalVariableTable)clone(); 186 187 c.local_variable_table = new LocalVariable[local_variable_table_length]; 188 for(int i=0; i < local_variable_table_length; i++) 189 c.local_variable_table[i] = local_variable_table[i].copy(); 190 191 c.constant_pool = constant_pool; 192 return c; 193 } 194 195 public final int getTableLength() { return local_variable_table_length; } 196 } 197 | Popular Tags |