Exemple #1
0
 /** 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);
 }
Exemple #2
0
  /**
   * 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();
  }
Exemple #3
0
 /** report a warning: */
 public void rawWarning(int pos, String msg) {
   if (nwarnings < MaxWarnings && emitWarnings) {
     printRawError(pos, "warning: " + msg);
   }
   prompt();
   nwarnings++;
   errWriter.flush();
 }
Exemple #4
0
 /** report an error: */
 public void rawError(int pos, String msg) {
   if (nerrors < MaxErrors && shouldReport(currentSourceFile(), pos)) {
     printRawError(pos, msg);
     prompt();
     nerrors++;
   }
   errWriter.flush();
 }
Exemple #5
0
 /** 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();
 }
Exemple #6
0
  /** 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();
  }
Exemple #7
0
 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();
   }
 }
Exemple #8
0
 protected void directError(String key, Object... args) {
   printRawLines(errWriter, localize(key, args));
   errWriter.flush();
 }
Exemple #9
0
 public void printNewline() {
   noticeWriter.println();
 }
Exemple #10
0
 /** Flush the logs */
 public void flush() {
   errWriter.flush();
   warnWriter.flush();
   noticeWriter.flush();
 }
Exemple #11
0
 public void setWriters(PrintWriter pw) {
   pw.getClass();
   noticeWriter = warnWriter = errWriter = pw;
 }