61 @Test
62 public void testDiagListener() throws Exception {
63 JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", "package pkg; public error { }");
64 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
65 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
66 File outDir = getOutDir();
67 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
68 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
69 DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
70 DocumentationTask t = tool.getTask(null, fm, dc, null, null, files);
71 if (t.call()) {
72 throw new Exception("task succeeded unexpectedly");
73 } else {
74 List<String> diagCodes = new ArrayList<String>();
75 for (Diagnostic d: dc.getDiagnostics()) {
76 System.err.println(d);
77 diagCodes.add(d.getCode());
78 }
79 List<String> expect = Arrays.asList(
80 "javadoc.note.msg", // Loading source file
81 "compiler.err.expected3", // class, interface, or enum expected
82 "javadoc.note.msg"); // 1 error
83 if (!diagCodes.equals(expect))
84 throw new Exception("unexpected diagnostics occurred");
85 System.err.println("diagnostics received as expected");
86 }
87 }
88 }
89
90 }
91
|
61 @Test
62 public void testDiagListener() throws Exception {
63 JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", "package pkg; public error { }");
64 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
65 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
66 File outDir = getOutDir();
67 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
68 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
69 DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
70 DocumentationTask t = tool.getTask(null, fm, dc, null, null, files);
71 if (t.call()) {
72 throw new Exception("task succeeded unexpectedly");
73 } else {
74 List<String> diagCodes = new ArrayList<String>();
75 for (Diagnostic d: dc.getDiagnostics()) {
76 System.err.println(d);
77 diagCodes.add(d.getCode());
78 }
79 List<String> expect = Arrays.asList(
80 "javadoc.note.msg", // Loading source file
81 "compiler.err.expected3", // class, interface, enum, or __datum expected
82 "javadoc.note.msg"); // 1 error
83 if (!diagCodes.equals(expect))
84 throw new Exception("unexpected diagnostics occurred");
85 System.err.println("diagnostics received as expected");
86 }
87 }
88 }
89
90 }
91
|