-
Notifications
You must be signed in to change notification settings - Fork 15
/
LineNumberTable.java
43 lines (38 loc) · 1.13 KB
/
LineNumberTable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package arden.codegenerator;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
/**
* Stores line numbers for exception stacktrace/debugger.
*
* @author Daniel Grunwald
*
*/
class LineNumberTable {
final int attributeNameIndex;
private ArrayList<Integer> programCounters = new ArrayList<Integer>();
private ArrayList<Integer> lineNumbers = new ArrayList<Integer>();
public LineNumberTable(ConstantPool pool) {
attributeNameIndex = pool.getUtf8("LineNumberTable");
}
public void addEntry(int pc, int lineNumber) {
programCounters.add(pc);
lineNumbers.add(lineNumber);
}
public byte[] getData() {
try {
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(byteOutputStream);
data.writeShort(lineNumbers.size());
for (int i = 0; i < lineNumbers.size(); i++) {
data.writeShort(programCounters.get(i));
data.writeShort(lineNumbers.get(i));
}
data.flush();
return byteOutputStream.toByteArray();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}