KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > bcel > generic > LineNumberGen


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.bcel.generic;
18
19 import org.apache.bcel.classfile.LineNumber;
20
21 /**
22  * This class represents a line number within a method, i.e., give an instruction
23  * a line number corresponding to the source code line.
24  *
25  * @version $Id: LineNumberGen.java 386056 2006-03-15 11:31:56Z tcurdt $
26  * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27  * @see LineNumber
28  * @see MethodGen
29  */

30 public class LineNumberGen implements InstructionTargeter, Cloneable JavaDoc, java.io.Serializable JavaDoc {
31
32     private InstructionHandle ih;
33     private int src_line;
34
35
36     /**
37      * Create a line number.
38      *
39      * @param ih instruction handle to reference
40      */

41     public LineNumberGen(InstructionHandle ih, int src_line) {
42         setInstruction(ih);
43         setSourceLine(src_line);
44     }
45
46
47     /**
48      * @return true, if ih is target of this line number
49      */

50     public boolean containsTarget( InstructionHandle ih ) {
51         return this.ih == ih;
52     }
53
54
55     /**
56      * @param old_ih old target
57      * @param new_ih new target
58      */

59     public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih ) {
60         if (old_ih != ih) {
61             throw new ClassGenException("Not targeting " + old_ih + ", but " + ih + "}");
62         } else {
63             setInstruction(new_ih);
64         }
65     }
66
67
68     /**
69      * Get LineNumber attribute .
70      *
71      * This relies on that the instruction list has already been dumped to byte code or
72      * or that the `setPositions' methods has been called for the instruction list.
73      */

74     public LineNumber getLineNumber() {
75         return new LineNumber(ih.getPosition(), src_line);
76     }
77
78
79     public void setInstruction( InstructionHandle ih ) {
80         BranchInstruction.notifyTarget(this.ih, ih, this);
81         this.ih = ih;
82     }
83
84
85     public Object JavaDoc clone() {
86         try {
87             return super.clone();
88         } catch (CloneNotSupportedException JavaDoc e) {
89             System.err.println(e);
90             return null;
91         }
92     }
93
94
95     public InstructionHandle getInstruction() {
96         return ih;
97     }
98
99
100     public void setSourceLine( int src_line ) {
101         this.src_line = src_line;
102     }
103
104
105     public int getSourceLine() {
106         return src_line;
107     }
108 }
109
Popular Tags