Skip to content

Commit 1a743c2

Browse files
author
duke
committedApr 25, 2022
Automatic merge of jdk:master into master
2 parents 26dbc2b + 80a7f7b commit 1a743c2

File tree

2 files changed

+61
-44
lines changed

2 files changed

+61
-44
lines changed
 

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

+31-24
Original file line numberDiff line numberDiff line change
@@ -59,38 +59,45 @@ public static DocTreePath getPath(TreePath treePath, DocCommentTree doc, DocTree
5959
* @return a path identifying the target node
6060
*/
6161
public static DocTreePath getPath(DocTreePath path, DocTree target) {
62-
Objects.requireNonNull(path); //null check
63-
Objects.requireNonNull(target); //null check
64-
65-
class Result extends Error {
66-
static final long serialVersionUID = -5942088234594905625L;
67-
@SuppressWarnings("serial") // Type of field is not Serializable
68-
DocTreePath path;
69-
Result(DocTreePath path) {
70-
this.path = path;
62+
Objects.requireNonNull(path);
63+
Objects.requireNonNull(target);
64+
65+
class PathFinder extends DocTreePathScanner<DocTreePath, DocTree> {
66+
private DocTreePath result;
67+
68+
@Override
69+
public DocTreePath scan(DocTreePath path, DocTree target) {
70+
super.scan(path, target);
71+
return result;
7172
}
72-
}
7373

74-
class PathFinder extends DocTreePathScanner<DocTreePath,DocTree> {
7574
@Override
7675
public DocTreePath scan(DocTree tree, DocTree target) {
77-
if (tree == target) {
78-
throw new Result(new DocTreePath(getCurrentPath(), target));
76+
if (result == null) {
77+
if (tree == target) {
78+
result = new DocTreePath(getCurrentPath(), target);
79+
} else {
80+
super.scan(tree, target);
81+
}
7982
}
80-
return super.scan(tree, target);
83+
return result;
8184
}
82-
}
8385

84-
if (path.getLeaf() == target) {
85-
return path;
86-
}
87-
88-
try {
89-
new PathFinder().scan(path, target);
90-
} catch (Result result) {
91-
return result.path;
86+
@Override
87+
public DocTreePath scan(Iterable<? extends DocTree> nodes, DocTree target) {
88+
if (nodes != null && result == null) {
89+
for (DocTree node : nodes) {
90+
scan(node, target);
91+
if (result != null) {
92+
break;
93+
}
94+
}
95+
}
96+
return result;
97+
}
9298
}
93-
return null;
99+
return path.getLeaf() == target ? path
100+
: new PathFinder().scan(path, target);
94101
}
95102

96103
/**

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

+30-20
Original file line numberDiff line numberDiff line change
@@ -61,34 +61,44 @@ public static TreePath getPath(TreePath path, Tree target) {
6161
Objects.requireNonNull(path);
6262
Objects.requireNonNull(target);
6363

64-
class Result extends Error {
65-
static final long serialVersionUID = -5942088234594905625L;
66-
@SuppressWarnings("serial") // Type of field is not Serializable
67-
TreePath path;
68-
Result(TreePath path) {
69-
this.path = path;
64+
class PathFinder extends TreePathScanner<TreePath,Tree> {
65+
private TreePath result;
66+
67+
68+
@Override
69+
public TreePath scan(TreePath path, Tree target) {
70+
super.scan(path, target);
71+
return result;
7072
}
71-
}
7273

73-
class PathFinder extends TreePathScanner<TreePath,Tree> {
74+
@Override
7475
public TreePath scan(Tree tree, Tree target) {
75-
if (tree == target) {
76-
throw new Result(new TreePath(getCurrentPath(), target));
76+
if (result == null) {
77+
if (tree == target) {
78+
result = new TreePath(getCurrentPath(), target);
79+
} else {
80+
super.scan(tree, target);
81+
}
7782
}
78-
return super.scan(tree, target);
83+
return result;
7984
}
80-
}
8185

82-
if (path.getLeaf() == target) {
83-
return path;
86+
@Override
87+
public TreePath scan(Iterable<? extends Tree> nodes, Tree target) {
88+
if (nodes != null && result == null) {
89+
for (Tree node : nodes) {
90+
scan(node, target);
91+
if (result != null) {
92+
break;
93+
}
94+
}
95+
}
96+
return result;
97+
}
8498
}
8599

86-
try {
87-
new PathFinder().scan(path, target);
88-
} catch (Result result) {
89-
return result.path;
90-
}
91-
return null;
100+
return path.getLeaf() == target ? path
101+
: new PathFinder().scan(path, target);
92102
}
93103

94104
/**

0 commit comments

Comments
 (0)
Please sign in to comment.