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.CSTNode;
08:
09: /**
10: * A base class for compilation messages.
11: *
12: * @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
13: *
14: * @version $Id: LocatedMessage.java 2264 2005-06-10 09:55:31Z cstein $
15: */
16:
17: public class LocatedMessage extends SimpleMessage {
18: protected CSTNode context; // The CSTNode that indicates the location to which the message applies
19:
20: public LocatedMessage(String message, CSTNode context,
21: SourceUnit source) {
22: super (message, source);
23: this .context = context;
24: }
25:
26: public LocatedMessage(String message, Object data, CSTNode context,
27: SourceUnit source) {
28: super (message, data, source);
29: this .context = context;
30: }
31:
32: public void write(PrintWriter writer, Janitor janitor) {
33: SourceUnit source = (SourceUnit) owner;
34:
35: String name = source.getName();
36: int line = context.getStartLine();
37: int column = context.getStartColumn();
38: String sample = source.getSample(line, column, janitor);
39:
40: if (sample != null) {
41: writer.println(source.getSample(line, column, janitor));
42: }
43:
44: writer.println(name + ": " + line + ": " + this .message);
45: writer.println("");
46: }
47:
48: }
|