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