KickJava   Java API By Example, From Geeks To Geeks.

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


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  * LineNumberTableAttribute represents a line number table attribute
31  * within a CodeAttribute within a class file
32  */

33
34 public class LineNumberTableAttribute extends ClassAttribute {
35   /* The expected attribute name */
36     public final static String JavaDoc expectedAttrName = "LineNumberTable";//NOI18N
37

38   /* The line numbers */
39   private short lineNumbers[];
40
41   /* The corresponding instructions */
42   private InsnTarget targets[];
43
44   /* public accessors */
45
46   /**
47    * Constructor
48    */

49   public LineNumberTableAttribute(
50     ConstUtf8 nameAttr, short lineNums[], InsnTarget targets[]) {
51     super(nameAttr);
52     lineNumbers = lineNums;
53     this.targets = targets;
54   }
55
56   /* package local methods */
57
58   static LineNumberTableAttribute read(
59     ConstUtf8 attrName, DataInputStream data, CodeEnv env)
60     throws IOException {
61     int nLnums = data.readUnsignedShort();
62     short lineNums[] = new short[nLnums];
63     InsnTarget targs[] = new InsnTarget[nLnums];
64     for (int i=0; i<nLnums; i++) {
65       targs[i] = env.getTarget(data.readShort());
66       lineNums[i] = data.readShort();
67     }
68     return new LineNumberTableAttribute(attrName, lineNums, targs);
69   }
70
71   void write(DataOutputStream out) throws IOException {
72     out.writeShort(attrName().getIndex());
73     int nlines = lineNumbers.length;
74     out.writeInt(2+4*nlines);
75     out.writeShort(nlines);
76     for (int i=0; i<nlines; i++) {
77       out.writeShort(targets[i].offset());
78       out.writeShort(lineNumbers[i]);
79     }
80   }
81
82   void print(PrintStream out, int indent) {
83     ClassPrint.spaces(out, indent);
84     out.println("Line Numbers: ");//NOI18N
85
for (int i=0; i<lineNumbers.length; i++) {
86       ClassPrint.spaces(out, indent+2);
87       out.println(Integer.toString(lineNumbers[i]) + " @ " +//NOI18N
88
Integer.toString(targets[i].offset()));
89     }
90   }
91 }
92
93
Popular Tags