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