KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > classfile > LocalVariableTableEntry


1 /*
2  * LocalVariableTable.java
3  *
4  * The contents of this file are subject to the terms of the Common Development
5  * and Distribution License (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
9  * or http://www.netbeans.org/cddl.txt.
10  *
11  * When distributing Covered Code, include this CDDL Header Notice in each file
12  * and include the License file at http://www.netbeans.org/cddl.txt.
13  * If applicable, add the following below the CDDL Header, with the fields
14  * enclosed by brackets [] replaced by your own identifying information:
15  * "Portions Copyrighted [year] [name of copyright owner]"
16  *
17  * The Original Software is NetBeans. The Initial Developer of the Original
18  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
19  * Microsystems, Inc. All Rights Reserved.
20  *
21  * Contributor(s): Thomas Ball
22  *
23  * Version: $Revision: 1.5 $
24  */

25
26 package org.netbeans.modules.classfile;
27
28 import java.io.DataInputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 /**
32  * An entry in the local variable table of a method's code attribute.
33  *
34  * @author Thomas Ball
35  */

36 public final class LocalVariableTableEntry {
37
38     int startPC;
39     int length;
40     String JavaDoc name;
41     String JavaDoc description;
42     int index;
43
44     static LocalVariableTableEntry[] loadLocalVariableTable(DataInputStream JavaDoc in, ConstantPool pool)
45       throws IOException JavaDoc {
46         int n = in.readUnsignedShort();
47         LocalVariableTableEntry[] entries = new LocalVariableTableEntry[n];
48         for (int i = 0; i < n; i++)
49             entries[i] = new LocalVariableTableEntry(in, pool);
50         return entries;
51     }
52
53     /** Creates new LocalVariableTableEntry */
54     LocalVariableTableEntry(DataInputStream JavaDoc in, ConstantPool pool)
55       throws IOException JavaDoc {
56         loadLocalVariableEntry(in, pool);
57     }
58
59     private void loadLocalVariableEntry(DataInputStream JavaDoc in, ConstantPool pool)
60       throws IOException JavaDoc {
61         startPC = in.readUnsignedShort();
62         length = in.readUnsignedShort();
63         Object JavaDoc o = pool.get(in.readUnsignedShort());
64         if (!(o instanceof CPUTF8Info))
65           throw new InvalidClassFormatException();
66         CPUTF8Info entry = (CPUTF8Info)o;
67         name = entry.getName();
68         o = pool.get(in.readUnsignedShort());
69         if (!(o instanceof CPUTF8Info))
70           throw new InvalidClassFormatException();
71         entry = (CPUTF8Info)o;
72         description = entry.getName();
73         index = in.readUnsignedShort();
74     }
75
76     /**
77      * Returns the first byte code offset where this variable is valid.
78      */

79     public final int getStartPC() {
80         return startPC;
81     }
82
83     /**
84      * Returns the length of the range of code bytes where this variable
85      * is valid.
86      */

87     public final int getLength() {
88         return length;
89     }
90
91     /**
92      * Returns the name of this variable.
93      */

94     public final String JavaDoc getName() {
95         return name;
96     }
97
98     /**
99      * Returns the signature (type) of this variable.
100      */

101     public final String JavaDoc getDescription() {
102         return description;
103     }
104
105     /**
106      * Returns the variable's index into the local variable array
107      * for the current stack frame.
108      */

109     public final int getIndex() {
110         return index;
111     }
112 }
113
Popular Tags