Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/com/sun/source/util/DocTreePathScanner.java
38899 views
1
/*
2
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
package com.sun.source.util;
26
27
import com.sun.source.doctree.DocTree;
28
29
/**
30
* A DocTreeVisitor that visits all the child tree nodes, and provides
31
* support for maintaining a path for the parent nodes.
32
* To visit nodes of a particular type, just override the
33
* corresponding visitorXYZ method.
34
* Inside your method, call super.visitXYZ to visit descendant
35
* nodes.
36
*
37
* @since 1.8
38
*/
39
@jdk.Exported
40
public class DocTreePathScanner<R, P> extends DocTreeScanner<R, P> {
41
/**
42
* Scan a tree from a position identified by a TreePath.
43
*/
44
public R scan(DocTreePath path, P p) {
45
this.path = path;
46
try {
47
return path.getLeaf().accept(this, p);
48
} finally {
49
this.path = null;
50
}
51
}
52
53
/**
54
* Scan a single node.
55
* The current path is updated for the duration of the scan.
56
*/
57
@Override
58
public R scan(DocTree tree, P p) {
59
if (tree == null)
60
return null;
61
62
DocTreePath prev = path;
63
path = new DocTreePath(path, tree);
64
try {
65
return tree.accept(this, p);
66
} finally {
67
path = prev;
68
}
69
}
70
71
/**
72
* Get the current path for the node, as built up by the currently
73
* active set of scan calls.
74
*/
75
public DocTreePath getCurrentPath() {
76
return path;
77
}
78
79
private DocTreePath path;
80
}
81
82