1 /* 2 * Copyright 2003-2007 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.codehaus.groovy.control.messages; 18 19 import java.io.PrintWriter; 20 21 import org.codehaus.groovy.control.Janitor; 22 import org.codehaus.groovy.control.ProcessingUnit; 23 import org.codehaus.groovy.control.SourceUnit; 24 import org.codehaus.groovy.syntax.SyntaxException; 25 26 27 28 /** 29 * A base class for compilation messages. 30 * 31 * @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a> 32 * 33 * @version $Id: Message.java 14269 2008-12-04 16:06:13Z blackdrag $ 34 */ 35 36 public abstract class Message 37 { 38 39 40 /** 41 * Writes the message to the specified PrintWriter. The supplied 42 * ProcessingUnit is the unit that holds this Message. 43 */ 44 45 public abstract void write( PrintWriter writer, Janitor janitor ); 46 47 48 /** 49 * A synonym for write( writer, owner, null ). 50 */ 51 52 public final void write( PrintWriter writer) 53 { 54 write( writer, null ); 55 } 56 57 58 59 //--------------------------------------------------------------------------- 60 // FACTORY METHODS 61 62 63 /** 64 * Creates a new Message from the specified text. 65 */ 66 67 public static Message create( String text, ProcessingUnit owner ) 68 { 69 return new SimpleMessage( text, owner ); 70 } 71 72 73 74 /** 75 * Creates a new Message from the specified text. 76 */ 77 78 public static Message create( String text, Object data, ProcessingUnit owner ) 79 { 80 return new SimpleMessage( text, data, owner); 81 } 82 83 84 85 /** 86 * Creates a new Message from the specified SyntaxException. 87 */ 88 89 public static Message create( SyntaxException error, SourceUnit owner ) 90 { 91 return new SyntaxErrorMessage( error, owner ); 92 } 93 94 95 96 97 } 98 99 100 101