Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/com/sun/source/util/DocTreePathScanner.java
38899 views
/*1* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package com.sun.source.util;2526import com.sun.source.doctree.DocTree;2728/**29* A DocTreeVisitor that visits all the child tree nodes, and provides30* support for maintaining a path for the parent nodes.31* To visit nodes of a particular type, just override the32* corresponding visitorXYZ method.33* Inside your method, call super.visitXYZ to visit descendant34* nodes.35*36* @since 1.837*/38@jdk.Exported39public class DocTreePathScanner<R, P> extends DocTreeScanner<R, P> {40/**41* Scan a tree from a position identified by a TreePath.42*/43public R scan(DocTreePath path, P p) {44this.path = path;45try {46return path.getLeaf().accept(this, p);47} finally {48this.path = null;49}50}5152/**53* Scan a single node.54* The current path is updated for the duration of the scan.55*/56@Override57public R scan(DocTree tree, P p) {58if (tree == null)59return null;6061DocTreePath prev = path;62path = new DocTreePath(path, tree);63try {64return tree.accept(this, p);65} finally {66path = prev;67}68}6970/**71* Get the current path for the node, as built up by the currently72* active set of scan calls.73*/74public DocTreePath getCurrentPath() {75return path;76}7778private DocTreePath path;79}808182