Class DocTreeScanner<R,P>
java.lang.Object
com.sun.source.util.DocTreeScanner<R,P>
- All Implemented Interfaces:
DocTreeVisitor<R,
P>
- Direct Known Subclasses:
DocTreePathScanner
public class DocTreeScanner<R,P> extends Object implements DocTreeVisitor<R,P>
A DocTreeVisitor that visits all the child tree nodes. To visit nodes of a particular type, just override the corresponding visitXYZ method. Inside your method, call super.visitXYZ to visit descendant nodes.
Here is an example to count the number of erroneous nodes in a tree:
class CountErrors extends DocTreeScanner<Integer,Void> { @Override public Integer visitErroneous(ErroneousTree node, Void p) { return 1; } @Override public Integer reduce(Integer r1, Integer r2) { return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2); } }
- Implementation Requirements:
-
The default implementation of the visitXYZ methods will determine a result as follows:
- If the node being visited has no children, the result will be
null
. - If the node being visited has one child, the result will be the result of calling
scan
with that child. The child may be a simple node or itself a list of nodes. - If the node being visited has more than one child, the result will be determined by calling
scan
with each child in turn, and then combining the result of each scan after the first with the cumulative result so far, as determined by thereduce(R, R)
method. Each child may be either a simple node or a list of nodes. The default behavior of thereduce
method is such that the result of the visitXYZ method will be the result of the last child scanned.
- If the node being visited has no children, the result will be
- Since:
- 1.8
Constructor Summary
Constructor | Description |
---|---|
DocTreeScanner() |
Constructs a DocTreeScanner . |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
R |
reduce |
Reduces two results into a combined result. |
R |
scan |
Scans a single node. |
R |
scan |
Scans a sequence of nodes. |
R |
visitAttribute |
Visits an AttributeTree node. |
R |
visitAuthor |
Visits an AuthorTree node. |
R |
visitComment |
Visits a CommentTree node. |
R |
visitDeprecated |
Visits a DeprecatedTree node. |
R |
visitDocComment |
Visits a DocCommentTree node. |
R |
visitDocRoot |
Visits a DocRootTree node. |
R |
visitDocType |
Visits a DocTypeTree node. |
R |
visitEndElement |
Visits an EndElementTree node. |
R |
visitEntity |
Visits an EntityTree node. |
R |
visitErroneous |
Visits an ErroneousTree node. |
R |
visitHidden |
Visits a HiddenTree node. |
R |
visitIdentifier |
Visits an IdentifierTree node. |
R |
visitIndex |
Visits an IndexTree node. |
R |
visitInheritDoc |
Visits an InheritDocTree node. |
R |
visitLink |
Visits a LinkTree node. |
R |
visitLiteral |
Visits an LiteralTree node. |
R |
visitOther |
Visits an unknown type of DocTree node. |
R |
visitParam |
Visits a ParamTree node. |
R |
visitProvides |
Visits a ProvidesTree node. |
R |
visitReference |
Visits a ReferenceTree node. |
R |
visitReturn |
Visits a ReturnTree node. |
R |
visitSee |
Visits a SeeTree node. |
R |
visitSerial |
Visits a SerialTree node. |
R |
visitSerialData |
Visits a SerialDataTree node. |
R |
visitSerialField |
Visits a SerialFieldTree node. |
R |
visitSince |
Visits a SinceTree node. |
R |
visitStartElement |
Visits a StartElementTree node. |
R |
visitSummary |
Visits a SummaryTree node. |
R |
visitSystemProperty |
Visits a SystemPropertyTree node. |
R |
visitText |
Visits a TextTree node. |
R |
visitThrows |
Visits a ThrowsTree node. |
R |
visitUnknownBlockTag |
Visits an UnknownBlockTagTree node. |
R |
visitUnknownInlineTag |
Visits an UnknownInlineTagTree node. |
R |
visitUses |
Visits a UsesTree node. |
R |
visitValue |
Visits a ValueTree node. |
R |
visitVersion |
Visits a VersionTree node. |
Constructor Details
DocTreeScanner
public DocTreeScanner()
Constructs a
DocTreeScanner
.Method Details
scan
public R scan(DocTree node, P p)
Scans a single node.
- Parameters:
-
node
- the node to be scanned -
p
- a parameter value passed to the visit method - Returns:
- the result value from the visit method
scan
public R scan(Iterable<? extends DocTree> nodes, P p)
Scans a sequence of nodes.
- Parameters:
-
nodes
- the nodes to be scanned -
p
- a parameter value to be passed to the visit method for each node - Returns:
- the combined return value from the visit methods. The values are combined using the
reduce
method.
reduce
public R reduce(R r1, R r2)
Reduces two results into a combined result. The default implementation is to return the first parameter. The general contract of the method is that it may take any action whatsoever.
- Parameters:
-
r1
- the first of the values to be combined -
r2
- the second of the values to be combined - Returns:
- the result of combining the two parameters
visitAttribute
public R visitAttribute(AttributeTree node, P p)
Visits an AttributeTree node.
- Specified by:
-
visitAttribute
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitAuthor
public R visitAuthor(AuthorTree node, P p)
Visits an AuthorTree node.
- Specified by:
-
visitAuthor
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitComment
public R visitComment(CommentTree node, P p)
Visits a CommentTree node.
- Specified by:
-
visitComment
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitDeprecated
public R visitDeprecated(DeprecatedTree node, P p)
Visits a DeprecatedTree node.
- Specified by:
-
visitDeprecated
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitDocComment
public R visitDocComment(DocCommentTree node, P p)
Visits a DocCommentTree node.
- Specified by:
-
visitDocComment
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitDocRoot
public R visitDocRoot(DocRootTree node, P p)
Visits a DocRootTree node.
- Specified by:
-
visitDocRoot
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitDocType
public R visitDocType(DocTypeTree node, P p)
Visits a DocTypeTree node.
- Specified by:
-
visitDocType
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitEndElement
public R visitEndElement(EndElementTree node, P p)
Visits an EndElementTree node.
- Specified by:
-
visitEndElement
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitEntity
public R visitEntity(EntityTree node, P p)
Visits an EntityTree node.
- Specified by:
-
visitEntity
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitErroneous
public R visitErroneous(ErroneousTree node, P p)
Visits an ErroneousTree node.
- Specified by:
-
visitErroneous
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitHidden
public R visitHidden(HiddenTree node, P p)
Visits a HiddenTree node.
- Specified by:
-
visitHidden
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitIdentifier
public R visitIdentifier(IdentifierTree node, P p)
Visits an IdentifierTree node.
- Specified by:
-
visitIdentifier
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitIndex
public R visitIndex(IndexTree node, P p)
Visits an IndexTree node.
- Specified by:
-
visitIndex
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitInheritDoc
public R visitInheritDoc(InheritDocTree node, P p)
Visits an InheritDocTree node.
- Specified by:
-
visitInheritDoc
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitLink
public R visitLink(LinkTree node, P p)
Visits a LinkTree node.
- Specified by:
-
visitLink
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitLiteral
public R visitLiteral(LiteralTree node, P p)
Visits an LiteralTree node.
- Specified by:
-
visitLiteral
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitParam
public R visitParam(ParamTree node, P p)
Visits a ParamTree node.
- Specified by:
-
visitParam
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitProvides
public R visitProvides(ProvidesTree node, P p)
Visits a ProvidesTree node.
- Specified by:
-
visitProvides
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitReference
public R visitReference(ReferenceTree node, P p)
Visits a ReferenceTree node.
- Specified by:
-
visitReference
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitReturn
public R visitReturn(ReturnTree node, P p)
Visits a ReturnTree node.
- Specified by:
-
visitReturn
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitSee
public R visitSee(SeeTree node, P p)
Visits a SeeTree node.
- Specified by:
-
visitSee
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitSerial
public R visitSerial(SerialTree node, P p)
Visits a SerialTree node.
- Specified by:
-
visitSerial
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitSerialData
public R visitSerialData(SerialDataTree node, P p)
Visits a SerialDataTree node.
- Specified by:
-
visitSerialData
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitSerialField
public R visitSerialField(SerialFieldTree node, P p)
Visits a SerialFieldTree node.
- Specified by:
-
visitSerialField
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitSince
public R visitSince(SinceTree node, P p)
Visits a SinceTree node.
- Specified by:
-
visitSince
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitStartElement
public R visitStartElement(StartElementTree node, P p)
Visits a StartElementTree node.
- Specified by:
-
visitStartElement
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitSummary
public R visitSummary(SummaryTree node, P p)
Visits a SummaryTree node.
- Specified by:
-
visitSummary
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
- Since:
- 10
visitSystemProperty
public R visitSystemProperty(SystemPropertyTree node, P p)
Visits a SystemPropertyTree node.
- Specified by:
-
visitSystemProperty
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
- Since:
- 12
visitText
public R visitText(TextTree node, P p)
Visits a TextTree node.
- Specified by:
-
visitText
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitThrows
public R visitThrows(ThrowsTree node, P p)
Visits a ThrowsTree node.
- Specified by:
-
visitThrows
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitUnknownBlockTag
public R visitUnknownBlockTag(UnknownBlockTagTree node, P p)
Visits an UnknownBlockTagTree node.
- Specified by:
-
visitUnknownBlockTag
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitUnknownInlineTag
public R visitUnknownInlineTag(UnknownInlineTagTree node, P p)
Visits an UnknownInlineTagTree node.
- Specified by:
-
visitUnknownInlineTag
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitUses
public R visitUses(UsesTree node, P p)
Visits a UsesTree node.
- Specified by:
-
visitUses
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitValue
public R visitValue(ValueTree node, P p)
Visits a ValueTree node.
- Specified by:
-
visitValue
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitVersion
public R visitVersion(VersionTree node, P p)
Visits a VersionTree node.
- Specified by:
-
visitVersion
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation scans the children in left to right order.
- Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
visitOther
public R visitOther(DocTree node, P p)
Visits an unknown type of DocTree node. This can occur if the set of tags evolves and new kinds of nodes are added to the
DocTree
hierarchy.- Specified by:
-
visitOther
in interfaceDocTreeVisitor<R,
P> - Implementation Requirements:
- This implementation returns
null
. - Parameters:
-
node
- the node being visited -
p
- a parameter value - Returns:
- the result of scanning
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/jdk.compiler/com/sun/source/util/DocTreeScanner.html