Module jdk.compiler

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.

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 on 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 each child in turn, and then combining the result of each scan after the first with the cumulative result so far, as determined by the reduce(R, R) method. Each child may be either a simple node of a list of nodes. The default behavior of the reduce method is such that the result of the visitXYZ method will be the result of the last child scanned.

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);
      }
   }
 

Since:
1.8
  • 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. This implementation scans the children in left to right order.
      Specified by:
      visitAttribute in interface DocTreeVisitor<R,​P>
      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. This implementation scans the children in left to right order.
      Specified by:
      visitAuthor in interface DocTreeVisitor<R,​P>
      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. This implementation returns null.
      Specified by:
      visitComment in interface DocTreeVisitor<R,​P>
      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. This implementation scans the children in left to right order.
      Specified by:
      visitDeprecated in interface DocTreeVisitor<R,​P>
      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. This implementation scans the children in left to right order.
      Specified by:
      visitDocComment in interface DocTreeVisitor<R,​P>
      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. This implementation returns null.
      Specified by:
      visitDocRoot in interface DocTreeVisitor<R,​P>
      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. This implementation returns null.
      Specified by: