Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/chaoswg/xtc4y/classdesc/LocalVariableTableEntry.java


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/LocalVariableTableEntry.java,v 1.2 2003/09/08 21:03:30 toggm Exp $
2   /******************************************************************************
3    * XTC4y - eXtreme Testing Collection 4 you                                   *
4    * -------------------------------------------------------------------------- *
5    * URL: http://www.chaoswg.com/xtc4y                                          *
6    * Author: Mike Toggweiler (2.dog@gmx.ch)                                     *
7    *                                                                            *
8    * Last Updated: $Date: 2003/09/08 21:03:30 $, by $Author: toggm $            *
9    * Version: $Revision: 1.2 $                                                  *
10   * -------------------------------------------------------------------------- *
11   * COPYRIGHT:   (c) 2003 by Mike Toggweiler                                   *
12   *                                                                            *
13   * This program is free software; you can redistribute it and/or modify       *
14   * it under the terms of the GNU General Public License as published by       *
15   * the Free Software Foundation; either version 2 of the License, or          *
16   * (at your option) any later version.                                        *
17   *****************************************************************************/
18  package com.chaoswg.xtc4y.classdesc;
19  
20  import java.io.DataInputStream;
21  import java.io.DataOutputStream;
22  import java.io.IOException;
23  
24  import com.chaoswg.xtc4y.classdesc.code.Code;
25  import com.chaoswg.xtc4y.classdesc.code.instructions.Instruction;
26  
27  /**
28   * this class represents an antry in the localvariabletable attribute, 
29   * described in §4.7.9
30   * TBD: make an entry editable through methods
31   * @author Mike Toggweiler
32   **/
33  public class LocalVariableTableEntry implements CodeCompatible {
34      private short startPc;
35      private short length;
36      private UTF8CPEntry descriptor;
37      private UTF8CPEntry name;
38      private short index;
39  
40      private Instruction startInstr;
41  
42      /**
43       * Creates a LocalVariableTableEntry and initializes it from a 
44       * DataInputStream
45       * @param dis the DataInputStream to read from
46       * @param cp the constant pool to resolve indices
47       **/
48      protected LocalVariableTableEntry(DataInputStream dis, ConstantPool cp)
49    throws IOException {
50    startPc = (short)dis.readUnsignedShort();
51    length = (short)dis.readUnsignedShort();
52    short nameIndex = (short)dis.readUnsignedShort();
53    short descIndex = (short)dis.readUnsignedShort();
54    index = (short)dis.readUnsignedShort();
55  
56    name = (UTF8CPEntry)cp.getCPEntryAt(nameIndex);
57    descriptor = (UTF8CPEntry)cp.getCPEntryAt(descIndex);
58      }
59  
60      /**
61       * Write the attribute information onto the DataOutputStream, using the 
62       * constant pool to register variables. .
63       * @param dos the DataOutputStream to write on
64       * @param cp The constant pool to register variables
65       **/
66      protected void writeEntry(DataOutputStream dos, ConstantPool cp) 
67    throws IOException {
68    dos.writeShort(startPc);
69    dos.writeShort(length);
70    dos.writeShort(cp.addCPEntry(name));
71    dos.writeShort(cp.addCPEntry(descriptor));
72    dos.writeShort(index);
73      }
74  
75      /**
76       * Called to resolve the temporary stored indices into the code 
77       * table
78       * @param code the Code table after initialization
79       **/
80      public void resolveIndices(Code code) {
81    startInstr = code.getInstructionAt(startPc);
82      }
83  
84      /**
85       * Called to resolve indices on instructions from the code table
86       * @param code the code table after initialization
87       **/
88      public void readIndices(Code code) {
89    startPc = code.getIndexOf(startInstr);
90      }
91  }