01: package org.codehaus.groovy.control.messages;
02:
03: import java.io.PrintWriter;
04:
05: import org.codehaus.groovy.control.Janitor;
06: import org.codehaus.groovy.control.SourceUnit;
07: import org.codehaus.groovy.syntax.SyntaxException;
08:
09: /**
10: * A class for error messages produced by the parser system.
11: *
12: * @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
13: * @version $Id: SyntaxErrorMessage.java 2392 2005-07-01 03:01:19Z fraz $
14: */
15:
16: public class SyntaxErrorMessage extends Message {
17: protected SyntaxException cause = null;
18: protected SourceUnit source;
19:
20: public SyntaxErrorMessage(SyntaxException cause, SourceUnit source) {
21: this .cause = cause;
22: this .source = source;
23: cause.setSourceLocator(source.getName());
24: }
25:
26: /**
27: * Returns the underlying SyntaxException.
28: */
29:
30: public SyntaxException getCause() {
31: return this .cause;
32: }
33:
34: /**
35: * Writes out a nicely formatted summary of the syntax error.
36: */
37:
38: public void write(PrintWriter output, Janitor janitor) {
39: String name = source.getName();
40: int line = getCause().getStartLine();
41: int column = getCause().getStartColumn();
42: String sample = source.getSample(line, column, janitor);
43:
44: output.print(name + ": " + line + ": "
45: + getCause().getMessage());
46: if (sample != null) {
47: output.println();
48: output.print(sample);
49: output.println();
50: }
51: }
52:
53: }
|