KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > javaguard > classfile > LineNumberInfo


1 /**
2  * JavaGuard -- an obfuscation package for Java classfiles.
3  *
4  * Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
5  * Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * The author may be contacted at theit@gmx.de.
22  *
23  *
24  * $Id: LineNumberInfo.java,v 1.2 2002/05/08 11:53:42 glurk Exp $
25  */

26 package net.sf.javaguard.classfile;
27
28 import java.io.*;
29
30
31 /** Representation of a line number table entry.
32  *
33  * @author <a HREF="mailto:theit@gmx.de">Thorsten Heit</a>
34  * @author <a HREF="mailto:markw@retrologic.com">Mark Welsh</a>
35  */

36 public class LineNumberInfo {
37   /** Start of the Program Counter (PC). */
38   private int startPc;
39   /** The line number. */
40   private int lineNumber;
41   
42   
43   
44   
45   /** Creates a new LineNumberInfo object from the given input stream.
46    * @param din the input stream
47    * @return the LineNumberInfo object created from the input stream
48    * @throws IOException if an I/O error occurs
49    */

50   public static LineNumberInfo create(DataInput din)
51   throws IOException {
52     LineNumberInfo lni = new LineNumberInfo();
53     lni.read(din);
54     return lni;
55   }
56   
57   
58   
59   
60   /** Private constructor that creates a new LineNumberInfo object.
61    */

62   private LineNumberInfo() {
63   }
64   
65   
66   
67   
68   /** Sets the address of the program counter.
69    * @param pc the address of the program counter
70    * @see #getStartPc
71    */

72   protected void setStartPc(int pc) {
73     this.startPc = pc;
74   }
75   
76   
77   /** Returns the address of the program counter.
78    * @return address of the program counter
79    * @see #setStartPc
80    */

81   protected int getStartPc() {
82     return startPc;
83   }
84   
85   
86   
87   
88   /** Sets the line number.
89    * @param num the line number
90    * @see #getLineNumber
91    */

92   protected void setLineNumber(int num) {
93     lineNumber = num;
94   }
95   
96   
97   /** Returns the line number.
98    * @return the line number
99    * @see #setLineNumber
100    */

101   protected int getLineNumber() {
102     return lineNumber;
103   }
104   
105   
106   
107   
108   /** Read the data following the header.
109    * @param din the input stream
110    * @throws IOException if an I/O error occurs
111    */

112   private void read(DataInput din)
113   throws IOException {
114     setStartPc(din.readUnsignedShort());
115     setLineNumber(din.readUnsignedShort());
116   }
117   
118   
119   /** Export data following the header to a DataOutput stream.
120    * @param dout the output stream
121    * @throws IOException if an I/O error occurs
122    */

123   public void write(DataOutput dout)
124   throws IOException {
125     dout.writeShort(getStartPc());
126     dout.writeShort(getLineNumber());
127   }
128   
129   
130   
131   
132   /** Dump the content of the entry to the specified file (used for debugging).
133    * @param pw the print writer
134    * @param cf the class file the element belongs to
135    */

136   public void dump(PrintWriter pw, ClassFile cf) {
137     pw.print("StartPC: ");
138     pw.println(getStartPc());
139     pw.print("Line number: ");
140     pw.println(getLineNumber());
141   }
142 }
143
Popular Tags