KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > control > messages > LocatedMessage


1 package org.codehaus.groovy.control.messages;
2
3 import java.io.PrintWriter JavaDoc;
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.CSTNode;
9
10
11
12 /**
13  * A base class for compilation messages.
14  *
15  * @author <a HREF="mailto:cpoirier@dreaming.org">Chris Poirier</a>
16  *
17  * @version $Id: LocatedMessage.java,v 1.1 2004/04/19 07:29:45 cpoirier Exp $
18  */

19
20 public class LocatedMessage extends SimpleMessage
21 {
22     protected CSTNode context; // The CSTNode that indicates the location to which the message applies
23

24     
25     public LocatedMessage( String JavaDoc message, CSTNode context )
26     {
27         super( message );
28         this.context = context;
29     }
30     
31     
32     public LocatedMessage( String JavaDoc message, Object JavaDoc data, CSTNode context )
33     {
34         super( message, data );
35         this.context = context;
36     }
37     
38     
39     public void write( PrintWriter JavaDoc writer, ProcessingUnit owner, Janitor janitor )
40     {
41         SourceUnit source = (SourceUnit)owner; // This is reliably true
42

43         String JavaDoc name = source.getName();
44         int line = context.getStartLine();
45         int column = context.getStartColumn();
46         String JavaDoc sample = source.getSample( line, column, janitor );
47         
48         if( sample != null )
49         {
50             writer.println( source.getSample(line, column, janitor) );
51         }
52         
53         writer.println( name + ": " + line + ": " + this.message );
54         writer.println("");
55     }
56     
57 }
58
59
60
61
62
Popular Tags