001 package org.codehaus.groovy.control.messages;
002
003 import java.io.PrintWriter;
004
005 import org.codehaus.groovy.control.Janitor;
006 import org.codehaus.groovy.control.SourceUnit;
007 import org.codehaus.groovy.syntax.CSTNode;
008
009
010
011 /**
012 * A class for warning messages.
013 *
014 * @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
015 *
016 * @version $Id: WarningMessage.java,v 1.4 2005/06/10 09:55:30 cstein Exp $
017 */
018
019 public class WarningMessage extends LocatedMessage
020 {
021 //---------------------------------------------------------------------------
022 // WARNING LEVELS
023
024 public static final int NONE = 0; // For querying, ignore all errors
025 public static final int LIKELY_ERRORS = 1; // Warning indicates likely error
026 public static final int POSSIBLE_ERRORS = 2; // Warning indicates possible error
027 public static final int PARANOIA = 3; // Warning indicates paranoia on the part of the compiler
028
029
030 /**
031 * Returns true if a warning would be relevant to the specified level.
032 */
033
034 public static boolean isRelevant( int actual, int limit )
035 {
036 return actual <= limit;
037 }
038
039
040
041 /**
042 * Returns true if this message is as or more important than the
043 * specified importance level.
044 */
045
046 public boolean isRelevant( int importance )
047 {
048 return isRelevant( this.importance, importance );
049 }
050
051
052
053 //---------------------------------------------------------------------------
054 // CONSTRUCTION AND DATA ACCESS
055
056 private int importance; // The warning level, for filtering
057
058
059 /**
060 * Creates a new warning message.
061 *
062 * @param importance the warning level
063 * @param message the message text
064 * @param context context information for locating the offending source text
065 */
066
067 public WarningMessage( int importance, String message, CSTNode context, SourceUnit owner )
068 {
069 super( message, context, owner );
070 this.importance = importance;
071 }
072
073
074
075 /**
076 * Creates a new warning message.
077 *
078 * @param importance the warning level
079 * @param message the message text
080 * @param data additional data needed when generating the message
081 * @param context context information for locating the offending source text
082 */
083
084 public WarningMessage( int importance, String message, Object data, CSTNode context, SourceUnit owner )
085 {
086 super( message, data, context, owner );
087 this.importance = importance;
088 }
089
090
091 public void write( PrintWriter writer, Janitor janitor )
092 {
093 writer.print( "warning: " );
094 super.write( writer, janitor );
095 }
096
097
098
099 }
100
101
102