Methods Summary |
---|
public com.sun.source.tree.CompilationUnitTree | getCompilationUnit()Get the compilation unit associated with this path.
return compilationUnit;
|
public com.sun.source.tree.Tree | getLeaf()Get the leaf node for this path.
return leaf;
|
public com.sun.source.util.TreePath | getParentPath()Get the path for the enclosing node, or null if there is no enclosing node.
return parent;
|
public static com.sun.source.util.TreePath | getPath(com.sun.source.tree.CompilationUnitTree unit, com.sun.source.tree.Tree target)Gets a tree path for a tree node within a compilation unit.
return getPath(new TreePath(unit), target);
|
public static com.sun.source.util.TreePath | getPath(com.sun.source.util.TreePath path, com.sun.source.tree.Tree target)Gets a tree path for a tree node within a subtree identified by a TreePath object.
path.getClass();
target.getClass();
class Result extends Error {
static final long serialVersionUID = -5942088234594905625L;
TreePath path;
Result(TreePath path) {
this.path = path;
}
}
class PathFinder extends TreePathScanner<TreePath,Tree> {
public TreePath scan(Tree tree, Tree target) {
if (tree == target)
throw new Result(new TreePath(getCurrentPath(), target));
return super.scan(tree, target);
}
}
try {
new PathFinder().scan(path, target);
} catch (Result result) {
return result.path;
}
return null;
|
public java.util.Iterator | iterator()
return new Iterator<Tree>() {
public boolean hasNext() {
return curr.parent != null;
}
public Tree next() {
curr = curr.parent;
return curr.leaf;
}
public void remove() {
throw new UnsupportedOperationException();
}
private TreePath curr;
};
|