Java Utililty Methods Diagnostic to Output

List of utility methods to do Diagnostic to Output

Description

The list of methods to do Diagnostic to Output are organized into topic(s).

Method

StringdiagnosticToString(final Diagnostic diagnostic, boolean usingAnomsgtxt)
diagnostic To String
String result = diagnostic.toString().trim();
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;
if (usingAnomsgtxt) {
...
StringerrorsToString(DiagnosticCollector diagnosticCollector)
errors To String
StringBuilder builder = new StringBuilder();
for (javax.tools.Diagnostic<? extends JavaFileObject> diagnostic : diagnosticCollector.getDiagnostics()) {
    if (diagnostic.getKind() == javax.tools.Diagnostic.Kind.ERROR) {
        builder.append(diagnostic).append("\n");
return builder.toString();
List>filterSupportedSourceVersionWarnings( List> diagnostics)
Filter out warnings about SupportedSourceVersion .
List<Diagnostic<? extends JavaFileObject>> r = new ArrayList<Diagnostic<? extends JavaFileObject>>();
for (Diagnostic<? extends JavaFileObject> d : diagnostics) {
    if (!d.getMessage(Locale.ENGLISH).contains("SupportedSourceVersion")) {
        r.add(d);
return r;
voidlog(ProcessingEnvironment processingEnvironment, Diagnostic.Kind kind, CharSequence message)
log
processingEnvironment.getMessager().printMessage(kind, MESSAGER_HEADER + " " + message);
voidnote(final ProcessingEnvironment processingEnv, final String message, final Object... args)
Writes a message of type Kind#NOTE to the messager substituting arguments in the message using String#format(String,Object) .
processingEnv.getMessager().printMessage(Kind.NOTE, PREFIX + String.format(message, args));
voidraiseCompilerError(String error)
Raises a fatal compiler error with the given message, halting execution.
if (processingEnv == null) {
    return;
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Fatal error from optimiser: " + error
        + "\nAt:\n" + Arrays.toString(new Exception().getStackTrace()).replace(',', '\n'));