langtools/src/share/classes/com/sun/source/util/DocTreePathScanner.java
author darcy
Fri, 04 Oct 2013 10:00:28 -0700
changeset 20612 4761f3ff7afb
parent 17549 65ea6f3b72d9
child 25287 d2440361b323
permissions -rw-r--r--
8025913: Rename jdk.Supported to jdk.Exported Reviewed-by: psandoz, forax, lancea, alanb, mchung, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     1
/*
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
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
 */
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    25
package com.sun.source.util;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    26
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    27
import com.sun.source.doctree.DocTree;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    28
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
 * A DocTreeVisitor that visits all the child tree nodes, and provides
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    31
 * support for maintaining a path for the parent nodes.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    32
 * To visit nodes of a particular type, just override the
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    33
 * corresponding visitorXYZ method.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    34
 * Inside your method, call super.visitXYZ to visit descendant
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    35
 * nodes.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    36
 *
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    37
 * @since 1.8
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    38
 */
20612
4761f3ff7afb 8025913: Rename jdk.Supported to jdk.Exported
darcy
parents: 17549
diff changeset
    39
@jdk.Exported
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    40
public class DocTreePathScanner<R, P> extends DocTreeScanner<R, P> {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    41
    /**
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    42
     * Scan a tree from a position identified by a TreePath.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    43
     */
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    44
    public R scan(DocTreePath path, P p) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    45
        this.path = path;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    46
        try {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    47
            return path.getLeaf().accept(this, p);
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    48
        } finally {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    49
            this.path = null;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    50
        }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    51
    }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    52
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    53
    /**
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    54
     * Scan a single node.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    55
     * The current path is updated for the duration of the scan.
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
    @Override
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    58
    public R scan(DocTree tree, P p) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    59
        if (tree == null)
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    60
            return null;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    61
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    62
        DocTreePath prev = path;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    63
        path = new DocTreePath(path, tree);
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    64
        try {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    65
            return tree.accept(this, p);
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    66
        } finally {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    67
            path = prev;
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
    }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    70
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    71
    /**
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    72
     * Get the current path for the node, as built up by the currently
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    73
     * active set of scan calls.
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    74
     */
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    75
    public DocTreePath getCurrentPath() {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    76
        return path;
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
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    79
    private DocTreePath path;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
diff changeset
    80
}