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