author | joehw |
Sun, 13 Aug 2017 21:10:40 -0700 | |
changeset 46174 | 5611d2529b49 |
parent 44797 | 8b3b3b911b8a |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
/* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
14 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
15 |
* Unless required by applicable law or agreed to in writing, software |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
18 |
* See the License for the specific language governing permissions and |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
19 |
* limitations under the License. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
20 |
*/ |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
21 |
|
6 | 22 |
package com.sun.org.apache.bcel.internal.generic; |
23 |
||
46174 | 24 |
import com.sun.org.apache.bcel.internal.classfile.LineNumber; |
6 | 25 |
|
26 |
/** |
|
27 |
* This class represents a line number within a method, i.e., give an instruction |
|
28 |
* a line number corresponding to the source code line. |
|
29 |
* |
|
46174 | 30 |
* @version $Id: LineNumberGen.java 1749603 2016-06-21 20:50:19Z ggregory $ |
6 | 31 |
* @see LineNumber |
32 |
* @see MethodGen |
|
33 |
*/ |
|
46174 | 34 |
public class LineNumberGen implements InstructionTargeter, Cloneable { |
35 |
||
36 |
private InstructionHandle ih; |
|
37 |
private int src_line; |
|
38 |
||
39 |
||
40 |
/** |
|
41 |
* Create a line number. |
|
42 |
* |
|
43 |
* @param ih instruction handle to reference |
|
44 |
*/ |
|
45 |
public LineNumberGen(final InstructionHandle ih, final int src_line) { |
|
46 |
setInstruction(ih); |
|
47 |
setSourceLine(src_line); |
|
48 |
} |
|
49 |
||
6 | 50 |
|
46174 | 51 |
/** |
52 |
* @return true, if ih is target of this line number |
|
53 |
*/ |
|
54 |
@Override |
|
55 |
public boolean containsTarget( final InstructionHandle ih ) { |
|
56 |
return this.ih == ih; |
|
57 |
} |
|
58 |
||
6 | 59 |
|
46174 | 60 |
/** |
61 |
* @param old_ih old target |
|
62 |
* @param new_ih new target |
|
63 |
*/ |
|
64 |
@Override |
|
65 |
public void updateTarget( final InstructionHandle old_ih, final InstructionHandle new_ih ) { |
|
66 |
if (old_ih != ih) { |
|
67 |
throw new ClassGenException("Not targeting " + old_ih + ", but " + ih + "}"); |
|
68 |
} |
|
69 |
setInstruction(new_ih); |
|
70 |
} |
|
71 |
||
6 | 72 |
|
46174 | 73 |
/** |
74 |
* Get LineNumber attribute . |
|
75 |
* |
|
76 |
* This relies on that the instruction list has already been dumped to byte code or |
|
77 |
* or that the `setPositions' methods has been called for the instruction list. |
|
78 |
*/ |
|
79 |
public LineNumber getLineNumber() { |
|
80 |
return new LineNumber(ih.getPosition(), src_line); |
|
81 |
} |
|
82 |
||
83 |
||
84 |
public void setInstruction( final InstructionHandle ih ) { // TODO could be package-protected? |
|
85 |
if (ih == null) { |
|
86 |
throw new NullPointerException("InstructionHandle may not be null"); |
|
87 |
} |
|
88 |
BranchInstruction.notifyTarget(this.ih, ih, this); |
|
89 |
this.ih = ih; |
|
90 |
} |
|
91 |
||
6 | 92 |
|
46174 | 93 |
@Override |
94 |
public Object clone() { |
|
95 |
try { |
|
96 |
return super.clone(); |
|
97 |
} catch (final CloneNotSupportedException e) { |
|
98 |
throw new Error("Clone Not Supported"); // never happens |
|
99 |
} |
|
100 |
} |
|
101 |
||
6 | 102 |
|
46174 | 103 |
public InstructionHandle getInstruction() { |
104 |
return ih; |
|
105 |
} |
|
106 |
||
6 | 107 |
|
46174 | 108 |
public void setSourceLine( final int src_line ) { // TODO could be package-protected? |
109 |
this.src_line = src_line; |
|
6 | 110 |
} |
46174 | 111 |
|
6 | 112 |
|
46174 | 113 |
public int getSourceLine() { |
114 |
return src_line; |
|
115 |
} |
|
6 | 116 |
} |