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