@@ -59,38 +59,45 @@ public static DocTreePath getPath(TreePath treePath, DocCommentTree doc, DocTree
59
59
* @return a path identifying the target node
60
60
*/
61
61
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 ;
71
72
}
72
- }
73
73
74
- class PathFinder extends DocTreePathScanner <DocTreePath ,DocTree > {
75
74
@ Override
76
75
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
+ }
79
82
}
80
- return super . scan ( tree , target ) ;
83
+ return result ;
81
84
}
82
- }
83
85
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
+ }
92
98
}
93
- return null ;
99
+ return path .getLeaf () == target ? path
100
+ : new PathFinder ().scan (path , target );
94
101
}
95
102
96
103
/**
0 commit comments