1 package polyglot.util; 2 3 4 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 name; 13 14 public AbstractErrorQueue(int limit, String 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 message) { 22 enqueue(type, message, null); 23 } 24 25 public final void enqueue(int type, String 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 54 protected void tooManyErrors(ErrorInfo lastError) { 55 } 56 57 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 |