Search in sources :

Example 31 with Diagnostic

use of javax.tools.Diagnostic in project ceylon-compiler by ceylon.

the class JavapTask method getDiagnosticListenerForWriter.

private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) {
    final PrintWriter pw = getPrintWriterForWriter(w);
    return new DiagnosticListener<JavaFileObject>() {

        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
            switch(diagnostic.getKind()) {
                case ERROR:
                    pw.print(getMessage("err.prefix"));
                    break;
                case WARNING:
                    pw.print(getMessage("warn.prefix"));
                    break;
                case NOTE:
                    pw.print(getMessage("note.prefix"));
                    break;
            }
            pw.print(" ");
            pw.println(diagnostic.getMessage(null));
        }
    };
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Diagnostic(javax.tools.Diagnostic) DiagnosticListener(javax.tools.DiagnosticListener) PrintWriter(java.io.PrintWriter)

Aggregations

Diagnostic (javax.tools.Diagnostic)31 JavaFileObject (javax.tools.JavaFileObject)30 Test (org.junit.Test)13 JavaCompiler (javax.tools.JavaCompiler)11 Result (com.sun.tools.javac.main.Main.Result)10 DiagnosticCollector (javax.tools.DiagnosticCollector)9 File (java.io.File)7 IOException (java.io.IOException)7 SimpleJavaFileObject (javax.tools.SimpleJavaFileObject)7 PrintWriter (java.io.PrintWriter)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 ArrayList (java.util.ArrayList)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DiagnosticListener (javax.tools.DiagnosticListener)4 ImmutableList (com.google.common.collect.ImmutableList)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)2 JavacTask (com.sun.source.util.JavacTask)2 OutputStreamWriter (java.io.OutputStreamWriter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2