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.classfile; |
23 |
||
24 |
||
25 |
import com.sun.org.apache.bcel.internal.Constants; |
|
26 |
import java.io.*; |
|
27 |
||
28 |
/** |
|
29 |
* This class represents a (PC offset, line number) pair, i.e., a line number in |
|
30 |
* the source that corresponds to a relative address in the byte code. This |
|
31 |
* is used for debugging purposes. |
|
32 |
* |
|
33 |
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> |
|
34 |
* @see LineNumberTable |
|
35 |
*/ |
|
36 |
public final class LineNumber implements Cloneable, Node, Serializable { |
|
37 |
private int start_pc; // Program Counter (PC) corresponds to line |
|
38 |
private int line_number; // number in source file |
|
39 |
||
40 |
/** |
|
41 |
* Initialize from another object. |
|
42 |
*/ |
|
43 |
public LineNumber(LineNumber c) { |
|
44 |
this(c.getStartPC(), c.getLineNumber()); |
|
45 |
} |
|
46 |
||
47 |
/** |
|
48 |
* Construct object from file stream. |
|
49 |
* @param file Input stream |
|
50 |
* @throws IOException |
|
51 |
*/ |
|
52 |
LineNumber(DataInputStream file) throws IOException |
|
53 |
{ |
|
54 |
this(file.readUnsignedShort(), file.readUnsignedShort()); |
|
55 |
} |
|
56 |
||
57 |
/** |
|
58 |
* @param start_pc Program Counter (PC) corresponds to |
|
59 |
* @param line_number line number in source file |
|
60 |
*/ |
|
61 |
public LineNumber(int start_pc, int line_number) |
|
62 |
{ |
|
63 |
this.start_pc = start_pc; |
|
64 |
this.line_number = line_number; |
|
65 |
} |
|
66 |
||
67 |
/** |
|
68 |
* Called by objects that are traversing the nodes of the tree implicitely |
|
69 |
* defined by the contents of a Java class. I.e., the hierarchy of methods, |
|
70 |
* fields, attributes, etc. spawns a tree of objects. |
|
71 |
* |
|
72 |
* @param v Visitor object |
|
73 |
*/ |
|
74 |
public void accept(Visitor v) { |
|
75 |
v.visitLineNumber(this); |
|
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Dump line number/pc pair to file stream in binary format. |
|
80 |
* |
|
81 |
* @param file Output file stream |
|
82 |
* @throws IOException |
|
83 |
*/ |
|
84 |
public final void dump(DataOutputStream file) throws IOException |
|
85 |
{ |
|
86 |
file.writeShort(start_pc); |
|
87 |
file.writeShort(line_number); |
|
88 |
||
89 |
} |
|
90 |
/** |
|
91 |
* @return Corresponding source line |
|
92 |
*/ |
|
93 |
public final int getLineNumber() { return line_number; } |
|
94 |
||
95 |
/** |
|
96 |
* @return PC in code |
|
97 |
*/ |
|
98 |
public final int getStartPC() { return start_pc; } |
|
99 |
||
100 |
/** |
|
101 |
* @param line_number. |
|
102 |
*/ |
|
103 |
public final void setLineNumber(int line_number) { |
|
104 |
this.line_number = line_number; |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* @param start_pc. |
|
109 |
*/ |
|
110 |
public final void setStartPC(int start_pc) { |
|
111 |
this.start_pc = start_pc; |
|
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* @return String representation |
|
116 |
*/ |
|
117 |
public final String toString() { |
|
118 |
return "LineNumber(" + start_pc + ", " + line_number + ")"; |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* @return deep copy of this object |
|
123 |
*/ |
|
124 |
public LineNumber copy() { |
|
125 |
try { |
|
126 |
return (LineNumber)clone(); |
|
127 |
} catch(CloneNotSupportedException e) {} |
|
128 |
||
129 |
return null; |
|
130 |
} |
|
131 |
} |