Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

LocalVariableTable.java

00001 package de.fub.bytecode.classfile;
00002 
00003 import  de.fub.bytecode.Constants;
00004 import  java.io.*;
00005 
00006 /**
00007  * This class is derived from <em>Attribute</em> and represents colection of local 
00008  * variables in a method. This attribute is used by the <em>Code</em> attribute.
00009  *
00010  * @version $Id: LocalVariableTable.java,v 1.1.1.1 2002/01/24 03:41:37 pserver Exp $
00011  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00012  * @see     Code
00013  * @see     LocalVariable
00014  */
00015 public class LocalVariableTable extends Attribute {
00016   private int             local_variable_table_length; // Table of local
00017   private LocalVariable[] local_variable_table;        // variables
00018 
00019   /**
00020    * @param name_index Index in constant pool to `LocalVariableTable'
00021    * @param length Content length in bytes
00022    * @param local_variable_table Table of local variables
00023    * @param constant_pool Array of constants
00024    */
00025   public LocalVariableTable(int name_index, int length,
00026                 LocalVariable[] local_variable_table,
00027                 ConstantPool    constant_pool)
00028   {
00029     super(Constants.ATTR_LOCAL_VARIABLE_TABLE, name_index, length, constant_pool);
00030     setLocalVariableTable(local_variable_table);
00031   }  
00032   /**
00033    * Construct object from file stream.
00034    * @param name_index Index in constant pool
00035    * @param length Content length in bytes
00036    * @param file Input stream
00037    * @param constant_pool Array of constants
00038    * @throw IOException
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    * Initialize from another object. Note that both objects use the same
00053    * references (shallow copy). Use clone() for a physical copy.
00054    */
00055   public LocalVariableTable(LocalVariableTable c) {
00056     this(c.getNameIndex(), c.getLength(), c.getLocalVariableTable(),
00057      c.getConstantPool());
00058   }  
00059   /**
00060    * Called by objects that are traversing the nodes of the tree implicitely
00061    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00062    * fields, attributes, etc. spawns a tree of objects.
00063    *
00064    * @param v Visitor object
00065    */
00066   public void accept(Visitor v) {
00067     v.visitLocalVariableTable(this);
00068   }  
00069   /**
00070    * @return deep copy of this attribute
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    * Dump local variable table attribute to file stream in binary format.
00084    *
00085    * @param file Output file stream
00086    * @throw IOException
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    * @return Array of local variables of method.
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    * @return String representation.
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 }

Generated at Thu Feb 7 06:49:49 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001