author | joehw |
Mon, 17 Apr 2017 16:24:10 -0700 | |
changeset 44797 | 8b3b3b911b8a |
parent 25868 | 686eef1e7a79 |
child 46174 | 5611d2529b49 |
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 |
||
24 |
||
25 |
import com.sun.org.apache.bcel.internal.classfile.*; |
|
26 |
||
27 |
/** |
|
28 |
* This class represents a line number within a method, i.e., give an instruction |
|
29 |
* a line number corresponding to the source code line. |
|
30 |
* |
|
31 |
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> |
|
32 |
* @see LineNumber |
|
33 |
* @see MethodGen |
|
34 |
*/ |
|
35 |
public class LineNumberGen |
|
36 |
implements InstructionTargeter, Cloneable, java.io.Serializable |
|
37 |
{ |
|
38 |
private InstructionHandle ih; |
|
39 |
private int src_line; |
|
40 |
||
41 |
/** |
|
42 |
* Create a line number. |
|
43 |
* |
|
44 |
* @param ih instruction handle to reference |
|
45 |
*/ |
|
46 |
public LineNumberGen(InstructionHandle ih, int src_line) { |
|
47 |
setInstruction(ih); |
|
48 |
setSourceLine(src_line); |
|
49 |
} |
|
50 |
||
51 |
/** |
|
52 |
* @return true, if ih is target of this line number |
|
53 |
*/ |
|
17538 | 54 |
@Override |
6 | 55 |
public boolean containsTarget(InstructionHandle ih) { |
56 |
return this.ih == ih; |
|
57 |
} |
|
58 |
||
59 |
/** |
|
60 |
* @param old_ih old target |
|
61 |
* @param new_ih new target |
|
62 |
*/ |
|
17538 | 63 |
@Override |
6 | 64 |
public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { |
65 |
if(old_ih != ih) |
|
66 |
throw new ClassGenException("Not targeting " + old_ih + ", but " + ih + "}"); |
|
67 |
else |
|
68 |
setInstruction(new_ih); |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Get LineNumber attribute . |
|
73 |
* |
|
74 |
* This relies on that the instruction list has already been dumped to byte code or |
|
75 |
* or that the `setPositions' methods has been called for the instruction list. |
|
76 |
*/ |
|
77 |
public LineNumber getLineNumber() { |
|
78 |
return new LineNumber(ih.getPosition(), src_line); |
|
79 |
} |
|
80 |
||
17538 | 81 |
public final void setInstruction(InstructionHandle ih) { |
82 |
BranchInstruction.notifyTargetChanging(this.ih, this); |
|
6 | 83 |
this.ih = ih; |
17538 | 84 |
BranchInstruction.notifyTargetChanged(this.ih, this); |
6 | 85 |
} |
86 |
||
17538 | 87 |
@Override |
6 | 88 |
public Object clone() { |
89 |
try { |
|
90 |
return super.clone(); |
|
91 |
} catch(CloneNotSupportedException e) { |
|
92 |
System.err.println(e); |
|
93 |
return null; |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
public InstructionHandle getInstruction() { return ih; } |
|
98 |
public void setSourceLine(int src_line) { this.src_line = src_line; } |
|
99 |
public int getSourceLine() { return src_line; } |
|
100 |
} |