KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > engine > RootTree


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.source.engine;
21
22 import com.sun.source.tree.CompilationUnitTree;
23 import com.sun.source.tree.Tree;
24 import com.sun.source.tree.TreeVisitor;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 /**
29  * A syntax tree definition for the list of compilation units which comprise
30  * the model for queries and transformations. The javac compiler
31  * doesn't create these, but Jackpot does to create a single root
32  * node for a set of source files which are processed together.
33  */

34 public final class RootTree implements Tree, Cloneable JavaDoc {
35     List JavaDoc<CompilationUnitTree> units;
36     
37     public RootTree(List JavaDoc<CompilationUnitTree> units) {
38         if (units == null)
39             throw new IllegalArgumentException JavaDoc("null units");
40         this.units = units;
41     }
42     
43     /**
44      * Returns all compilation units (source files) that were compiled for
45      * this query/transformation session.
46      */

47     public List JavaDoc<CompilationUnitTree> getCompilationUnits() {
48         return units;
49     }
50
51     public Kind getKind() {
52         return Kind.OTHER;
53     }
54
55     public <R, D> R accept(TreeVisitor<R, D> arg0, D arg1) {
56         // visitor is directly implemented, since com.sun.source.tree.TreeVisitor
57
// base classes don't know how to support the OTHER kind.
58
R r = null;
59         for (CompilationUnitTree unit : units) {
60             r = unit.accept(arg0, arg1);
61         }
62         return r;
63     }
64     
65     public Object JavaDoc clone() {
66         return new RootTree(new ArrayList JavaDoc<CompilationUnitTree>(units));
67     }
68 }
69
Popular Tags