01: /*
02: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation; either version 2 of the License, or
12: * (at your option) any later version.
13: *
14: * Resin Open Source is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17: * of NON-INFRINGEMENT. See the GNU General Public License for more
18: * details.
19: *
20: * You should have received a copy of the GNU General Public License
21: * along with Resin Open Source; if not, write to the
22: * Free SoftwareFoundation, Inc.
23: * 59 Temple Place, Suite 330
24: * Boston, MA 02111-1307 USA
25: *
26: * @author Sam
27: */
28:
29: package com.caucho.quercus;
30:
31: /**
32: * Records the source file location of a statement or expression.
33: */
34: public class Location {
35: public static final Location UNKNOWN = new Location();
36:
37: private final String _fileName;
38: private final int _lineNumber;
39: private final String _className;
40: private final String _functionName;
41:
42: public Location(String fileName, int lineNumber, String className,
43: String functionName) {
44: _fileName = fileName;
45: _lineNumber = lineNumber;
46: _className = className;
47: _functionName = functionName;
48: }
49:
50: private Location() {
51: _fileName = null;
52: _lineNumber = 0;
53: _className = null;
54: _functionName = null;
55: }
56:
57: public String getFileName() {
58: return _fileName;
59: }
60:
61: public int getLineNumber() {
62: return _lineNumber;
63: }
64:
65: public String getClassName() {
66: return _className;
67: }
68:
69: public String getFunctionName() {
70: return _functionName;
71: }
72:
73: /**
74: * Returns a prefix of the form "filename:linenumber: ", or the empty string
75: * if the filename is not known.
76: */
77: public String getMessagePrefix() {
78: if (_fileName == null)
79: return "";
80: else
81: return _fileName + ":" + _lineNumber + ": ";
82: }
83:
84: public String toString() {
85: return "Location[" + _fileName + ":" + _lineNumber + "]";
86: }
87: }
|