KickJava   Java API By Example, From Geeks To Geeks.

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


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.AttributeInfo;
11 import org.gjt.jclasslib.structures.InvalidByteCodeException;
12
13 import java.io.*;
14
15 /**
16     Describes an <tt>LineNumberTable</tt> attribute structure.
17
18     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
19     @version $Revision: 1.4 $ $Date: 2003/08/18 07:52:05 $
20 */

21 public class LineNumberTableAttribute extends AttributeInfo {
22
23     /** Name of the attribute as in the corresponding constant pool entry. */
24     public static final String JavaDoc ATTRIBUTE_NAME = "LineNumberTable";
25
26     private static final int INITIAL_LENGTH = 2;
27     
28     private LineNumberTableEntry[] lineNumberTable;
29     
30     /**
31         Get the list of line number associations of the parent
32         <tt>Code</tt> structure as an array of <tt>LineNumberTableEntry</tt> structures.
33         @return the array
34      */

35     public LineNumberTableEntry[] getLineNumberTable() {
36         return lineNumberTable;
37     }
38     
39     /**
40         Set the list of line number associations of the parent
41         <tt>Code</tt> structure as an array of <tt>LineNumberTableEntry</tt> structures.
42         @param lineNumberTable the index
43      */

44     public void setLineNumberTable(LineNumberTableEntry[] lineNumberTable) {
45         this.lineNumberTable = lineNumberTable;
46     }
47     
48     public void read(DataInput in)
49         throws InvalidByteCodeException, IOException {
50             
51         int lineNumberTableLength = in.readUnsignedShort();
52         lineNumberTable = new LineNumberTableEntry[lineNumberTableLength];
53         for (int i = 0 ; i < lineNumberTableLength; i++) {
54             lineNumberTable[i] = LineNumberTableEntry.create(in, classFile);
55         }
56         
57         if (debug) debug("read ");
58     }
59
60     public void write(DataOutput out)
61         throws InvalidByteCodeException, IOException {
62         
63         super.write(out);
64
65         int lineNumberTableLength = getLength(lineNumberTable);
66         
67         out.writeShort(lineNumberTableLength);
68         for (int i = 0 ; i < lineNumberTableLength; i++) {
69             lineNumberTable[i].write(out);
70         }
71         if (debug) debug("wrote ");
72     }
73
74     public int getAttributeLength() {
75         return INITIAL_LENGTH + getLength(lineNumberTable) * LineNumberTableEntry.LENGTH;
76     }
77
78     protected void debug(String JavaDoc message) {
79         super.debug(message + "LineNumberTable attribute with " + getLength(lineNumberTable) + " entries");
80     }
81
82 }
83
Popular Tags