View Javadoc

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