1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 import java.util.Objects;
20
21 import org.apache.bcel.classfile.LineNumber;
22
23
24
25
26
27
28
29
30 public class LineNumberGen implements InstructionTargeter, Cloneable {
31
32 static final LineNumberGen[] EMPTY_ARRAY = {};
33
34 private InstructionHandle ih;
35 private int srcLine;
36
37
38
39
40
41
42 public LineNumberGen(final InstructionHandle ih, final int srcLine) {
43 setInstruction(ih);
44 setSourceLine(srcLine);
45 }
46
47 @Override
48 public Object clone() {
49 try {
50 return super.clone();
51 } catch (final CloneNotSupportedException e) {
52 throw new UnsupportedOperationException("Clone Not Supported", e);
53 }
54 }
55
56
57
58
59 @Override
60 public boolean containsTarget(final InstructionHandle ih) {
61 return this.ih == ih;
62 }
63
64 public InstructionHandle getInstruction() {
65 return ih;
66 }
67
68
69
70
71
72
73
74 public LineNumber getLineNumber() {
75 return new LineNumber(ih.getPosition(), srcLine);
76 }
77
78 public int getSourceLine() {
79 return srcLine;
80 }
81
82 public void setInstruction(final InstructionHandle instructionHandle) {
83 Objects.requireNonNull(instructionHandle, "instructionHandle");
84 BranchInstruction.notifyTarget(this.ih, instructionHandle, this);
85 this.ih = instructionHandle;
86 }
87
88 public void setSourceLine(final int srcLine) {
89 this.srcLine = srcLine;
90 }
91
92
93
94
95
96 @Override
97 public void updateTarget(final InstructionHandle oldIh, final InstructionHandle newIh) {
98 if (oldIh != ih) {
99 throw new ClassGenException("Not targeting " + oldIh + ", but " + ih + "}");
100 }
101 setInstruction(newIh);
102 }
103 }