report method which hands off to
a similar method in the superclass (Log.report, which takes care
of reporting the diagnostic (unless it has been suppressed), displaying
the source line and a caret to indicate the position of the issue (if appropriate),
counting errors and warnings, and so on.
In general, the underlying javac layer is more powerful, whereas the javadoc methods are
constrained by the public jdk.javadoc.doclet.Doclet API.
In the underlying javac layer, the following abstractions are used:
DiagnosticType -- error, warning, note, etc.
DiagnosticSource -- a file object and a cache of its content
DiagnosticPosition -- a tuple of values (start, pos, end) for the position of a diagnostic
DiagnosticFlag -- additional flags related to the diagnostic
Doclet.Reporter, and by
assorted methods defined in this class for use by the javadoc tool.
The primary data types are:
Diagnostic.Kind -- maps to DiagnosticType and Set<DiagnosticFlag>
Element -- maps to DiagnosticSource and DiagnosticPosition
DocTreePath -- maps to DiagnosticSource and DiagnosticPosition
Reporter interface, take
localized strings. To accommodate this, "wrapper" resources are used, whose value is {0},
to pass the localized string down to javac. A side-effect is that clients using a
DiagnosticListener with a DocumentationTask cannot access the original resource
key for the localized message.
Given the limitations of the API, it is not possible to do any better.
The javac Annotation Processing API has the same problem.
There is a slight disparity between javac's use of streams and javadoc's use of streams.
javac reports all diagnostics to the "error" stream, and provides a separate
"output" stream for expected output, such as command-line help or the output from options
like -Xprint. javadoc API, and Reporter in particular, does not specify
the use of streams, and provides no support for identifying or specifying streams. JDK-8267204.
The current implementation/workaround is to write errors and warnings to the "error"
stream and notes to the "output" stream.
java.util.ResourceBundle , java.text.MessageFormat
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final Context | context
The overall context for the documentation run.
|
| private final LinkedHashMap | diagSourceCache
A memory-sensitive cache of recently used |
| private final JCDiagnostic. | |
| private Locale | |
| private final JavacMessages | |
| pack-priv final String | |
| private DocSourcePositions | sourcePositions
The utility class to access the positions of items in doc comments. |
| private ToolEnvironment | toolEnv
The tool environment, providing access to the tool's utility classes and tables. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JavadocLog(Context context, String
Name of the program (for error messages). programName, PrintWriter Stream for notices etc. outWriter, PrintWriter Stream for errors and warnings errWriter)Constructor |
| Modifier and Type | Method and Description |
|---|---|
| private JCDiagnostic. | Returns: the diagnostic positionthe tree node, or null if no tree is applicable tree, int the start position start, int the "preferred" position: this is used to position the caret in messages pos, int the end position end)Creates a diagnostic position. |
| private static PrintWriter | |
| private Set | Returns: the flagsthe diagnostic kind kindReturns the diagnostic flags for a diagnostic kind. |
| private JCDiagnostic. | Returns: the diagnostic positionthe path for the documentation tree node path)Returns a diagnostic position for a documentation tree node. |
| private JCDiagnostic. | Returns: the diagnostic positionthe element element)Returns a diagnostic position for an element, or |
| private DiagnosticSource | Returns: the diagnostic sourcethe path for the documentation tree node path)Returns the diagnostic source for a documentation tree node. |
| private DiagnosticSource | Returns: the diagnostic sourcethe element element)Returns the diagnostic source for an element, or |
| private DiagnosticSource | Returns: the diagnostic sourcethe file object fo)Returns the diagnostic source for a file object. |
| private JCDiagnostic. | Returns: the diagnostic typethe diagnostic kind kindReturns the diagnostic type for a diagnostic kind. |
| public PrintWriter | getDiagnosticWriter()
Overrides default jdk. Returns a writer that can be used to write diagnostic output,
or |
| private DocSourcePositions | Returns: the object for computing source positionsReturns the object for computing source positions. |
| public PrintWriter | getStandardWriter()
Overrides default jdk. Returns a writer that can be used to write non-diagnostic output,
or |
| pack-priv String | |
| private ToolEnvironment | |
| public boolean | |
| public boolean | |
| public static JavadocLog | |
| public static void | |
| public static void | preRegister(Context context, final String programName, final PrintWriter outWriter, final PrintWriter errWriter)
|
| public void | print(Diagnostic.
Implements jdk. Prints a diagnostic message. |
| public void | print(Diagnostic.
Implements jdk. Prints a diagnostic message related to a tree node in a documentation comment. |
| public void | print(Diagnostic.
Overrides default jdk. Prints a diagnostic message related to a position within a range of characters in a tree node. |
| public void | print(Diagnostic.
Implements jdk. Prints a diagnostic message related to an element. |
| public void | print(Diagnostic.
Overrides default jdk. Prints a diagnostic message related to a position within a range of characters in a file. |
| private void | |
| public void | |
| public void | printError(DocTreePath
the path for the documentation tree node path, String the message message)Prints an error message for a given documentation tree node. |
| public void | printError(Element
the element element, String the message message)Prints an error message for a given element. |
| public void | printErrorUsingKey(String
the resource key for the message key, Object... the arguments for the message args)Prints an error message. |
| public void | |
| public void | |
| public void | printNoteUsingKey(String
the resource key for the message key, Object... the arguments for the message args)Prints a "notice" message. |
| public void | |
| public void | printWarning(DocTreePath
the path for the documentation tree node path, String the message message)Prints a warning message for a given documentation tree node. |
| public void | printWarning(Element
the element element, String the message message)Prints a warning message for a given element. |
| public void | printWarningUsingKey(String
the resource key for the message key, Object... the arguments for the message args)Prints a warning message. |
| public void | printWarningUsingKey(Element
the element element, String the resource key for the message key, Object... the arguments for the message args)Prints a warning message for an element. |
| private void | report(Diagnostic.
the kind of diagnostic kind,the diagnostic source ds, JCDiagnostic.the diagnostic position dp,the message message)Reports a diagnostic message. |
| private void | report(JCDiagnostic.
the diagnostic type dt,the diagnostic source ds, JCDiagnostic.the diagnostic position dp,the message message)Reports a diagnostic message. |
| private void | report(JCDiagnostic.
the diagnostic type dt,the diagnostic source ds, JCDiagnostic.the diagnostic position dp,the message message)Reports a diagnostic message, with diagnostic flags. |
| public void |
| context | back to summary |
|---|---|
| private final Context context Hides com. The overall context for the documentation run. | |
| diagSourceCache | back to summary |
|---|---|
| private final LinkedHashMap<JavaFileObject, SoftReference<DiagnosticSource>> diagSourceCache A memory-sensitive cache of recently used | |
| javadocDiags | back to summary |
|---|---|
| private final JCDiagnostic. | |
| locale | back to summary |
|---|---|
| private Locale locale | |
| messages | back to summary |
|---|---|
| private final JavacMessages messages | |
| programName | back to summary |
|---|---|
| pack-priv final String programName | |
| sourcePositions | back to summary |
|---|---|
| private DocSourcePositions sourcePositions The utility class to access the positions of items in doc comments. | |
| toolEnv | back to summary |
|---|---|
| private ToolEnvironment toolEnv The tool environment, providing access to the tool's utility classes and tables. | |
| JavadocLog | back to summary |
|---|---|
| public JavadocLog(Context context, String programName) Constructor
| |
| JavadocLog | back to summary |
|---|---|
| public JavadocLog(Context context, String programName, PrintWriter outWriter, PrintWriter errWriter) Constructor
| |
| createDiagnosticPosition | back to summary |
|---|---|
| private JCDiagnostic. Creates a diagnostic position.
| |
| createPrintWriter | back to summary |
|---|---|
| private static PrintWriter createPrintWriter(PrintStream ps, boolean autoflush) | |
| getDiagnosticFlags | back to summary |
|---|---|
| private Set Returns the diagnostic flags for a diagnostic kind.
A diagnostic kind of
| |
| getDiagnosticPosition | back to summary |
|---|---|
| private JCDiagnostic. Returns a diagnostic position for a documentation tree node.
| |
| getDiagnosticPosition | back to summary |
|---|---|
| private JCDiagnostic. Returns a diagnostic position for an element, or
| |
| getDiagnosticSource | back to summary |
|---|---|
| private DiagnosticSource getDiagnosticSource(DocTreePath path) Returns the diagnostic source for a documentation tree node.
| |
| getDiagnosticSource | back to summary |
|---|---|
| private DiagnosticSource getDiagnosticSource(Element element) Returns the diagnostic source for an element, or
| |
| getDiagnosticSource | back to summary |
|---|---|
| private DiagnosticSource getDiagnosticSource(JavaFileObject fo) Returns the diagnostic source for a file object.
| |
| getDiagnosticType | back to summary |
|---|---|
| private JCDiagnostic. Returns the diagnostic type for a diagnostic kind.
| |
| getDiagnosticWriter | back to summary |
|---|---|
| public PrintWriter getDiagnosticWriter() Overrides default jdk. Doc from jdk. Returns a writer that can be used to write diagnostic output,
or
| |
| getSourcePositions | back to summary |
|---|---|
| private DocSourcePositions getSourcePositions() Returns the object for computing source positions. The value is determined lazily because the tool environment is computed lazily.
| |
| getStandardWriter | back to summary |
|---|---|
| public PrintWriter getStandardWriter() Overrides default jdk. Doc from jdk. Returns a writer that can be used to write non-diagnostic output,
or
| |
| getText | back to summary |
|---|---|
| pack-priv String getText(String key, Object... args) Returns the localized string from the tool's resource bundles. | |
| getToolEnv | back to summary |
|---|---|
| private ToolEnvironment getToolEnv() Returns the tool environment. The value is determined lazily, because creating it eagerly disrupts the overall initialization of objects in the context.
| |
| hasErrors | back to summary |
|---|---|
| public boolean hasErrors() Returns true if errors have been recorded. | |
| hasWarnings | back to summary |
|---|---|
| public boolean hasWarnings() Returns true if warnings have been recorded. | |
| instance0 | back to summary |
|---|---|
| public static JavadocLog instance0(Context context) Get the current javadoc log, which is also the compiler log. | |
| preRegister | back to summary |
|---|---|
| public static void preRegister(Context context, final String programName) | |
| preRegister | back to summary |
|---|---|
| public static void preRegister(Context context, final String programName, final PrintWriter outWriter, final PrintWriter errWriter) | |
| back to summary | |
|---|---|
| public void print(Diagnostic. Implements jdk. Doc from jdk. Prints a diagnostic message.
| |
| back to summary | |
|---|---|
| public void print(Diagnostic. Implements jdk. Doc from jdk. Prints a diagnostic message related to a tree node in a documentation comment.
| |
| back to summary | |
|---|---|
| public void print(Diagnostic. Overrides default jdk. Doc from jdk. Prints a diagnostic message related to a position within a range of characters in a tree node.
Only kinds of
| |
| back to summary | |
|---|---|
| public void print(Diagnostic. Implements jdk. Doc from jdk. Prints a diagnostic message related to an element.
| |
| back to summary | |
|---|---|
| public void print(Diagnostic. Overrides default jdk. Doc from jdk. Prints a diagnostic message related to a position within a range of characters in a file.
The positions are all 0-based character offsets from the beginning of content of the file.
The positions should satisfy the relation
| |
| printCount | back to summary |
|---|---|
| private void printCount(int count, String singleKey, String pluralKey) | |
| printError | back to summary |
|---|---|
| public void printError(String message) Prints an error message.
| |
| printError | back to summary |
|---|---|
| public void printError(DocTreePath path, String message) Prints an error message for a given documentation tree node.
| |
| printError | back to summary |
|---|---|
| public void printError(Element element, String message) Prints an error message for a given element. | |
| printErrorUsingKey | back to summary |
|---|---|
| public void printErrorUsingKey(String key, Object... args) Prints an error message. | |
| printErrorWarningCounts | back to summary |
|---|---|
| public void printErrorWarningCounts() Prints the error and warning counts, if any, to the diagnostic writer. | |
| printNote | back to summary |
|---|---|
| public void printNote(String message) Prints a "notice" message.
| |
| printNoteUsingKey | back to summary |
|---|---|
| public void printNoteUsingKey(String key, Object... args) Prints a "notice" message. | |
| printWarning | back to summary |
|---|---|
| public void printWarning(String message) Prints a warning message.
| |
| printWarning | back to summary |
|---|---|
| public void printWarning(DocTreePath path, String message) Prints a warning message for a given documentation tree node.
| |
| printWarning | back to summary |
|---|---|
| public void printWarning(Element element, String message) Prints a warning message for a given element. | |
| printWarningUsingKey | back to summary |
|---|---|
| public void printWarningUsingKey(String key, Object... args) Prints a warning message. | |
| printWarningUsingKey | back to summary |
|---|---|
| public void printWarningUsingKey(Element element, String key, Object... args) Prints a warning message for an element. | |
| report | back to summary |
|---|---|
| private void report(Diagnostic. Reports a diagnostic message.
| |
| report | back to summary |
|---|---|
| private void report(JCDiagnostic. Reports a diagnostic message.
| |
| report | back to summary |
|---|---|
| private void report(JCDiagnostic. Reports a diagnostic message, with diagnostic flags.
For javadoc, the only flag that is used is Note there is an intentional difference in behavior between the diagnostic source
being set to
| |
| setLocale | back to summary |
|---|---|
| public void setLocale(Locale locale) | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Modifier | getAccessLevel()
Implements javax. Provides a hint about the access level of the class represented by this file object. |
| public JavaFileObject. | |
| public NestingKind | getNestingKind()
Implements javax. Provides a hint about the nesting level of the class represented by this file object. |
| public boolean | isNameCompatible(String simpleName, JavaFileObject.
Implements javax. Checks if this file object is compatible with the specified simple name and kind. |
| WrappingJavaFileObject | back to summary |
|---|---|
| pack-priv WrappingJavaFileObject(FileObject fo) | |
| getAccessLevel | back to summary |
|---|---|
| public Modifier getAccessLevel() Implements javax. Doc from javax. Provides a hint about the access level of the class represented
by this file object. If the access level is not known or
this file object does not represent a class file this method
returns
| |
| getKind | back to summary |
|---|---|
| public JavaFileObject. Implements javax. Doc from javax. Returns the kind of this file object.
| |
| getNestingKind | back to summary |
|---|---|
| public NestingKind getNestingKind() Implements javax. Doc from javax. Provides a hint about the nesting level of the class
represented by this file object. This method may return
| |
| isNameCompatible | back to summary |
|---|---|
| public boolean isNameCompatible(String simpleName, JavaFileObject. Implements javax. Doc from javax. Checks if this file object is compatible with the specified simple name and kind. A simple name is a single identifier (not qualified) as defined in The Java Language Specification, section 6.2.
| |