EMMA Coverage Report (generated Thu Dec 06 15:52:10 GMT 2007)
[all classes][com.sun.source.util]

COVERAGE SUMMARY FOR SOURCE FILE [TreePath.java]

nameclass, %method, %block, %line, %
TreePath.java0%   (0/4)0%   (0/17)0%   (0/132)0%   (0/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TreePath0%   (0/1)0%   (0/10)0%   (0/77)0%   (0/23)
TreePath (CompilationUnitTree): void 0%   (0/1)0%   (0/5)0%   (0/2)
TreePath (TreePath, Tree): void 0%   (0/1)0%   (0/25)0%   (0/8)
access$000 (TreePath): TreePath 0%   (0/1)0%   (0/3)0%   (0/1)
access$100 (TreePath): Tree 0%   (0/1)0%   (0/3)0%   (0/1)
getCompilationUnit (): CompilationUnitTree 0%   (0/1)0%   (0/3)0%   (0/1)
getLeaf (): Tree 0%   (0/1)0%   (0/3)0%   (0/1)
getParentPath (): TreePath 0%   (0/1)0%   (0/3)0%   (0/1)
getPath (CompilationUnitTree, Tree): TreePath 0%   (0/1)0%   (0/7)0%   (0/1)
getPath (TreePath, Tree): TreePath 0%   (0/1)0%   (0/20)0%   (0/7)
iterator (): Iterator 0%   (0/1)0%   (0/5)0%   (0/1)
     
class TreePath$10%   (0/1)0%   (0/4)0%   (0/27)0%   (0/5)
TreePath$1 (TreePath): void 0%   (0/1)0%   (0/6)0%   (0/1)
hasNext (): boolean 0%   (0/1)0%   (0/8)0%   (0/1)
next (): Tree 0%   (0/1)0%   (0/9)0%   (0/2)
remove (): void 0%   (0/1)0%   (0/4)0%   (0/1)
     
class TreePath$1PathFinder0%   (0/1)0%   (0/2)0%   (0/22)0%   (0/4)
TreePath$1PathFinder (): void 0%   (0/1)0%   (0/3)0%   (0/1)
scan (Tree, Tree): TreePath 0%   (0/1)0%   (0/19)0%   (0/3)
     
class TreePath$1Result0%   (0/1)0%   (0/1)0%   (0/6)0%   (0/3)
TreePath$1Result (TreePath): void 0%   (0/1)0%   (0/6)0%   (0/3)

1/*
2 * Copyright 2006 Sun Microsystems, Inc.  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.  Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25 
26package com.sun.source.util;
27 
28import com.sun.source.tree.*;
29import java.util.Iterator;
30 
31/**
32 * A path of tree nodes, typically used to represent the sequence of ancestor
33 * nodes of a tree node up to the top level CompilationUnitTree node.
34 *
35 * @author Jonathan Gibbons
36 * @since 1.6
37 */
38public class TreePath implements Iterable<Tree> {
39    /**
40     * Gets a tree path for a tree node within a compilation unit.
41     * @return null if the node is not found
42     */
43    public static TreePath getPath(CompilationUnitTree unit, Tree target) {
44        return getPath(new TreePath(unit), target);
45    }
46 
47    /**
48     * Gets a tree path for a tree node within a subtree identified by a TreePath object.
49     * @return null if the node is not found
50     */
51    public static TreePath getPath(TreePath path, Tree target) {
52        path.getClass();
53        target.getClass();
54 
55        class Result extends Error {
56            static final long serialVersionUID = -5942088234594905625L;
57            TreePath path;
58            Result(TreePath path) {
59                this.path = path;
60            }
61        }
62        class PathFinder extends TreePathScanner<TreePath,Tree> {
63            public TreePath scan(Tree tree, Tree target) {
64                if (tree == target)
65                    throw new Result(new TreePath(getCurrentPath(), target));
66                return super.scan(tree, target);
67            }
68        }
69 
70        try {
71            new PathFinder().scan(path, target);
72        } catch (Result result) {
73            return result.path;
74        }
75        return null;
76    }
77 
78    /**
79     * Creates a TreePath for a root node.
80     */
81    public TreePath(CompilationUnitTree t) {
82        this(null, t);
83    }
84 
85    /**
86     * Creates a TreePath for a child node.
87     */
88    public TreePath(TreePath p, Tree t) {
89        if (t.getKind() == Tree.Kind.COMPILATION_UNIT) {
90            compilationUnit = (CompilationUnitTree) t;
91            parent = null;
92        }
93        else {
94            compilationUnit = p.compilationUnit;
95            parent = p;
96        }
97        leaf = t;
98    }
99    /**
100     * Get the compilation unit associated with this path.
101     */
102    public CompilationUnitTree getCompilationUnit() {
103        return compilationUnit;
104    }
105 
106    /**
107     * Get the leaf node for this path.
108     */
109    public Tree getLeaf() {
110        return leaf;
111    }
112 
113    /**
114     * Get the path for the enclosing node, or null if there is no enclosing node.
115     */
116    public TreePath getParentPath() {
117        return parent;
118    }
119 
120    public Iterator<Tree> iterator() {
121        return new Iterator<Tree>() {
122            public boolean hasNext() {
123                return curr.parent != null;
124            }
125 
126            public Tree next() {
127                curr = curr.parent;
128                return curr.leaf;
129            }
130 
131            public void remove() {
132                throw new UnsupportedOperationException();
133            }
134 
135            private TreePath curr;
136        };
137    }
138 
139    private CompilationUnitTree compilationUnit;
140    private Tree leaf;
141    private TreePath parent;
142}

[all classes][com.sun.source.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov