KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > util > SourceRef


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// directory tree for the complete NOSA document.
10
//
11
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18
//
19
package gov.nasa.jpf.util;
20
21 /**
22  * a source reference abstraction wrapping file and line information
23  */

24 public class SourceRef {
25   public String JavaDoc fileName;
26   public int line;
27
28   public SourceRef () {
29     fileName = null;
30     line = -1;
31   }
32
33   public SourceRef (String JavaDoc f, int l) {
34     fileName = f;
35     line = l;
36   }
37
38   public String JavaDoc getLineString () {
39     Source source = Source.getSource(fileName);
40
41     return source.getLine(line);
42   }
43
44   public boolean equals (Object JavaDoc o) {
45     if (o == null) {
46       return false;
47     }
48
49     if (!(o instanceof SourceRef)) {
50       return false;
51     }
52
53     SourceRef sr = (SourceRef) o;
54
55     if (fileName == null) {
56       return false;
57     }
58
59     if (line == -1) {
60       return false;
61     }
62
63     if (!fileName.equals(sr.fileName)) {
64       return false;
65     }
66
67     if (line != sr.line) {
68       return false;
69     }
70
71     return true;
72   }
73
74   public boolean equals (String JavaDoc f, int l) {
75     if (fileName == null) {
76       return false;
77     }
78
79     if (line == -1) {
80       return false;
81     }
82
83     if (!fileName.equals(f)) {
84       return false;
85     }
86
87     if (line != l) {
88       return false;
89     }
90
91     return true;
92   }
93
94   public String JavaDoc getFileName () {
95     return fileName;
96   }
97     
98   public void set (SourceRef sr) {
99     fileName = sr.fileName;
100     line = sr.line;
101   }
102
103   public String JavaDoc toString () {
104     return (fileName + ':' + line);
105   }
106 }
Popular Tags