1 package gnu.mapping; 2 import gnu.text.SourceLocator; 3 4 5 6 public class UnboundLocationException extends RuntimeException 7 { 8 public Object symbol; 9 Location location; 10 String filename; 11 int line, column; 12 13 public UnboundLocationException () 14 { 15 } 16 17 public UnboundLocationException (Object symbol) 18 { 19 this.symbol = symbol; 20 } 21 22 public UnboundLocationException (Object symbol, String filename, 23 int line, int column) 24 { 25 this.symbol = symbol; 26 this.filename = filename; 27 this.line = line; 28 this.column = column; 29 } 30 31 public UnboundLocationException (Object symbol, SourceLocator location) 32 { 33 this.symbol = symbol; 34 if (location != null) 35 { 36 this.filename = location.getFileName(); 37 this.line = location.getLineNumber(); 38 this.column = location.getColumnNumber(); 39 } 40 } 41 42 public UnboundLocationException (Location loc) 43 { 44 this.location = loc; 45 } 46 47 public UnboundLocationException (Object symbol, String message) 48 { 49 super (message); 50 this.symbol = symbol; 51 } 52 53 public void setLine (String filename, int line, int column) 54 { 55 this.filename = filename; 56 this.line = line; 57 this.column = column; 58 } 59 60 public String getMessage() 61 { 62 String msg = super.getMessage(); 63 if (msg != null) 64 return msg; 65 StringBuffer sbuf = new StringBuffer (); 66 if (filename != null || line > 0) 67 { 68 if (filename != null) 69 sbuf.append(filename); 70 if (line >= 0) 71 { 72 sbuf.append(':'); 73 sbuf.append(line); 74 if (column > 0) 75 { 76 sbuf.append(':'); 77 sbuf.append(column); 78 } 79 } 80 sbuf.append(": "); 81 } 82 Symbol name = location == null ? null : location.getKeySymbol(); 83 if (name != null) 84 { 85 sbuf.append("unbound location "); 86 sbuf.append(name); 87 Object property = location.getKeyProperty(); 88 if (property != null) 89 { 90 sbuf.append(" (property "); 91 sbuf.append(property); 92 sbuf.append(')'); 93 } 94 } 95 else if (symbol != null) 96 { 97 sbuf.append("unbound location "); 98 sbuf.append(symbol); 99 } 100 else 101 sbuf.append("unbound location"); 102 return sbuf.toString(); 103 } 104 105 public String toString() 106 { 107 return getMessage(); 108 } 109 } 110 | Popular Tags |