1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.compress.harmony.unpack200.bytecode;
18
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21
22
23
24
25 public class LineNumberTableAttribute extends BCIRenumberedAttribute {
26
27 private static CPUTF8 attributeName;
28
29 public static void setAttributeName(final CPUTF8 cpUTF8Value) {
30 attributeName = cpUTF8Value;
31 }
32
33 private final int lineNumberTableLength;
34 private final int[] startPcs;
35 private final int[] lineNumbers;
36
37 public LineNumberTableAttribute(final int lineNumberTableLength, final int[] startPcs, final int[] lineNumbers) {
38 super(attributeName);
39 this.lineNumberTableLength = lineNumberTableLength;
40 this.startPcs = startPcs;
41 this.lineNumbers = lineNumbers;
42 }
43
44 @Override
45 public boolean equals(final Object obj) {
46 return this == obj;
47 }
48
49 @Override
50 protected int getLength() {
51 return 2 + 4 * lineNumberTableLength;
52 }
53
54
55
56
57
58
59 @Override
60 protected ClassFileEntry[] getNestedClassFileEntries() {
61 return new ClassFileEntry[] { getAttributeName() };
62 }
63
64 @Override
65 protected int[] getStartPCs() {
66 return startPcs;
67 }
68
69
70
71
72
73
74 @Override
75 public String toString() {
76 return "LineNumberTable: " + lineNumberTableLength + " lines";
77 }
78
79 @Override
80 protected void writeBody(final DataOutputStream dos) throws IOException {
81 dos.writeShort(lineNumberTableLength);
82 for (int i = 0; i < lineNumberTableLength; i++) {
83 dos.writeShort(startPcs[i]);
84 dos.writeShort(lineNumbers[i]);
85 }
86 }
87 }