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.5 2005/07/01 03:01:19 fraz 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 cause.setSourceLocator(source.getName()); 25 } 26 27 28 /*** 29 * Returns the underlying SyntaxException. 30 */ 31 32 public SyntaxException getCause() { 33 return this.cause; 34 } 35 36 37 /*** 38 * Writes out a nicely formatted summary of the syntax error. 39 */ 40 41 public void write(PrintWriter output, Janitor janitor) { 42 String name = source.getName(); 43 int line = getCause().getStartLine(); 44 int column = getCause().getStartColumn(); 45 String sample = source.getSample(line, column, janitor); 46 47 output.print(name + ": " + line + ": " + getCause().getMessage()); 48 if (sample != null) { 49 output.println(); 50 output.print(sample); 51 output.println(); 52 } 53 } 54 55 56 } 57 58 59