KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * LocalVariableTypeTable.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.3 $
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 type table of a method's code attribute.
33  * This table is similar to the local variable table, but differs in that
34  * it only contains the type information for those variables that are generic
35  * reference types. Local variables that are generic reference types have
36  * entries in both tables, while other local variable types are only defined
37  * in the local variable table.
38  *
39  * @author Thomas Ball
40  */

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

84     public final int getStartPC() {
85         return startPC;
86     }
87
88     /**
89      * Returns the length of the range of code bytes where this variable
90      * is valid.
91      */

92     public final int getLength() {
93         return length;
94     }
95
96     /**
97      * Returns the name of this variable.
98      */

99     public final String JavaDoc getName() {
100         return name;
101     }
102
103     /**
104      * Returns the generic field type signature of this variable.
105      */

106     public final String JavaDoc getSignature() {
107         return signature;
108     }
109
110     /**
111      * Returns the variable's index into the local variable array
112      * for the current stack frame.
113      */

114     public final int getIndex() {
115         return index;
116     }
117 }
118
Popular Tags