-
Bug
-
Resolution: Fixed
-
P4
-
7
-
b128
-
generic
-
generic
-
Not verified
Three minor doc bugs in JavaCompiler.java code example :
The doc says :
<DiagnosticCollector_example_code >
Used to collect diagnostics in a list, for example:
Iterable<? extends JavaFileObject> compilationUnits = ...;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits).call();
for (Diagnostic diagnostic : diagnostics.getDiagnostics())
System.out.format("Error on line %d in %d%n",
diagnostic.getLineNumber()
diagnostic.getSource().toUri());
fileManager.close();
</DiagnosticCollector_example_code >
1)for (Diagnostic diagnostic : diagnostics.getDiagnostics()) should be
*for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) *
since
a) toUri() method is directly calling on dignostic.getSource() method
***diagnostic.getSource().toUri()) ***
b) diagnostics is already of type JavaFileObject
2)System.out.format has both '%d's, it should be one %d and other %s since first one points to number but second one pointes to a String.
System.out.format("Error on line %d in **%s**%n",
3) ',' is missing between diagnostic.getLineNumber and diagnostic.getSource
The doc says :
<DiagnosticCollector_example_code >
Used to collect diagnostics in a list, for example:
Iterable<? extends JavaFileObject> compilationUnits = ...;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits).call();
for (Diagnostic diagnostic : diagnostics.getDiagnostics())
System.out.format("Error on line %d in %d%n",
diagnostic.getLineNumber()
diagnostic.getSource().toUri());
fileManager.close();
</DiagnosticCollector_example_code >
1)for (Diagnostic diagnostic : diagnostics.getDiagnostics()) should be
*for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) *
since
a) toUri() method is directly calling on dignostic.getSource() method
***diagnostic.getSource().toUri()) ***
b) diagnostics is already of type JavaFileObject
2)System.out.format has both '%d's, it should be one %d and other %s since first one points to number but second one pointes to a String.
System.out.format("Error on line %d in **%s**%n",
3) ',' is missing between diagnostic.getLineNumber and diagnostic.getSource