01: package gnu.mapping;
02:
03: import gnu.text.SourceLocator;
04:
05: /** An undefined symbol was evaluated. */
06:
07: public class UnboundLocationException extends RuntimeException {
08: public Object symbol;
09: Location location;
10: String filename;
11: int line, column;
12:
13: public UnboundLocationException() {
14: }
15:
16: public UnboundLocationException(Object symbol) {
17: this .symbol = symbol;
18: }
19:
20: public UnboundLocationException(Object symbol, String filename,
21: int line, int column) {
22: this .symbol = symbol;
23: this .filename = filename;
24: this .line = line;
25: this .column = column;
26: }
27:
28: public UnboundLocationException(Object symbol,
29: SourceLocator location) {
30: this .symbol = symbol;
31: if (location != null) {
32: this .filename = location.getFileName();
33: this .line = location.getLineNumber();
34: this .column = location.getColumnNumber();
35: }
36: }
37:
38: public UnboundLocationException(Location loc) {
39: this .location = loc;
40: }
41:
42: public UnboundLocationException(Object symbol, String message) {
43: super (message);
44: this .symbol = symbol;
45: }
46:
47: public void setLine(String filename, int line, int column) {
48: this .filename = filename;
49: this .line = line;
50: this .column = column;
51: }
52:
53: public String getMessage() {
54: String msg = super .getMessage();
55: if (msg != null)
56: return msg;
57: StringBuffer sbuf = new StringBuffer();
58: if (filename != null || line > 0) {
59: if (filename != null)
60: sbuf.append(filename);
61: if (line >= 0) {
62: sbuf.append(':');
63: sbuf.append(line);
64: if (column > 0) {
65: sbuf.append(':');
66: sbuf.append(column);
67: }
68: }
69: sbuf.append(": ");
70: }
71: Symbol name = location == null ? null : location.getKeySymbol();
72: if (name != null) {
73: sbuf.append("unbound location ");
74: sbuf.append(name);
75: Object property = location.getKeyProperty();
76: if (property != null) {
77: sbuf.append(" (property ");
78: sbuf.append(property);
79: sbuf.append(')');
80: }
81: } else if (symbol != null) {
82: sbuf.append("unbound location ");
83: sbuf.append(symbol);
84: } else
85: sbuf.append("unbound location");
86: return sbuf.toString();
87: }
88:
89: public String toString() {
90: return getMessage();
91: }
92: }
|