KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > LocalVarTableAttr


1 /**
2  * Local variable table attributes are embedded into Code attributes
3  * and used for further debugging information.
4  * @see CodeAttr#setLocalVar
5  * @author $Author: fqian $
6  * @version $Revision: 1.1 $
7  */

8
9 package jas;
10
11 import java.io.*;
12 import java.util.*;
13
14 public class LocalVarTableAttr
15 {
16   static CP attr = new AsciiCP("LocalVariableTable");
17
18   Vector vars;
19
20
21   /**
22    * Note: A local var is associated with a <em>method</em>, so you
23    * need to create a new LocalVarTableAttr for each method for which you add
24    * debugging information.
25    * @see CodeAttr#setLocalVarTable
26    */

27   public LocalVarTableAttr()
28   { vars = new Vector(); }
29
30   /**
31    * Add a LocalVar Entry to the attribute
32    * @param entry Local variable Entry to be added to the table
33    */

34
35   public void addEntry(LocalVarEntry e)
36   { vars.addElement(e); }
37
38   void resolve(ClassEnv e)
39   {
40     e.addCPItem(attr);
41
42     for (Enumeration en = vars.elements(); en.hasMoreElements();)
43       {
44         LocalVarEntry lv = (LocalVarEntry)(en.nextElement());
45         lv.resolve(e);
46       }
47   }
48
49   int size()
50   { return
51       (2 + // name_idx
52
4 + // attr_len
53
2 + // line table len spec
54
10*(vars.size())); // table
55
}
56
57   void write(ClassEnv e, CodeAttr ce, DataOutputStream out)
58     throws IOException, jasError
59   {
60     out.writeShort(e.getCPIndex(attr));
61     out.writeInt(2 + 10*(vars.size()));
62     out.writeShort(vars.size());
63     for (Enumeration en = vars.elements(); en.hasMoreElements();)
64       {
65     LocalVarEntry lv = (LocalVarEntry)(en.nextElement());
66     lv.write(e, ce, out);
67       }
68   }
69 }
70
Popular Tags