1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.impl.enhancer.classfile;
19
20 import java.io.*;
21 import java.util.Stack;
22
23 /***
24 * LineNumberTableAttribute represents a line number table attribute
25 * within a CodeAttribute within a class file
26 */
27 public class LineNumberTableAttribute extends ClassAttribute {
28
29 public final static String expectedAttrName = "LineNumberTable";
30
31
32 private short lineNumbers[];
33
34
35 private InsnTarget targets[];
36
37
38
39 /***
40 * Constructor
41 */
42 public LineNumberTableAttribute(
43 ConstUtf8 nameAttr, short lineNums[], InsnTarget targets[]) {
44 super(nameAttr);
45 lineNumbers = lineNums;
46 this.targets = targets;
47 }
48
49 /***
50 * Compares this instance with another for structural equality.
51 */
52
53 public boolean isEqual(Stack msg, Object obj) {
54 if (!(obj instanceof LineNumberTableAttribute)) {
55 msg.push("obj/obj.getClass() = "
56 + (obj == null ? null : obj.getClass()));
57 msg.push("this.getClass() = "
58 + this.getClass());
59 return false;
60 }
61 LineNumberTableAttribute other = (LineNumberTableAttribute)obj;
62
63 if (!super.isEqual(msg, other)) {
64 return false;
65 }
66
67
68 return true;
69 }
70
71 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
72
73 static LineNumberTableAttribute read(
74 ConstUtf8 attrName, DataInputStream data, CodeEnv env)
75 throws IOException {
76 int nLnums = data.readUnsignedShort();
77 short lineNums[] = new short[nLnums];
78 InsnTarget targs[] = new InsnTarget[nLnums];
79 for (int i=0; i<nLnums; i++) {
80 targs[i] = env.getTarget(data.readShort());
81 lineNums[i] = data.readShort();
82 }
83 return new LineNumberTableAttribute(attrName, lineNums, targs);
84 }
85
86 void write(DataOutputStream out) throws IOException {
87 out.writeShort(attrName().getIndex());
88 int nlines = lineNumbers.length;
89 out.writeInt(2+4*nlines);
90 out.writeShort(nlines);
91 for (int i=0; i<nlines; i++) {
92 out.writeShort(targets[i].offset());
93 out.writeShort(lineNumbers[i]);
94 }
95 }
96
97 void print(PrintStream out, int indent) {
98 ClassPrint.spaces(out, indent);
99 out.println("Line Numbers: ");
100 for (int i=0; i<lineNumbers.length; i++) {
101 ClassPrint.spaces(out, indent+2);
102 out.println(Integer.toString(lineNumbers[i]) + " @ " +
103 Integer.toString(targets[i].offset()));
104 }
105 }
106 }
107