📄 log.java
字号:
bp = lineStart; while (bp < buf.length && bp < pos) { switch (buf[bp++]) { case CR: if (bp < buf.length && buf[bp] == LF) bp++; line++; lineStart = bp; break; case LF: line++; lineStart = bp; break; } } return bp <= buf.length; } catch (IOException e) { //e.printStackTrace(); // FIXME: include e.getLocalizedMessage() in error message printLines(errWriter, getLocalizedString("source.unavailable")); errWriter.flush(); buf = new char[0]; } return false; } /** Print the text of a message, translating newlines appropriately * for the platform. */ public static void printLines(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); } /** Report an error, unless another error was already reported at same * source position. * @param key The key for the localized error message. * @param args Fields of the error message. */ public void error(String key, Object ... args) { report(diags.error(source, null, key, args)); } /** Report an error, unless another error was already reported at same * source position. * @param pos The source position at which to report the error. * @param key The key for the localized error message. * @param args Fields of the error message. */ public void error(DiagnosticPosition pos, String key, Object ... args) { report(diags.error(source, pos, key, args)); } /** Report an error, unless another error was already reported at same * source position. * @param pos The source position at which to report the error. * @param key The key for the localized error message. * @param args Fields of the error message. */ public void error(int pos, String key, Object ... args) { report(diags.error(source, wrap(pos), key, args)); } /** Report a warning, unless suppressed by the -nowarn option or the * maximum number of warnings has been reached. * @param pos The source position at which to report the warning. * @param key The key for the localized warning message. * @param args Fields of the warning message. */ public void warning(String key, Object ... args) { report(diags.warning(source, null, key, args)); } /** Report a warning, unless suppressed by the -nowarn option or the * maximum number of warnings has been reached. * @param pos The source position at which to report the warning. * @param key The key for the localized warning message. * @param args Fields of the warning message. */ public void warning(DiagnosticPosition pos, String key, Object ... args) { report(diags.warning(source, pos, key, args)); } /** Report a warning, unless suppressed by the -nowarn option or the * maximum number of warnings has been reached. * @param pos The source position at which to report the warning. * @param key The key for the localized warning message. * @param args Fields of the warning message. */ public void warning(int pos, String key, Object ... args) { report(diags.warning(source, wrap(pos), key, args)); } /** Report a warning. * @param pos The source position at which to report the warning. * @param key The key for the localized warning message. * @param args Fields of the warning message. */ public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) { if (enforceMandatoryWarnings) report(diags.mandatoryWarning(source, pos, key, args)); else report(diags.warning(source, pos, key, args)); } /** Report a warning that cannot be suppressed. * @param pos The source position at which to report the warning. * @param key The key for the localized warning message. * @param args Fields of the warning message. */ public void strictWarning(DiagnosticPosition pos, String key, Object ... args) { writeDiagnostic(diags.warning(source, pos, key, args)); nwarnings++; } /** Provide a non-fatal notification, unless suppressed by the -nowarn option. * @param key The key for the localized notification message. * @param args Fields of the notification message. */ public void note(String key, Object ... args) { report(diags.note(source, null, key, args)); } /** Provide a non-fatal notification, unless suppressed by the -nowarn option. * @param key The key for the localized notification message. * @param args Fields of the notification message. */ public void note(DiagnosticPosition pos, String key, Object ... args) { report(diags.note(source, pos, key, args)); } /** Provide a non-fatal notification, unless suppressed by the -nowarn option. * @param key The key for the localized notification message. * @param args Fields of the notification message. */ public void note(int pos, String key, Object ... args) { report(diags.note(source, wrap(pos), key, args)); } /** Provide a non-fatal notification, unless suppressed by the -nowarn option. * @param key The key for the localized notification message. * @param args Fields of the notification message. */ public void mandatoryNote(final JavaFileObject file, String key, Object ... args) { JCDiagnostic.DiagnosticSource wrapper = null; if (file != null) { wrapper = new JCDiagnostic.DiagnosticSource() { public JavaFileObject getFile() { return file; } public CharSequence getName() { return JavacFileManager.getJavacBaseFileName(getFile()); } public int getLineNumber(int pos) { return Log.this.getLineNumber(pos); } public int getColumnNumber(int pos) { return Log.this.getColumnNumber(pos); } public Map<JCTree, Integer> getEndPosTable() { return (endPosTables == null ? null : endPosTables.get(file)); } }; } if (enforceMandatoryWarnings) report(diags.mandatoryNote(wrapper, key, args)); else report(diags.note(wrapper, null, key, args)); } private DiagnosticPosition wrap(int pos) { return (pos == Position.NOPOS ? null : new SimpleDiagnosticPosition(pos)); } /** * Common diagnostic handling. * The diagnostic is counted, and depending on the options and how many diagnostics have been * reported so far, the diagnostic may be handed off to writeDiagnostic. */ public void report(JCDiagnostic diagnostic) { switch (diagnostic.getType()) { case FRAGMENT: throw new IllegalArgumentException(); case NOTE: // Print out notes only when we are permitted to report warnings // Notes are only generated at the end of a compilation, so should be small // in number. if (emitWarnings || diagnostic.isMandatory()) { writeDiagnostic(diagnostic); } break; case WARNING: if (emitWarnings || diagnostic.isMandatory()) { if (nwarnings < MaxWarnings) { writeDiagnostic(diagnostic); nwarnings++; } } break; case ERROR: if (nerrors < MaxErrors && shouldReport(diagnostic.getSource(), diagnostic.getIntPosition())) { writeDiagnostic(diagnostic); nerrors++; } break; } } /** * Write out a diagnostic. */ protected void writeDiagnostic(JCDiagnostic diag) { if (diagListener != null) { try { diagListener.report(diag); return; } catch (Throwable t) { throw new ClientCodeException(t); } } PrintWriter writer = getWriterForDiagnosticType(diag.getType()); printLines(writer, diagFormatter.format(diag)); if (showSourceLine) { int pos = diag.getIntPosition(); if (pos != Position.NOPOS) { JavaFileObject prev = useSource(diag.getSource()); printErrLine(pos, writer); useSource(prev); } } if (promptOnError) { switch (diag.getType()) { case ERROR: case WARNING: prompt(); } } if (dumpOnError) new RuntimeException().printStackTrace(writer); writer.flush(); } @Deprecated protected PrintWriter getWriterForDiagnosticType(DiagnosticType dt) { switch (dt) { case FRAGMENT: throw new IllegalArgumentException(); case NOTE: return noticeWriter; case WARNING: return warnWriter; case ERROR: return errWriter; default: throw new Error(); } } /** Find a localized string in the resource bundle. * @param key The key for the localized string. * @param args Fields to substitute into the string. */ public static String getLocalizedString(String key, Object ... args) { return Messages.getDefaultLocalizedString("compiler.misc." + key, args); }/*************************************************************************** * raw error messages without internationalization; used for experimentation * and quick prototyping ***************************************************************************//** print an error or warning message: */ private void printRawError(int pos, String msg) { if (!findLine(pos)) { printLines(errWriter, "error: " + msg); } else { JavaFileObject file = currentSource(); if (file != null) printLines(errWriter, JavacFileManager.getJavacFileName(file) + ":" + line + ": " + msg); printErrLine(pos, errWriter); } errWriter.flush(); }/** report an error: */ public void rawError(int pos, String msg) { if (nerrors < MaxErrors && shouldReport(currentSource(), pos)) { printRawError(pos, msg); prompt(); nerrors++; } errWriter.flush(); }/** report a warning: */ public void rawWarning(int pos, String msg) { if (nwarnings < MaxWarnings && emitWarnings) { printRawError(pos, "warning: " + msg); } prompt(); nwarnings++; errWriter.flush(); } /** Return the one-based line number associated with a given pos * for the current source file. Zero is returned if no line exists * for the given position. */ protected int getLineNumber(int pos) { if (findLine(pos)) return line; return 0; } /** Return the one-based column number associated with a given pos * for the current source file. Zero is returned if no column exists * for the given position. */ protected int getColumnNumber(int pos) { if (findLine(pos)) { int column = 0; for (bp = lineStart; bp < pos; bp++) { if (bp >= buf.length) return 0; if (buf[bp] == '\t') column = (column / TabInc * TabInc) + TabInc; else column++; } return column + 1; // positions are one-based } return 0; } public static String format(String fmt, Object... args) { return String.format((java.util.Locale)null, fmt, args); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -