src/jdk.compiler/share/classes/com/sun/source/util/DocTreeScanner.java

Print this page




  51  * method is such that the result of the visitXYZ method will be the result of
  52  * the last child scanned.
  53  * </ul>
  54  *
  55  * <p>Here is an example to count the number of erroneous nodes in a tree:
  56  * <pre>
  57  *   class CountErrors extends DocTreeScanner&lt;Integer,Void&gt; {
  58  *      {@literal @}Override
  59  *      public Integer visitErroneous(ErroneousTree node, Void p) {
  60  *          return 1;
  61  *      }
  62  *      {@literal @}Override
  63  *      public Integer reduce(Integer r1, Integer r2) {
  64  *          return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
  65  *      }
  66  *   }
  67  * </pre>
  68  *
  69  * @since 1.8
  70  */
  71 @jdk.Exported
  72 public class DocTreeScanner<R,P> implements DocTreeVisitor<R,P> {
  73 
  74     /**
  75      * Scans a single node.
  76      * @param node the node to be scanned
  77      * @param p a parameter value passed to the visit method
  78      * @return the result value from the visit method
  79      */
  80     public R scan(DocTree node, P p) {
  81         return (node == null) ? null : node.accept(this, p);
  82     }
  83 
  84     private R scanAndReduce(DocTree node, P p, R r) {
  85         return reduce(scan(node, p), r);
  86     }
  87 
  88     /**
  89      * Scans a sequence of nodes.
  90      * @param nodes the nodes to be scanned
  91      * @param p a parameter value to be passed to the visit method for each node




  51  * method is such that the result of the visitXYZ method will be the result of
  52  * the last child scanned.
  53  * </ul>
  54  *
  55  * <p>Here is an example to count the number of erroneous nodes in a tree:
  56  * <pre>
  57  *   class CountErrors extends DocTreeScanner&lt;Integer,Void&gt; {
  58  *      {@literal @}Override
  59  *      public Integer visitErroneous(ErroneousTree node, Void p) {
  60  *          return 1;
  61  *      }
  62  *      {@literal @}Override
  63  *      public Integer reduce(Integer r1, Integer r2) {
  64  *          return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
  65  *      }
  66  *   }
  67  * </pre>
  68  *
  69  * @since 1.8
  70  */

  71 public class DocTreeScanner<R,P> implements DocTreeVisitor<R,P> {
  72 
  73     /**
  74      * Scans a single node.
  75      * @param node the node to be scanned
  76      * @param p a parameter value passed to the visit method
  77      * @return the result value from the visit method
  78      */
  79     public R scan(DocTree node, P p) {
  80         return (node == null) ? null : node.accept(this, p);
  81     }
  82 
  83     private R scanAndReduce(DocTree node, P p, R r) {
  84         return reduce(scan(node, p), r);
  85     }
  86 
  87     /**
  88      * Scans a sequence of nodes.
  89      * @param nodes the nodes to be scanned
  90      * @param p a parameter value to be passed to the visit method for each node