Class DocTrees
java.lang.Object
com.sun.source.util.Trees
com.sun.source.util.DocTrees
Provides access to syntax trees for doc comments.
- Since:
- 1.8
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract BreakIterator
Returns the break iterator used to compute the first sentence of documentation comments.abstract String
getCharacters
(EntityTree tree) Returns a string containing the characters for the entity in a given entity tree, ornull
if the tree does not represent a valid series of characters.abstract Elements.DocCommentKind
getDocCommentKind
(TreePath path) Returns the style of the documentation comment associated with a tree node.abstract DocCommentTree
getDocCommentTree
(TreePath path) Returns the doc comment tree, if any, for the Tree node identified by a given TreePath.abstract DocCommentTree
Returns the doc comment tree of the given element.abstract DocCommentTree
getDocCommentTree
(Element e, String relativePath) Returns the doc comment tree of the given file, which must be of one of the supported file types, and whose path is specified relative to the given element.abstract DocCommentTree
getDocCommentTree
(FileObject fileObject) Returns the doc comment tree of the given file, which must be of one of the supported file types.abstract DocTreeFactory
Returns a utility object for creatingDocTree
objects.abstract DocTreePath
getDocTreePath
(FileObject fileObject, PackageElement packageElement) Returns a doc tree path containing the doc comment tree of the given file, which must be of one of the supported file types.abstract Element
getElement
(DocTreePath path) Returns the language model element referred to by the leaf node of the givenDocTreePath
, ornull
if unknown.getFirstSentence
(List<? extends DocTree> list) Returns the list ofDocTree
representing the first sentence of a comment.abstract DocSourcePositions
Returns a utility object for accessing the source positions of documentation tree nodes.abstract TypeMirror
getType
(DocTreePath path) Returns the language model type referred to by the leaf node of the givenDocTreePath
, ornull
if unknown.static DocTrees
Returns a DocTrees object for a given ProcessingEnvironment.static DocTrees
Returns a DocTrees object for a given CompilationTask.abstract void
printMessage
(Diagnostic.Kind kind, CharSequence msg, DocTree t, DocCommentTree c, CompilationUnitTree root) Prints a message of the specified kind at the location of the tree within the provided compilation unit.abstract void
setBreakIterator
(BreakIterator breakIterator) Sets the break iterator to compute the first sentence of documentation comments.Methods declared in class Trees
getDocComment, getElement, getLub, getOriginalType, getPath, getPath, getPath, getPath, getScope, getTree, getTree, getTree, getTree, getTree, getTypeMirror, isAccessible, isAccessible, printMessage
Modifier and TypeMethodDescriptionabstract String
getDocComment
(TreePath path) Returns the doc comment, if any, for theTree
node identified by a givenTreePath
.abstract Element
getElement
(TreePath path) Returns theElement
for theTree
node identified by a givenTreePath
.abstract TypeMirror
Returns the lub of an exception parameter declared in a catch clause.abstract TypeMirror
getOriginalType
(ErrorType errorType) Returns the original type from theErrorType
object.abstract TreePath
getPath
(CompilationUnitTree unit, Tree node) Returns the path to tree node within the specified compilation unit.abstract TreePath
Returns theTreePath
node for a givenElement
.abstract TreePath
getPath
(Element e, AnnotationMirror a) Returns theTreePath
node for anAnnotationMirror
on a givenElement
.abstract TreePath
getPath
(Element e, AnnotationMirror a, AnnotationValue v) Returns theTreePath
node for anAnnotationValue
for anAnnotationMirror
on a givenElement
.abstract Scope
Returns theScope
for theTree
node identified by a givenTreePath
.abstract Tree
Returns theTree
node for a givenElement
.abstract Tree
getTree
(Element e, AnnotationMirror a) Returns theTree
node for anAnnotationMirror
on a givenElement
.abstract Tree
getTree
(Element e, AnnotationMirror a, AnnotationValue v) Returns theTree
node for anAnnotationValue
for anAnnotationMirror
on a givenElement
.abstract MethodTree
getTree
(ExecutableElement method) Returns theMethodTree
node for a givenExecutableElement
.abstract ClassTree
getTree
(TypeElement element) Returns theClassTree
node for a givenTypeElement
.abstract TypeMirror
getTypeMirror
(TreePath path) Returns theTypeMirror
for theTree
node identified by a givenTreePath
.abstract boolean
isAccessible
(Scope scope, Element member, DeclaredType type) Checks whether the given element is accessible as a member of the given type in a given scope.abstract boolean
isAccessible
(Scope scope, TypeElement type) Checks whether a given type is accessible in a given scope.abstract void
printMessage
(Diagnostic.Kind kind, CharSequence msg, Tree t, CompilationUnitTree root) Prints a message of the specified kind at the location of the tree within the provided compilation unitMethods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Modifier and TypeMethodDescriptionprotected Object
clone()
Creates and returns a copy of this object.boolean
Indicates whether some other object is "equal to" this one.protected void
finalize()
Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class
<?> getClass()
Returns the runtime class of thisObject
.int
hashCode()
Returns a hash code value for this object.final void
notify()
Wakes up a single thread that is waiting on this object's monitor.final void
Wakes up all threads that are waiting on this object's monitor.toString()
Returns a string representation of the object.final void
wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final void
wait
(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final void
wait
(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Constructor Details
-
DocTrees
public DocTrees()Constructor for subclasses to call.
-
-
Method Details
-
instance
Returns a DocTrees object for a given CompilationTask.- Parameters:
task
- the compilation task for which to get the Trees object- Returns:
- the DocTrees object
- Throws:
IllegalArgumentException
- if the task does not support the Trees API.
-
instance
Returns a DocTrees object for a given ProcessingEnvironment.- Parameters:
env
- the processing environment for which to get the Trees object- Returns:
- the DocTrees object
- Throws:
IllegalArgumentException
- if the env does not support the Trees API.
-
getBreakIterator
Returns the break iterator used to compute the first sentence of documentation comments. Returnsnull
if none has been specified.- Returns:
- the break iterator
- Since:
- 9
-
getDocCommentKind
Returns the style of the documentation comment associated with a tree node.- Parameters:
path
- the path for the tree node- Returns:
- the style of the documentation comment associated with a tree node
- Since:
- 23
- See Also:
-
getDocCommentTree
Returns the doc comment tree, if any, for the Tree node identified by a given TreePath. Returnsnull
if no doc comment was found.- Implementation Note:
- The default implementation of this method returns the same
DocCommentTree
instance for repeated invocations with the same argument. - Parameters:
path
- the path for the tree node- Returns:
- the doc comment tree
-
getDocCommentTree
Returns the doc comment tree of the given element. Returnsnull
if no doc comment was found.- Implementation Note:
- The default implementation of this method returns the same
DocCommentTree
instance for repeated invocations with the same argument. - Parameters:
e
- an element whose documentation is required- Returns:
- the doc comment tree
- Since:
- 9
-
getDocCommentTree
Returns the doc comment tree of the given file, which must be of one of the supported file types.The supported file types are:
- HTML files, identified by a file name ending in
.html
, - Markdown files, identified by a file name ending in
.md
.
- Implementation Note:
- The default implementation of this method returns a
new
DocCommentTree
instance for each invocation. - Parameters:
fileObject
- the content container- Returns:
- the doc comment tree
- Throws:
IllegalArgumentException
- if the file type is not supported- Since:
- 9
- HTML files, identified by a file name ending in
-
getDocCommentTree
Returns the doc comment tree of the given file, which must be of one of the supported file types, and whose path is specified relative to the given element.The supported file types are:
- HTML files, identified by a file name ending in
.html
, - Markdown files, identified by a file name ending in
.md
.
- Implementation Note:
- The default implementation of this method returns a
new
DocCommentTree
instance for each invocation. - Parameters:
e
- an element whose path is used as a referencerelativePath
- the relative path from the Element- Returns:
- the doc comment tree
- Throws:
IOException
- if an exception occursIllegalArgumentException
- if the file type is not supported- Since:
- 9
- HTML files, identified by a file name ending in
-
getDocTreePath
Returns a doc tree path containing the doc comment tree of the given file, which must be of one of the supported file types. Supported file types are HTML files and Markdown files. Future releases may support additional file types. Any references to source code elements contained in@see
and{@link}
tags in the doc comment tree will be evaluated in the context of the given package element. Returnsnull
if no doc comment was found.- Parameters:
fileObject
- a file object encapsulating the HTML contentpackageElement
- a package element to associate with the given file object representing a legacy package.html, null otherwise- Returns:
- a doc tree path containing the doc comment parsed from the given file
- Throws:
IllegalArgumentException
- if the file type is not supported- Since:
- 9
-
getElement
Returns the language model element referred to by the leaf node of the givenDocTreePath
, ornull
if unknown.- Parameters:
path
- the path for the tree node- Returns:
- the element
-
getType
Returns the language model type referred to by the leaf node of the givenDocTreePath
, ornull
if unknown. This method usually returns the same value asgetElement(path).asType()
for apath
argument for whichgetElement(DocTreePath)
returns a non-null value, but may return a type that includes additional information, such as a parameterized generic type instead of a raw type.- Parameters:
path
- the path for the tree node- Returns:
- the referenced type, or null
- Since:
- 15
-
getFirstSentence
-
getSourcePositions
Returns a utility object for accessing the source positions of documentation tree nodes.- Specified by:
getSourcePositions
in classTrees
- Returns:
- the utility object
-
printMessage
public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg, DocTree t, DocCommentTree c, CompilationUnitTree root) Prints a message of the specified kind at the location of the tree within the provided compilation unit.- Parameters:
kind
- the kind of messagemsg
- the message, or an empty string if nonet
- the tree to use as a position hintc
- the doc comment tree to use as a position hintroot
- the compilation unit that contains tree
-
setBreakIterator
Sets the break iterator to compute the first sentence of documentation comments.- Parameters:
breakIterator
- a break iterator ornull
to specify the default sentence breaker- Since:
- 9
-
getDocTreeFactory
Returns a utility object for creatingDocTree
objects.- Returns:
- a utility object for creating
DocTree
objects - Since:
- 9
-
getCharacters
Returns a string containing the characters for the entity in a given entity tree, ornull
if the tree does not represent a valid series of characters.The interpretation of entities is based on section 8.1.4. Character references in the HTML 5.2 specification.
- Parameters:
tree
- the tree containing the entity- Returns:
- a string containing the characters
- Since:
- 16
- External Specifications
-