KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > classfile > LocalVariable


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.classfile;
26
27 import java.io.*;
28
29 /**
30  * Represents a local variable within a LocalVariableTable within
31  * a CodeAttribute in a class file.
32  */

33
34 public class LocalVariable {
35   /* The pc at which the variable becomes effecive */
36   private InsnTarget varStartPC; /* inclusive */
37
38   /* The pc at which the variable becomes in-effecive */
39   private InsnTarget varEndPC; /* exclusive */
40
41   /* The name of the variable */
42   private ConstUtf8 varName;
43
44   /* The type signature of the variable */
45   private ConstUtf8 varSig;
46
47   /* The slot to which the variable is assigned */
48   private int varSlot;
49
50   /* public accessors */
51
52   /**
53    * Constructor for a local variable
54    */

55   public LocalVariable(InsnTarget startPC, InsnTarget endPC,
56                        ConstUtf8 name, ConstUtf8 sig, int slot) {
57     varStartPC = startPC;
58     varEndPC = endPC;
59     varName = name;
60     varSig = sig;
61     varSlot = slot;
62   }
63
64   /* package local methods */
65
66   static LocalVariable read(DataInputStream data, CodeEnv env)
67     throws IOException {
68     int startPC = data.readUnsignedShort();
69     InsnTarget startPCTarget = env.getTarget(startPC);
70     int length = data.readUnsignedShort();
71     InsnTarget endPCTarget = env.getTarget(startPC+length);
72     ConstUtf8 name =
73       (ConstUtf8) env.pool().constantAt(data.readUnsignedShort());
74     ConstUtf8 sig =
75       (ConstUtf8) env.pool().constantAt(data.readUnsignedShort());
76     int slot = data.readUnsignedShort();
77     return new LocalVariable(startPCTarget, endPCTarget, name, sig, slot);
78   }
79
80   void write(DataOutputStream out) throws IOException {
81     out.writeShort(varStartPC.offset());
82     out.writeShort(varEndPC.offset() - varStartPC.offset());
83     out.writeShort((varName == null) ? 0 : varName.getIndex());
84     out.writeShort((varSig == null) ? 0 : varSig.getIndex());
85     out.writeShort(varSlot);
86   }
87
88   public void print(PrintStream out, int indent) {
89     ClassPrint.spaces(out, indent);
90     out.print("'" + ((varName == null) ? "(null)" : varName.asString()) + "'");//NOI18N
91
out.print(" sig = " + ((varSig == null) ? "(null)" : varSig.asString()));//NOI18N
92
out.print(" start_pc = " + Integer.toString(varStartPC.offset()));//NOI18N
93
out.print(" length = " +//NOI18N
94
Integer.toString(varEndPC.offset() - varStartPC.offset()));
95     out.println(" slot = " + Integer.toString(varSlot));//NOI18N
96
}
97
98 }
99
100
Popular Tags