2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.util;
21 * a source reference abstraction wrapping file and line information
23 public class SourceRef {
24 public String fileName;
27 public SourceRef (String f, int l) {
37 public SourceRef (String spec){
38 int idx = spec.indexOf(':');
40 fileName = spec.substring(0, idx);
41 line = Integer.parseInt(spec.substring(idx+1));
48 public String getLocationString() {
49 return (fileName + ':' + line);
52 public String getLineString () {
53 Source source = Source.getSource(fileName);
55 return source.getLine(line);
62 public boolean equals (Object o) {
67 if (!(o instanceof SourceRef)) {
71 SourceRef that = (SourceRef) o;
73 if (this.fileName == null) {
77 if (this.line == -1) {
81 if (!this.fileName.equals(that.fileName)) {
85 if (this.line != that.line) {
92 public boolean equals (String f, int l) {
93 if (fileName == null) {
101 if (!fileName.equals(f)) {
112 public boolean equals (String filePos){
113 if (filePos.startsWith(fileName)){
114 int len = fileName.length();
115 if (filePos.charAt(len) == ':'){
116 if (Integer.parseInt(filePos.substring(len+1)) == line){
126 public int hashCode() {
127 assert false : "hashCode not designed";
128 return 42; // any arbitrary constant will do
132 public String getFileName () {
136 public void set (SourceRef sr) {
137 fileName = sr.fileName;
142 public String toString () {
143 return (fileName + ':' + line);