APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.javadoc.internal.tool

public Class JavadocLog

extends Log
implements Reporter
Class Inheritance
All Implemented Interfaces
jdk.javadoc.doclet.Reporter
Imports
java.io.PrintStream, .PrintWriter, java.lang.ref.Reference, .SoftReference, java.util.EnumSet, .LinkedHashMap, .Locale, .Map, .ResourceBundle, .Set, javax.lang.model.element.Element, .Modifier, .NestingKind, javax.tools.Diagnostic, .Diagnostic.Kind, .FileObject, .ForwardingFileObject, .JavaFileObject, jdk.javadoc.doclet.Reporter, com.sun.source.doctree.CommentTree, .DocTree, .DocTypeTree, .ReferenceTree, .TextTree, com.sun.tools.javac.tree.DCTree.DCDocComment, .DCTree, .JCTree, com.sun.tools.javac.util.Context.Factory, .DiagnosticSource, .Context, .JCDiagnostic, .JCDiagnostic.DiagnosticFlag, .JCDiagnostic.DiagnosticPosition, .JCDiagnostic.DiagnosticType, .JavacMessages, .Log, com.sun.source.tree.CompilationUnitTree, com.sun.source.util.DocSourcePositions, .DocTreePath, .TreePath

Class for reporting diagnostics and other messages. The class leverages the javac support for reporting diagnostics, for stylistic consistency of diagnostic messages and to avoid code duplication. The class is a subtype of javac's Log, and is primarily an adapter between javadoc method signatures and the underlying javac methods. Within this class, the methods call down to a core 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: The javadoc layer is defined by the methods on Doclet.Reporter, and by assorted methods defined in this class for use by the javadoc tool. The primary data types are: The reporting methods in the javac layer primarily take pre-localized (key, args) pairs, while the methods in the javadoc layer, especially the 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.
See Also
java.util.ResourceBundle, java.text.MessageFormat

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final Context
context

Hides com.sun.tools.javac.util.Log.context.

The overall context for the documentation run.
private final LinkedHashMap<JavaFileObject, SoftReference<DiagnosticSource>>
diagSourceCache

A memory-sensitive cache of recently used DiagnosticSource objects.

private final JCDiagnostic.Factory
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.

Inherited from com.sun.tools.javac.util.Log:
compressedOutputdiagListenerdumpOnErroremitWarningserrKeyexpectDiagKeyslintWarningslogKeyMaxErrorsMaxWarningsnerrorsnonLintWarningsnsuppressederrorsnsuppressedwarnsnwarningsoutKeypromptOnErrorrecordedrecordedSourceLevelErrorssuppressNotes

Constructor Summary

AccessConstructor and Description
public
JavadocLog(Context context, String
Name of the program (for error messages).
programName
)

Constructor

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

Method Summary

Modifier and TypeMethod and Description
private JCDiagnostic.DiagnosticPosition

Returns:

the diagnostic position
createDiagnosticPosition
(JCTree
the 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
createPrintWriter(PrintStream ps, boolean autoflush)

private Set<JCDiagnostic.DiagnosticFlag>

Returns:

the flags
getDiagnosticFlags
(Diagnostic.Kind
the diagnostic kind
kind
)

Returns the diagnostic flags for a diagnostic kind.

private JCDiagnostic.DiagnosticPosition

Returns:

the diagnostic position
getDiagnosticPosition
(DocTreePath
the path for the documentation tree node
path
)

Returns a diagnostic position for a documentation tree node.

private JCDiagnostic.DiagnosticPosition

Returns:

the diagnostic position
getDiagnosticPosition
(Element
the element
element
)

Returns a diagnostic position for an element, or null if the source file is not available.

private DiagnosticSource

Returns:

the diagnostic source
getDiagnosticSource
(DocTreePath
the path for the documentation tree node
path
)

Returns the diagnostic source for a documentation tree node.

private DiagnosticSource

Returns:

the diagnostic source
getDiagnosticSource
(Element
the element
element
)

Returns the diagnostic source for an element, or NO_SOURCE if the source file is not known (for example, if the element was read from a class file).

private DiagnosticSource

Returns:

the diagnostic source
getDiagnosticSource
(JavaFileObject
the file object
fo
)

Returns the diagnostic source for a file object.

private JCDiagnostic.DiagnosticType

Returns:

the diagnostic type
getDiagnosticType
(Diagnostic.Kind
the diagnostic kind
kind
)

Returns the diagnostic type for a diagnostic kind.

public PrintWriter
getDiagnosticWriter()

Overrides default jdk.javadoc.doclet.Reporter.getDiagnosticWriter.

Returns a writer that can be used to write diagnostic output, or null if no such writer is available.

private DocSourcePositions

Returns:

the object for computing source positions
getSourcePositions
()

Returns the object for computing source positions.

public PrintWriter
getStandardWriter()

Overrides default jdk.javadoc.doclet.Reporter.getStandardWriter.

Returns a writer that can be used to write non-diagnostic output, or null if no such writer is available.

pack-priv String
getText(String
the resource key
key
,
Object...
arguments for the resource
args
)

Returns the localized string from the tool's resource bundles.

private ToolEnvironment

Returns:

the tool environment
getToolEnv
()

Returns the tool environment.

public boolean
hasErrors()

Returns true if errors have been recorded.

public boolean
hasWarnings()

Returns true if warnings have been recorded.

public static JavadocLog
instance0(Context context)

Get the current javadoc log, which is also the compiler log.

public static void
preRegister(Context context, final String programName)

public static void
preRegister(Context context, final String programName, final PrintWriter outWriter, final PrintWriter errWriter)

private void
printCount(int count, String singleKey, String pluralKey)

public void
printError(String
the message
message
)

Prints an error message.

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
printErrorWarningCounts()

Prints the error and warning counts, if any, to the diagnostic writer.

public void
printNote(String
the message
message
)

Prints a "notice" message.

public void
printNoteUsingKey(String
the resource key for the message
key
,
Object...
the arguments for the message
args
)

Prints a "notice" message.

public void
printWarning(String
the message
message
)

Prints a warning message.

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.Kind
the kind of diagnostic
kind
,
DiagnosticSource
the diagnostic source
ds
,
JCDiagnostic.DiagnosticPosition
the diagnostic position
dp
,
String
the message
message
)

Reports a diagnostic message.

private void
report(JCDiagnostic.DiagnosticType
the diagnostic type
dt
,
DiagnosticSource
the diagnostic source
ds
,
JCDiagnostic.DiagnosticPosition
the diagnostic position
dp
,
String
the message
message
)

Reports a diagnostic message.

private void
report(JCDiagnostic.DiagnosticType
the diagnostic type
dt
,
Set<JCDiagnostic.DiagnosticFlag> flags, DiagnosticSource
the diagnostic source
ds
,
JCDiagnostic.DiagnosticPosition
the diagnostic position
dp
,
String
the message
message
)

Reports a diagnostic message, with diagnostic flags.

public void
setLocale(Locale locale)

Inherited from com.sun.tools.javac.util.Log:
clearcurrentSourceFiledirectErrorflushflushformatgetDefaultMaxErrorsgetDefaultMaxWarningsgetDiagnosticFormattergetLocalizedStringgetWritergetWriterForDiagnosticTypehasDiagnosticListenerhasErrorOninstancelocalizelocalizelocalizepopDiagnosticHandlerpreRegisterprintLinesprintLinesprintLinesprintLinesprintLinesprintNewlineprintNewlineprintRawLinesprintRawLinesprintRawLinesprintVerbosepromptrawErrorrawWarningreportreportOutstandingNotesreportOutstandingWarningssetDiagnosticFormattersetWritersetWritersshouldReportsuppressAggregatedWarningNoteswriteDiagnostic

Field Detail

contextback to summary
private final Context context

Hides com.sun.tools.javac.util.Log.context.

The overall context for the documentation run.

diagSourceCacheback to summary
private final LinkedHashMap<JavaFileObject, SoftReference<DiagnosticSource>> diagSourceCache

A memory-sensitive cache of recently used DiagnosticSource objects.

javadocDiagsback to summary
private final JCDiagnostic.Factory javadocDiags
localeback to summary
private Locale locale
messagesback to summary
private final JavacMessages messages

Hides com.sun.tools.javac.util.Log.messages.

programNameback to summary
pack-priv final String programName
sourcePositionsback to summary
private DocSourcePositions sourcePositions

The utility class to access the positions of items in doc comments.

toolEnvback to summary
private ToolEnvironment toolEnv

The tool environment, providing access to the tool's utility classes and tables.

Constructor Detail

JavadocLogback to summary
public JavadocLog(Context context, String programName)

Constructor

Parameters
programName:String

Name of the program (for error messages).

JavadocLogback to summary
public JavadocLog(Context context, String programName, PrintWriter outWriter, PrintWriter errWriter)

Constructor

Parameters
programName:String

Name of the program (for error messages).

outWriter:PrintWriter

Stream for notices etc.

errWriter:PrintWriter

Stream for errors and warnings

Method Detail

createDiagnosticPositionback to summary
private JCDiagnostic.DiagnosticPosition createDiagnosticPosition(JCTree tree, int start, int pos, int end)

Creates a diagnostic position.

Parameters
tree:JCTree

the tree node, or null if no tree is applicable

start:int

the start position

pos:int

the "preferred" position: this is used to position the caret in messages

end:int

the end position

Returns:JCDiagnostic.DiagnosticPosition

the diagnostic position

createPrintWriterback to summary
private static PrintWriter createPrintWriter(PrintStream ps, boolean autoflush)
getDiagnosticFlagsback to summary
private Set<JCDiagnostic.DiagnosticFlag> getDiagnosticFlags(Diagnostic.Kind kind)

Returns the diagnostic flags for a diagnostic kind. A diagnostic kind of MANDATORY_WARNING requires the MANDATORY flag.

Parameters
kind:Diagnostic.Kind

the diagnostic kind

Returns:Set<JCDiagnostic.DiagnosticFlag>

the flags

getDiagnosticPositionback to summary
private JCDiagnostic.DiagnosticPosition getDiagnosticPosition(DocTreePath path)

Returns a diagnostic position for a documentation tree node.

Parameters
path:DocTreePath

the path for the documentation tree node

Returns:JCDiagnostic.DiagnosticPosition

the diagnostic position

getDiagnosticPositionback to summary
private JCDiagnostic.DiagnosticPosition getDiagnosticPosition(Element element)

Returns a diagnostic position for an element, or null if the source file is not available.

Parameters
element:Element

the element

Returns:JCDiagnostic.DiagnosticPosition

the diagnostic position

getDiagnosticSourceback to summary
private DiagnosticSource getDiagnosticSource(DocTreePath path)

Returns the diagnostic source for a documentation tree node.

Parameters
path:DocTreePath

the path for the documentation tree node

Returns:DiagnosticSource

the diagnostic source

getDiagnosticSourceback to summary
private DiagnosticSource getDiagnosticSource(Element element)

Returns the diagnostic source for an element, or NO_SOURCE if the source file is not known (for example, if the element was read from a class file).

Parameters
element:Element

the element

Returns:DiagnosticSource

the diagnostic source

getDiagnosticSourceback to summary
private DiagnosticSource getDiagnosticSource(JavaFileObject fo)

Returns the diagnostic source for a file object. DiagnosticSource objects are moderately expensive because they maintain an internal copy of the content, to provide the line map. Therefore, we keep a small memory-sensitive cache of recently used objects.

Parameters
fo:JavaFileObject

the file object

Returns:DiagnosticSource

the diagnostic source

getDiagnosticTypeback to summary
private JCDiagnostic.DiagnosticType getDiagnosticType(Diagnostic.Kind kind)

Returns the diagnostic type for a diagnostic kind.

Parameters
kind:Diagnostic.Kind

the diagnostic kind

Returns:JCDiagnostic.DiagnosticType

the diagnostic type

getDiagnosticWriterback to summary
public PrintWriter getDiagnosticWriter()

Overrides default jdk.javadoc.doclet.Reporter.getDiagnosticWriter.

Doc from jdk.javadoc.doclet.Reporter.getDiagnosticWriter.

Returns a writer that can be used to write diagnostic output, or null if no such writer is available.

Annotations
@Override
getSourcePositionsback to summary
private DocSourcePositions getSourcePositions()

Returns the object for computing source positions. The value is determined lazily because the tool environment is computed lazily.

Returns:DocSourcePositions

the object for computing source positions

getStandardWriterback to summary
public PrintWriter getStandardWriter()

Overrides default jdk.javadoc.doclet.Reporter.getStandardWriter.

Doc from jdk.javadoc.doclet.Reporter.getStandardWriter.

Returns a writer that can be used to write non-diagnostic output, or null if no such writer is available.

Annotations
@Override
getTextback to summary
pack-priv String getText(String key, Object... args)

Returns the localized string from the tool's resource bundles.

Parameters
key:String

the resource key

args:Object[]

arguments for the resource

getToolEnvback 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.

Returns:ToolEnvironment

the tool environment

hasErrorsback to summary
public boolean hasErrors()

Returns true if errors have been recorded.

hasWarningsback to summary
public boolean hasWarnings()

Returns true if warnings have been recorded.

instance0back to summary
public static JavadocLog instance0(Context context)

Get the current javadoc log, which is also the compiler log.

preRegisterback to summary
public static void preRegister(Context context, final String programName)
preRegisterback to summary
public static void preRegister(Context context, final String programName, final PrintWriter outWriter, final PrintWriter errWriter)
printCountback to summary
private void printCount(int count, String singleKey, String pluralKey)
printErrorback to summary
public void printError(String message)

Prints an error message.

Parameters
message:String

the message

printErrorback to summary
public void printError(DocTreePath path, String message)

Prints an error message for a given documentation tree node.

Parameters
path:DocTreePath

the path for the documentation tree node

message:String

the message

printErrorback to summary
public void printError(Element element, String message)

Prints an error message for a given element.

Parameters
element:Element

the element

message:String

the message

printErrorUsingKeyback to summary
public void printErrorUsingKey(String key, Object... args)

Prints an error message.

Parameters
key:String

the resource key for the message

args:Object[]

the arguments for the message

printErrorWarningCountsback to summary
public void printErrorWarningCounts()

Prints the error and warning counts, if any, to the diagnostic writer.

printNoteback to summary
public void printNote(String message)

Prints a "notice" message.

Parameters
message:String

the message

printNoteUsingKeyback to summary
public void printNoteUsingKey(String key, Object... args)

Prints a "notice" message.

Parameters
key:String

the resource key for the message

args:Object[]

the arguments for the message

printWarningback to summary
public void printWarning(String message)

Prints a warning message.

Parameters
message:String

the message

printWarningback to summary
public void printWarning(DocTreePath path, String message)

Prints a warning message for a given documentation tree node.

Parameters
path:DocTreePath

the path for the documentation tree node

message:String

the message

printWarningback to summary
public void printWarning(Element element, String message)

Prints a warning message for a given element.

Parameters
element:Element

the element

message:String

the message

printWarningUsingKeyback to summary
public void printWarningUsingKey(String key, Object... args)

Prints a warning message.

Parameters
key:String

the resource key for the message

args:Object[]

the arguments for the message

printWarningUsingKeyback to summary
public void printWarningUsingKey(Element element, String key, Object... args)

Prints a warning message for an element.

Parameters
element:Element

the element

key:String

the resource key for the message

args:Object[]

the arguments for the message

reportback to summary
private void report(Diagnostic.Kind kind, DiagnosticSource ds, JCDiagnostic.DiagnosticPosition dp, String message)

Reports a diagnostic message.

Parameters
kind:Diagnostic.Kind

the kind of diagnostic

ds:DiagnosticSource

the diagnostic source

dp:JCDiagnostic.DiagnosticPosition

the diagnostic position

message:String

the message

reportback to summary
private void report(JCDiagnostic.DiagnosticType dt, DiagnosticSource ds, JCDiagnostic.DiagnosticPosition dp, String message)

Reports a diagnostic message.

Parameters
dt:JCDiagnostic.DiagnosticType

the diagnostic type

ds:DiagnosticSource

the diagnostic source

dp:JCDiagnostic.DiagnosticPosition

the diagnostic position

message:String

the message

reportback to summary
private void report(JCDiagnostic.DiagnosticType dt, Set<JCDiagnostic.DiagnosticFlag> flags, DiagnosticSource ds, JCDiagnostic.DiagnosticPosition dp, String message)

Reports a diagnostic message, with diagnostic flags. For javadoc, the only flag that is used is MANDATORY_WARNING, and only because in principle the public API supports it via Kind.MANDATORY_WARNING. javadoc itself does generate mandatory warnings. This is the primary low-level wrapper around the underlying Log.report. Because we already have a localized message, we use wrapper resources (just {0}) to wrap the string. The current behavior is one wrapper per diagnostic type. We could improve this by subtyping DiagnosticInfo to modify the resource key used. Log reports all diagnostics to the corresponding writer, which defaults to the "error" stream, when using the two-stream constructor. That doesn't work for javadoc, which has historically written notes to the "output" stream, because the public API used by doclets does not provide for more detailed control. Therefore, for now, javadoc continues to use the (deprecated) three-stream constructor, with the NOTE stream set to the "output" stream. Log reports all notes with a "Note:" prefix. That's not good for the standard doclet, which uses notes to report the various "progress" messages, such as "Generating class ...". They can be written directly to the diagnostic writer, but that bypasses low-level checks about whether to suppress notes, and bypasses the diagnostic listener for API clients. Overall, it's an over-constrained problem with no obvious good solution.

Note

there is an intentional difference in behavior between the diagnostic source being set to null (no source intended) and NO_SOURCE (no source available).

Parameters
dt:JCDiagnostic.DiagnosticType

the diagnostic type

ds:DiagnosticSource

the diagnostic source

dp:JCDiagnostic.DiagnosticPosition

the diagnostic position

message:String

the message

setLocaleback to summary
public void setLocale(Locale locale)
jdk.javadoc.internal.tool back to summary

private Class JavadocLog.WrappingJavaFileObject

extends ForwardingFileObject<FileObject>
implements JavaFileObject
Class Inheritance
All Implemented Interfaces
javax.tools.JavaFileObject, javax.tools.FileObject

Field Summary

Inherited from javax.tools.ForwardingFileObject:
fileObject

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Modifier
getAccessLevel()

Implements javax.tools.JavaFileObject.getAccessLevel.

Provides a hint about the access level of the class represented by this file object.

public JavaFileObject.Kind
getKind()

Implements javax.tools.JavaFileObject.getKind.

Returns the kind of this file object.

public NestingKind
getNestingKind()

Implements javax.tools.JavaFileObject.getNestingKind.

Provides a hint about the nesting level of the class represented by this file object.

public boolean
isNameCompatible(String simpleName, JavaFileObject.Kind kind)

Implements javax.tools.JavaFileObject.isNameCompatible.

Checks if this file object is compatible with the specified simple name and kind.

Inherited from javax.tools.ForwardingFileObject:
deletegetCharContentgetLastModifiedgetNameopenInputStreamopenOutputStreamopenReaderopenWritertoUri

Constructor Detail

WrappingJavaFileObjectback to summary
pack-priv WrappingJavaFileObject(FileObject fo)

Method Detail

getAccessLevelback to summary
public Modifier getAccessLevel()

Implements javax.tools.JavaFileObject.getAccessLevel.

Doc from javax.tools.JavaFileObject.getAccessLevel.

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 null.

Annotations
@Override
getKindback to summary
public JavaFileObject.Kind getKind()

Implements javax.tools.JavaFileObject.getKind.

Doc from javax.tools.JavaFileObject.getKind.

Returns the kind of this file object.

Annotations
@Override
getNestingKindback to summary
public NestingKind getNestingKind()

Implements javax.tools.JavaFileObject.getNestingKind.

Doc from javax.tools.JavaFileObject.getNestingKind.

Provides a hint about the nesting level of the class represented by this file object. This method may return NestingKind#MEMBER to mean NestingKind#LOCAL or NestingKind#ANONYMOUS. If the nesting level is not known or this file object does not represent a class file this method returns null.

Annotations
@Override
isNameCompatibleback to summary
public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind)

Implements javax.tools.JavaFileObject.isNameCompatible.

Doc from javax.tools.JavaFileObject.isNameCompatible.

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.

Annotations
@Override