KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.java.source.engine.RootTree;
23 import com.sun.source.tree.IdentifierTree;
24 import javax.lang.model.SourceVersion;
25 import org.netbeans.modules.java.source.engine.ReattributionException;
26 import org.netbeans.modules.java.source.engine.RootTree;
27 import com.sun.source.tree.CompilationUnitTree;
28 import com.sun.source.tree.Tree;
29 import java.util.List JavaDoc;
30 import javax.lang.model.element.Element;
31 import javax.lang.model.type.TypeMirror;
32
33 /**
34  * A service that provides access to the current root tree node of the
35  * source model, as well as utility methods.
36  */

37 public interface ASTModel {
38
39     /**
40      * Return the current root tree.
41      */

42     Tree getRoot();
43
44     /**
45      * Return the JCCompilationUnit parent of a specified tree.
46      *
47      * @return the JCCompilationUnit, or null if tree is a RootTree.
48      */

49     CompilationUnitTree getTopLevel(Tree tree);
50     
51     /**
52      * Returns the element for a specified tree. Null is returned if the
53      * tree type doesn't have an associated element, or if the reference
54      * is not resolved.
55      */

56     Element getElement(Tree tree);
57     
58     /**
59      * Returns the type for a specified tree. Null is returned if the
60      * tree type doesn't have an associated type, or if the type reference
61      * is not resolved.
62      */

63     TypeMirror getType(Tree tree);
64     
65     /**
66      * Get the position for a tree node. The position is defined
67      * as the place where the cursor would be placed when printing
68      * an error message for a tree. While most trees define the
69      * start position and this position to be the same, some don't.
70      * For example, method trees define the position as the start
71      * of the method's name, while the start position is the start
72      * of the first modifier token.
73      */

74     int getPos(Tree tree);
75
76     /**
77      * Get the start position for a tree node. The start position is
78      * defined to be the position of the first character of the first
79      * token of the node's source text.
80      * @param tree The tree node
81      */

82     int getStartPos(Tree tree);
83             
84     /** Get the end position for a tree node. The end position is
85      * defined to be the position of the last character of the last
86      * token of the node's source text. Returns Position.NOPOS if genEndPos
87      * is not set, or the position is otherwise not found.
88      * @param tree The tree node
89      */

90     int getEndPos(Tree tree, CompilationUnitTree topLevel);
91     
92     /**
93      * Sets the tree position. This method is normally only called by
94      * ImmutableTreeTranslator.
95      */

96     void setPos(Tree tree, int newPos);
97     
98     /**
99      * Returns true if this is an identifier for "this".
100      */

101     boolean isThis(IdentifierTree t);
102
103     /**
104      * Returns true if this is an element for "this".
105      */

106     boolean isThis(Element e);
107
108     /**
109      * Returns true if the tree was generated by javac and
110      * not defined in the source code.
111      */

112     boolean isSynthetic(Tree tree);
113     
114     /**
115      * Sets the element associated with a Tree. This should only be done
116      * either on trees created by TreeMaker or clone(), and never on original
117      * trees.
118      *
119      * @see org.netbeans.api.java.source.TreeMaker
120      */

121     void setElement(Tree tree, Element element);
122         
123     /**
124      * Sets the TypeMirror associated with a Tree. This should only be done
125      * either on trees created by TreeMaker or clone(), and never on original
126      * trees.
127      *
128      * @see org.netbeans.api.java.source.TreeMaker
129      */

130     void setType(Tree tree, TypeMirror type);
131     
132     /**
133      * Replace the current root tree.
134      */

135     void setRoot(final RootTree tree) throws ReattributionException;
136     
137     /**
138      * Returns how many references to instance variables or methods there are
139      * in a given tree.
140      */

141     int getInstanceReferenceCount(Tree t);
142     
143     /**
144      * Return the -source level the model was built with.
145      */

146     SourceVersion sourceVersion();
147     
148     /**
149      * Returns true if the tree defines a static class or class member.
150      */

151     boolean isStatic(Tree tree);
152
153     /**
154      * Returns the list of children from a package, compilation unit or
155      * class. If the specified tree is not one of these types or if the
156      * tree doesn't have any children, then an empty list is returned.
157      */

158     List JavaDoc<? extends Tree> getChildren(Tree tree);
159
160     /**
161      * Returns a tree path from a specified root tree to a specified
162      * target tree. If the target is not a child of the root tree,
163      * then a zero-length array is returned.
164      */

165     Tree[] makePath(final Tree root, final Tree target);
166 }
167
Popular Tags