Java Diagnostic to Output diagnosticToString(final Diagnostic diagnostic, boolean usingAnomsgtxt)

Here you can find the source of diagnosticToString(final Diagnostic diagnostic, boolean usingAnomsgtxt)

Description

diagnostic To String

License

Open Source License

Declaration

public static String diagnosticToString(final Diagnostic<? extends JavaFileObject> diagnostic,
            boolean usingAnomsgtxt) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

import javax.tools.Diagnostic;

import javax.tools.JavaFileObject;

public class Main {
    public static String diagnosticToString(final Diagnostic<? extends JavaFileObject> diagnostic,
            boolean usingAnomsgtxt) {

        String result = diagnostic.toString().trim();

        // suppress Xlint warnings
        if (result.contains("uses unchecked or unsafe operations.")
                || result.contains("Recompile with -Xlint:unchecked for details.")
                || result.endsWith(" declares unsafe vararg methods.")
                || result.contains("Recompile with -Xlint:varargs for details.")) {
            return null;
        }/*from  www .  j ava  2  s .  co m*/

        if (usingAnomsgtxt) {
            // Lines with "unexpected Throwable" are stack traces
            // and should be printed in full.
            if (!result.contains("unexpected Throwable")) {
                String firstLine;
                if (result.contains("\n")) {
                    firstLine = result.substring(0, result.indexOf('\n'));
                } else {
                    firstLine = result;
                }
                if (firstLine.contains(".java:")) {
                    firstLine = firstLine.substring(firstLine.indexOf(".java:") + 5).trim();
                }
                result = firstLine;
            }
        }

        return result;
    }
}

Related

  1. errorsToString( DiagnosticCollector diagnosticCollector)
  2. filterSupportedSourceVersionWarnings( List> diagnostics)
  3. log(ProcessingEnvironment processingEnvironment, Diagnostic.Kind kind, CharSequence message)
  4. note(final ProcessingEnvironment processingEnv, final String message, final Object... args)