/** Print the text of a message, translating newlines appropriately for the platform. */ public static void printRawLines(PrintWriter writer, String msg) { int nl; while ((nl = msg.indexOf('\n')) != -1) { writer.println(msg.substring(0, nl)); msg = msg.substring(nl + 1); } if (msg.length() != 0) writer.println(msg); }
/** * Print the faulty source code line and point to the error. * * @param pos Buffer index of the error position, must be on current line */ private void printErrLine(int pos, PrintWriter writer) { String line = (source == null ? null : source.getLine(pos)); if (line == null) return; int col = source.getColumnNumber(pos, false); printRawLines(writer, line); for (int i = 0; i < col - 1; i++) { writer.print((line.charAt(i) == '\t') ? "\t" : " "); } writer.println("^"); writer.flush(); }
/** report a warning: */ public void rawWarning(int pos, String msg) { if (nwarnings < MaxWarnings && emitWarnings) { printRawError(pos, "warning: " + msg); } prompt(); nwarnings++; errWriter.flush(); }
/** report an error: */ public void rawError(int pos, String msg) { if (nerrors < MaxErrors && shouldReport(currentSourceFile(), pos)) { printRawError(pos, msg); prompt(); nerrors++; } errWriter.flush(); }
/** print an error or warning message: */ private void printRawError(int pos, String msg) { if (source == null || pos == Position.NOPOS) { printRawLines(errWriter, "error: " + msg); } else { int line = source.getLineNumber(pos); JavaFileObject file = source.getFile(); if (file != null) printRawLines(errWriter, file.getName() + ":" + line + ": " + msg); printErrLine(pos, errWriter); } errWriter.flush(); }
/** Write out a diagnostic. */ protected void writeDiagnostic(JCDiagnostic diag) { if (diagListener != null) { diagListener.report(diag); return; } PrintWriter writer = getWriterForDiagnosticType(diag.getType()); printRawLines(writer, diagFormatter.format(diag, messages.getCurrentLocale())); if (promptOnError) { switch (diag.getType()) { case ERROR: case WARNING: prompt(); } } if (dumpOnError) new RuntimeException().printStackTrace(writer); writer.flush(); }
public void setWriter(WriterKind kind, PrintWriter pw) { pw.getClass(); switch (kind) { case NOTICE: noticeWriter = pw; break; case WARNING: warnWriter = pw; break; case ERROR: errWriter = pw; break; default: throw new IllegalArgumentException(); } }
protected void directError(String key, Object... args) { printRawLines(errWriter, localize(key, args)); errWriter.flush(); }
public void printNewline() { noticeWriter.println(); }
/** Flush the logs */ public void flush() { errWriter.flush(); warnWriter.flush(); noticeWriter.flush(); }
public void setWriters(PrintWriter pw) { pw.getClass(); noticeWriter = warnWriter = errWriter = pw; }