KickJava   Java API By Example, From Geeks To Geeks.

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


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.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,v 1.1 2004/04/19 07:29:45 cpoirier Exp $
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 JavaDoc message, CSTNode context )
68     {
69         super( message, context );
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 JavaDoc message, Object JavaDoc data, CSTNode context )
85     {
86         super( message, data, context );
87         this.importance = importance;
88     }
89     
90     
91     public void write( PrintWriter JavaDoc writer, ProcessingUnit owner, Janitor janitor )
92     {
93         writer.print( "warning: " );
94         super.write( writer, owner, janitor );
95     }
96
97      
98      
99 }
100
101
102
103
Popular Tags