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 class for warning messages.
    13   *
    14   *  @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
    15   *
    16   *  @version $Id: WarningMessage.java 2264 2005-06-10 09:55:31Z cstein $
    17   */
    18
    19  public class WarningMessage extends LocatedMessage
    20  {
    21    //---------------------------------------------------------------------------
    22    // WARNING LEVELS
    23
    24      public static final int NONE            = 0;  // For querying, ignore all errors
    25      public static final int LIKELY_ERRORS   = 1;  // Warning indicates likely error
    26      public static final int POSSIBLE_ERRORS = 2;  // Warning indicates possible error
    27      public static final int PARANOIA        = 3;  // Warning indicates paranoia on the part of the compiler
    28
    29
    30     /***
    31      *  Returns true if a warning would be relevant to the specified level.
    32      */
    33
    34      public static boolean isRelevant( int actual, int limit )
    35      {
    36          return actual <= limit;
    37      }
    38
    39
    40
    41     /***
    42      *  Returns true if this message is as or more important than the
    43      *  specified importance level.
    44      */
    45
    46      public boolean isRelevant( int importance )
    47      {
    48          return isRelevant( this.importance, importance );
    49      }
    50
    51
    52
    53    //---------------------------------------------------------------------------
    54    // CONSTRUCTION AND DATA ACCESS
    55
    56      private int importance;  // The warning level, for filtering
    57
    58
    59     /***
    60      *  Creates a new warning message.
    61      *
    62      *  @param importance the warning level
    63      *  @param message    the message text
    64      *  @param context    context information for locating the offending source text
    65      */
    66
    67      public WarningMessage( int importance, String message, CSTNode context, SourceUnit owner )
    68      {
    69          super( message, context, owner );
    70          this.importance = importance;
    71      }
    72
    73
    74
    75     /***
    76      *  Creates a new warning message.
    77      *
    78      *  @param importance the warning level
    79      *  @param message    the message text
    80      *  @param data       additional data needed when generating the message
    81      *  @param context    context information for locating the offending source text
    82      */
    83
    84      public WarningMessage( int importance, String message, Object data, CSTNode context, SourceUnit owner )
    85      {
    86          super( message, data, context, owner );
    87          this.importance = importance;
    88      }
    89
    90
    91      public void write( PrintWriter writer, Janitor janitor )
    92      {
    93          writer.print( "warning: " );
    94          super.write( writer, janitor );
    95      }
    96
    97
    98
    99  }
    100
    101
    102