KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > attributes > LineNumberTableEntry


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.structures.attributes;
9
10 import org.gjt.jclasslib.structures.*;
11
12 import java.io.*;
13
14 /**
15  * Describes an entry in a <tt>LineNumberTable</tt> attribute structure.
16  *
17  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>, <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
18  * @version $Revision: 1.4 $ $Date: 2004/12/28 13:04:32 $
19  */

20 public class LineNumberTableEntry extends AbstractStructure {
21
22     /**
23      * Length in bytes of a line number association.
24      */

25     public static final int LENGTH = 4;
26
27     private int startPc;
28     private int lineNumber;
29
30     /**
31      * Factory method for creating <tt>LineNumberTableEntry</tt> structures.
32      *
33      * @param in the <tt>DataInput</tt> from which to read the
34      * <tt>LineNumberTableEntry</tt> structure
35      * @param classFile the parent class file of the structure to be created
36      * @return the new <tt>LineNumberTableEntry</tt> structure
37      * @throws InvalidByteCodeException if the byte code is invalid
38      * @throws IOException if an exception occurs with the <tt>DataInput</tt>
39      */

40     public static LineNumberTableEntry create(DataInput in, ClassFile classFile)
41             throws InvalidByteCodeException, IOException {
42
43         LineNumberTableEntry lineNumberTableEntry = new LineNumberTableEntry();
44         lineNumberTableEntry.setClassFile(classFile);
45         lineNumberTableEntry.read(in);
46
47         return lineNumberTableEntry;
48     }
49
50     /**
51      * Get the <tt>start_pc</tt> of this line number association.
52      *
53      * @return the <tt>start_pc</tt>
54      */

55     public int getStartPc() {
56         return startPc;
57     }
58
59     /**
60      * Set the <tt>start_pc</tt> of this line number association.
61      *
62      * @param startPc the <tt>start_pc</tt>
63      */

64     public void setStartPc(int startPc) {
65         this.startPc = startPc;
66     }
67
68     /**
69      * Get the line number of this line number association.
70      *
71      * @return the line number
72      */

73     public int getLineNumber() {
74         return lineNumber;
75     }
76
77     /**
78      * Set the line number of this line number association.
79      *
80      * @param lineNumber the line number
81      */

82     public void setLineNumber(int lineNumber) {
83         this.lineNumber = lineNumber;
84     }
85
86     public void read(DataInput in)
87             throws InvalidByteCodeException, IOException {
88
89         startPc = in.readUnsignedShort();
90         lineNumber = in.readUnsignedShort();
91
92         if (debug) debug("read ");
93     }
94
95     public void write(DataOutput out)
96             throws InvalidByteCodeException, IOException {
97
98         super.write(out);
99         out.writeShort(startPc);
100         out.writeShort(lineNumber);
101         if (debug) debug("wrote ");
102     }
103
104     protected void debug(String JavaDoc message) {
105         super.debug(message + "LineNumberTable entry with start_pc " + startPc +
106                 ", line_number " + lineNumber);
107     }
108
109     protected String JavaDoc printAccessFlagsVerbose(int accessFlags) {
110         if (accessFlags != 0)
111             throw new RuntimeException JavaDoc("Access flags should be zero: " + Integer.toHexString(accessFlags));
112         return "";
113     }
114
115 }
116
Popular Tags