langtools/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePathScanner.java
author vasya
Mon, 14 Dec 2015 20:18:19 +0100
changeset 34752 9c262a013456
parent 25874 83c19f00452c
child 34916 16043fc1d90b
permissions -rw-r--r--
8145342: Some copyright notices are inconsistently and ill formatted Summary: Adjusted formatting of copyright notices. Reviewed-by: darcy, alundblad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     1
/*
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
     2
 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     4
 *
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    10
 *
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    16
 *
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    20
 *
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    23
 * questions.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    24
 */
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 25874
diff changeset
    25
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    26
package com.sun.source.util;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    27
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    28
import com.sun.source.doctree.DocTree;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    29
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    30
/**
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    31
 * A DocTreeVisitor that visits all the child tree nodes, and provides
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    32
 * support for maintaining a path for the parent nodes.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    33
 * To visit nodes of a particular type, just override the
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    34
 * corresponding visitorXYZ method.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    35
 * Inside your method, call super.visitXYZ to visit descendant
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    36
 * nodes.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    37
 *
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    38
 * @since 1.8
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    39
 */
20612
4761f3ff7afb 8025913: Rename jdk.Supported to jdk.Exported
darcy
parents: 17549
diff changeset
    40
@jdk.Exported
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    41
public class DocTreePathScanner<R, P> extends DocTreeScanner<R, P> {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    42
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    43
     * Scans a tree from a position identified by a tree path.
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    44
     * @param path the path
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    45
     * @param p a value to be passed to visitor methods
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    46
     * @return the result returned from the main visitor method
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    47
     */
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    48
    public R scan(DocTreePath path, P p) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    49
        this.path = path;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    50
        try {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    51
            return path.getLeaf().accept(this, p);
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    52
        } finally {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    53
            this.path = null;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    54
        }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    55
    }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    56
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    57
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    58
     * Scans a single node.
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    59
     * The current path is updated for the duration of the scan.
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    60
     * @param tree the tree to be scanned
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    61
     * @param p a value to be passed to visitor methods
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    62
     * @return the result returned from the main visitor method
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    63
     */
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    64
    @Override
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    65
    public R scan(DocTree tree, P p) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    66
        if (tree == null)
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    67
            return null;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    68
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    69
        DocTreePath prev = path;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    70
        path = new DocTreePath(path, tree);
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    71
        try {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    72
            return tree.accept(this, p);
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    73
        } finally {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    74
            path = prev;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    75
        }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    76
    }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    77
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    78
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    79
     * Returns the current path for the node, as built up by the currently
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    80
     * active set of scan calls.
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    81
     * @return the current path
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    82
     */
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    83
    public DocTreePath getCurrentPath() {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    84
        return path;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    85
    }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    86
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    87
    private DocTreePath path;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    88
}