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