< prev index next >

test/langtools/tools/javac/processing/6430209/T6430209.java

Print this page
rev 48841 : imported patch 8187950

*** 35,47 **** // Note that 6441871 is an interim partial fix for 6430209 that just removes the javac // crash message and stacktrace import java.io.*; import java.util.*; - import javax.annotation.processing.*; - import javax.lang.model.*; - import javax.lang.model.element.*; import javax.tools.*; import com.sun.source.util.*; import com.sun.tools.javac.api.*; --- 35,44 ----
*** 57,90 **** // run annotation processor b6341534 so we can check diagnostics // -proc:only -processor b6341534 -cp . ./src/*.java String testSrc = System.getProperty("test.src", "."); String testClassPath = System.getProperty("test.class.path"); JavacTool tool = JavacTool.create(); ! MyDiagListener dl = new MyDiagListener(); ! try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File("."))); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList( new File(testSrc, "test0.java"), new File(testSrc, "test1.java"))); ! Iterable<String> opts = Arrays.asList("-proc:only", "-processor", "b6341534", "-processorpath", testClassPath); StringWriter out = new StringWriter(); ! JavacTask task = tool.getTask(out, fm, dl, opts, null, files); task.call(); String s = out.toString(); System.err.print(s); ! // Expect the following 2 diagnostics, and no output to log ! System.err.println(dl.count + " diagnostics; " + s.length() + " characters"); ! if (dl.count != 2 || s.length() != 0) ! throw new AssertionError("unexpected output from compiler"); } } - static class MyDiagListener implements DiagnosticListener<JavaFileObject> { - public void report(Diagnostic d) { - System.err.println(d); - count++; - } - - public int count; - } } --- 54,80 ---- // run annotation processor b6341534 so we can check diagnostics // -proc:only -processor b6341534 -cp . ./src/*.java String testSrc = System.getProperty("test.src", "."); String testClassPath = System.getProperty("test.class.path"); JavacTool tool = JavacTool.create(); ! try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File("."))); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList( new File(testSrc, "test0.java"), new File(testSrc, "test1.java"))); ! Iterable<String> opts = Arrays.asList("-XDrawDiagnostics", ! "-proc:only", "-processor", "b6341534", "-processorpath", testClassPath); StringWriter out = new StringWriter(); ! JavacTask task = tool.getTask(out, fm, null, opts, null, files); task.call(); String s = out.toString(); System.err.print(s); ! s = s.replace(System.getProperty("line.separator"), "\n"); ! String expected = "test0.java:1:8: compiler.err.duplicate.class: test0\n" + ! "1 error\n"; ! if (!expected.equals(s)) ! throw new AssertionError("unexpected text in output"); } } }
< prev index next >