001: //
002: // Copyright (C) 2005 United States Government as represented by the
003: // Administrator of the National Aeronautics and Space Administration
004: // (NASA). All Rights Reserved.
005: //
006: // This software is distributed under the NASA Open Source Agreement
007: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
008: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
009: // directory tree for the complete NOSA document.
010: //
011: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
012: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
013: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
014: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
015: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
016: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
017: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
018: //
019: package gov.nasa.jpf.util;
020:
021: /**
022: * a source reference abstraction wrapping file and line information
023: */
024: public class SourceRef {
025: public String fileName;
026: public int line;
027:
028: public SourceRef() {
029: fileName = null;
030: line = -1;
031: }
032:
033: public SourceRef(String f, int l) {
034: fileName = f;
035: line = l;
036: }
037:
038: public String getLineString() {
039: Source source = Source.getSource(fileName);
040:
041: return source.getLine(line);
042: }
043:
044: public boolean equals(Object o) {
045: if (o == null) {
046: return false;
047: }
048:
049: if (!(o instanceof SourceRef)) {
050: return false;
051: }
052:
053: SourceRef sr = (SourceRef) o;
054:
055: if (fileName == null) {
056: return false;
057: }
058:
059: if (line == -1) {
060: return false;
061: }
062:
063: if (!fileName.equals(sr.fileName)) {
064: return false;
065: }
066:
067: if (line != sr.line) {
068: return false;
069: }
070:
071: return true;
072: }
073:
074: public boolean equals(String f, int l) {
075: if (fileName == null) {
076: return false;
077: }
078:
079: if (line == -1) {
080: return false;
081: }
082:
083: if (!fileName.equals(f)) {
084: return false;
085: }
086:
087: if (line != l) {
088: return false;
089: }
090:
091: return true;
092: }
093:
094: public String getFileName() {
095: return fileName;
096: }
097:
098: public void set(SourceRef sr) {
099: fileName = sr.fileName;
100: line = sr.line;
101: }
102:
103: public String toString() {
104: return (fileName + ':' + line);
105: }
106: }
|