KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > util > AbstractErrorQueue


1 package polyglot.util;
2
3
4 /**
5  * A <code>StdErrorQueue</code> handles outputing error messages.
6  */

7 public abstract class AbstractErrorQueue implements ErrorQueue
8 {
9     protected boolean flushed;
10     protected int errorCount;
11     protected final int limit;
12     protected final String JavaDoc name;
13     
14     public AbstractErrorQueue(int limit, String JavaDoc name) {
15     this.errorCount = 0;
16     this.limit = limit;
17     this.name = name;
18         this.flushed = true;
19     }
20
21     public final void enqueue(int type, String JavaDoc message) {
22     enqueue(type, message, null);
23     }
24
25     public final void enqueue(int type, String JavaDoc message, Position position) {
26     enqueue(new ErrorInfo(type, message, position));
27     }
28
29     public final void enqueue(ErrorInfo e) {
30     if (e.getErrorKind() != ErrorInfo.WARNING) {
31         errorCount++;
32     }
33
34     flushed = false;
35
36         displayError(e);
37
38     if (errorCount >= limit) {
39         tooManyErrors(e);
40         flush();
41         throw new ErrorLimitError();
42     }
43     }
44
45     protected abstract void displayError(ErrorInfo error);
46     
47     /**
48      * This method is called when we have had too many errors. This method
49      * give subclasses the opportunity to output appropriate messages, or
50      * tidy up.
51      *
52      * @param lastError the last error that pushed us over the limit
53      */

54     protected void tooManyErrors(ErrorInfo lastError) {
55     }
56     
57     /**
58      * This method is called to flush the error queue. Subclasses may want to
59      * print summary information in this method.
60      */

61     public void flush() {
62         flushed = true;
63     }
64
65     public final boolean hasErrors() {
66       return errorCount > 0;
67     }
68
69     public final int errorCount() {
70         return errorCount;
71     }
72 }
73
Popular Tags