KickJava   Java API By Example, From Geeks To Geeks.

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


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

19
20 package org.netbeans.modules.classfile;
21
22 import java.io.DataInputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 /**
26  * VerificationTypeInfo structure, which is defined as a C-like union
27  * in the Java Virtual Machine Specification, section 4.8.4, and is
28  * used to define stack map frame structures. To map this union to Java
29  * classes, this class is abstract and has a separate public subclass for each
30  * union member. The verification type can be determined either by the
31  * its <code>frame_type</code> or using an instanceof test.
32  *
33  * @author tball
34  */

35 public abstract class VerificationTypeInfo {
36     private int tag;
37     
38     /** Verification type <code>top</code>. */
39     public static final int ITEM_Top = 0;
40     /** Verification type <code>int</code>. */
41     public static final int ITEM_Integer = 1;
42     /** Verification type <code>float</code>. */
43     public static final int ITEM_Float = 2;
44     /** Verification type <code>double</code>. */
45     public static final int ITEM_Double = 3;
46     /** Verification type <code>long</code>. */
47     public static final int ITEM_Long = 4;
48     /** Verification type <code>null</code>. */
49     public static final int ITEM_Null = 5;
50     /** Verification type <code>uninitializedThis</code>. */
51     public static final int ITEM_UninitializedThis = 6;
52     /** Verification type <code>object</object>. */
53     public static final int ITEM_Object = 7;
54     /** Verification type <code>uninitialized</code>. */
55     public static final int ITEM_Uninitialized = 8;
56     
57     static VerificationTypeInfo loadVerificationTypeInfo(DataInputStream JavaDoc in, ConstantPool pool)
58       throws IOException JavaDoc {
59         int tag = in.readUnsignedByte();
60         switch (tag) {
61             case ITEM_Top: return new TopVariableInfo();
62             case ITEM_Integer: return new IntegerVariableInfo();
63             case ITEM_Float: return new FloatVariableInfo();
64             case ITEM_Long: return new LongVariableInfo();
65             case ITEM_Double: return new DoubleVariableInfo();
66             case ITEM_Null: return new NullVariableInfo();
67             case ITEM_UninitializedThis: return new UninitializedThisVariableInfo();
68             case ITEM_Object: {
69                 int cpool_index = in.readUnsignedShort();
70                 return new ObjectVariableInfo(pool.get(cpool_index));
71             }
72             case ITEM_Uninitialized: {
73                 int offset = in.readUnsignedShort();
74                 return new UninitializedVariableInfo(offset);
75             }
76             default:
77                 throw new InvalidClassFormatException("invalid verification_type_info tag: " + tag);
78         }
79     }
80     
81     /** Creates a new instance of VerificationTypeInfo */
82     VerificationTypeInfo(int tag) {
83         this.tag = tag;
84     }
85
86     /**
87      * Returns the structure's tag, which specifies its type. This tag is a
88      * value between 0 and 8, as defined by the <code>ITEM_*</code> constants
89      * in this class. (When Java 5 is the minimum JVM for NetBeans, these
90      * constants can be replaced with an enum.)
91      */

92     public int getTag() {
93         return tag;
94     }
95     
96     /**
97      * A Top_variable_info type, which indicates that the local variable has
98      * the verification type <code>top</code>.
99      */

100     public static final class TopVariableInfo extends VerificationTypeInfo {
101         TopVariableInfo() {
102             super(ITEM_Top);
103         }
104     }
105     
106     /**
107      * A Integer_variable_info type, which indicates that the location
108      * contains the verification type <code>int</code>.
109      */

110     public static final class IntegerVariableInfo extends VerificationTypeInfo {
111         IntegerVariableInfo() {
112             super(ITEM_Integer);
113         }
114     }
115     
116     /**
117      * A Float_variable_info type, which indicates that the location contains
118      * the verification type <code>float</code>.
119      */

120     public static final class FloatVariableInfo extends VerificationTypeInfo {
121         FloatVariableInfo() {
122             super(ITEM_Float);
123         }
124     }
125     
126     /**
127      * A Long_variable_info type, which indicates that the location contains
128      * the verification type <code>long</code>.
129      */

130     public static final class LongVariableInfo extends VerificationTypeInfo {
131         LongVariableInfo() {
132             super(ITEM_Long);
133         }
134     }
135     
136     /**
137      * A Double_variable_info type, which indicates that the location contains
138      * the verification type <code>double</code>.
139      */

140     public static final class DoubleVariableInfo extends VerificationTypeInfo {
141         DoubleVariableInfo() {
142             super(ITEM_Double);
143         }
144     }
145     
146     /**
147      * A Null_variable_info type, which indicates that the location contains
148      * the verification type <code>null</code>.
149      */

150     public static final class NullVariableInfo extends VerificationTypeInfo {
151         NullVariableInfo() {
152             super(ITEM_Null);
153         }
154     }
155     
156     /**
157      * A UninitializedThis_variable_info type, which indicates that the location contains
158      * the verification type <code>uninitializedThis</code>.
159      */

160     public static final class UninitializedThisVariableInfo extends VerificationTypeInfo {
161         UninitializedThisVariableInfo() {
162             super(ITEM_UninitializedThis);
163         }
164     }
165     
166     /**
167      * An Object_variable_info type, which indicates that the location
168      * contains an instance of the class referenced by the constant pool entry.
169      */

170     public static final class ObjectVariableInfo extends VerificationTypeInfo {
171         CPEntry cpEntry;
172         ObjectVariableInfo(CPEntry entry) {
173             super(ITEM_Object);
174             cpEntry = entry;
175         }
176         
177         /**
178          * Returns the constant pool entry which initializes this variables.
179          */

180         public CPEntry getConstantPoolEntry() {
181             return cpEntry;
182         }
183     }
184     
185     /**
186      * An Uninitialized_variable_info type, which indicates that the location
187      * contains the verification type <code>uninitialized(<i>offset</i>)</code>.
188      */

189     public static final class UninitializedVariableInfo extends VerificationTypeInfo {
190         int offset;
191         UninitializedVariableInfo(int offset) {
192             super(ITEM_Object);
193             this.offset = offset;
194         }
195         
196         /**
197          * Returns the offset of the new instruction that created
198          * the object being stored in the location.
199          */

200         public int getOffset() {
201             return offset;
202         }
203     }
204 }
205
Popular Tags