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.ProcessingUnit;
07: import org.codehaus.groovy.control.SourceUnit;
08: import org.codehaus.groovy.syntax.SyntaxException;
09:
10: /**
11: * A base class for compilation messages.
12: *
13: * @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
14: *
15: * @version $Id: Message.java 2257 2005-06-09 19:51:59Z blackdrag $
16: */
17:
18: public abstract class Message {
19:
20: /**
21: * Writes the message to the specified PrintWriter. The supplied
22: * ProcessingUnit is the unit that holds this Message.
23: */
24:
25: public abstract void write(PrintWriter writer, Janitor janitor);
26:
27: /**
28: * A synonyn for write( writer, owner, null ).
29: */
30:
31: public final void write(PrintWriter writer) {
32: write(writer, null);
33: }
34:
35: //---------------------------------------------------------------------------
36: // FACTORY METHODS
37:
38: /**
39: * Creates a new Message from the specified text.
40: */
41:
42: public static Message create(String text, ProcessingUnit owner) {
43: return new SimpleMessage(text, owner);
44: }
45:
46: /**
47: * Creates a new Message from the specified text.
48: */
49:
50: public static Message create(String text, Object data,
51: ProcessingUnit owner) {
52: return new SimpleMessage(text, data, owner);
53: }
54:
55: /**
56: * Creates a new Message from the specified SyntaxException.
57: */
58:
59: public static Message create(SyntaxException error, SourceUnit owner) {
60: return new SyntaxErrorMessage(error, owner);
61: }
62:
63: }
|