1 package gnu.text; 2 3 4 5 public class SourceError 6 implements SourceLocator 7 { 8 9 public SourceError next; 10 11 13 public char severity; 14 15 16 public String filename; 17 18 19 public String code; 20 21 23 24 public int line; 25 26 28 public int column; 29 30 33 public String message; 34 35 38 public Throwable fakeException; 39 40 public SourceError(char severity, String filename, int line, int column, 41 String message) 42 { 43 this.severity = severity; 44 this.filename = filename; 45 this.line = line; 46 this.column = column; 47 this.message = message; 48 } 49 50 public SourceError(char severity, SourceLocator location, String message) 51 { 52 this(severity, location.getFileName(), location.getLineNumber(), 53 location.getColumnNumber(), message); 54 } 55 56 58 public SourceError(LineBufferedReader port, char severity, String message) 59 { 60 this(severity, port.getName(), 61 port.getLineNumber() + 1, port.getColumnNumber(), 62 message); 63 if (column >= 0) 64 column++; 65 } 66 67 70 public String toString() 71 { 72 StringBuffer buffer = new StringBuffer (); 73 buffer.append (filename == null ? "<unknown>" : filename); 74 if (line > 0 || column > 0) 75 { 76 buffer.append (':'); 77 buffer.append (line); 78 if (column > 0) 79 { 80 buffer.append (':'); 81 buffer.append (column); 82 } 83 } 84 buffer.append (": "); 85 if (severity == 'w') 86 buffer.append("warning - "); 87 buffer.append (message); 88 if (code != null) 89 { 90 buffer.append(" ["); 91 buffer.append(code); 92 buffer.append("]"); 93 } 94 if (fakeException != null) 95 { 96 99 StackTraceElement [] stackTrace = fakeException.getStackTrace(); 100 for (int i = 0; i < stackTrace.length; i++) 101 { 102 buffer.append("\n"); 103 buffer.append(" "); 104 buffer.append(stackTrace[i].toString()); 105 } 106 107 114 } 115 return buffer.toString (); 116 } 117 118 public void print(java.io.PrintWriter out) 119 { 120 out.print(this); 121 } 122 123 public void println(java.io.PrintWriter out) 124 { 125 String line = toString(); 126 for (;;) 127 { 128 int nl = line.indexOf('\n'); 129 if (nl < 0) 130 break; 131 out.println(line.substring(0, nl)); 132 line = line.substring(nl+1); 133 } 134 out.println(line); 135 } 136 137 public void println(java.io.PrintStream out) 138 { 139 String line = toString(); 140 for (;;) 141 { 142 int nl = line.indexOf('\n'); 143 if (nl < 0) 144 break; 145 out.println(line.substring(0, nl)); 146 line = line.substring(nl+1); 147 } 148 out.println(line); 149 } 150 151 public int getLineNumber () { return line == 0 ? -1 : line; } 152 public int getColumnNumber () { return column == 0 ? -1 : column; } 153 public String getPublicId() { return null; } 154 public String getSystemId() { return filename; } 155 public String getFileName() { return filename; } 156 public boolean isStableSourceLocation() { return true; } 157 } 158 | Popular Tags |