Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JavafxEnv |
|
| 0.0;0 | ||||
JavafxEnv$1 |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 1999-2007 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 | ||
26 | package com.sun.tools.javafx.comp; | |
27 | ||
28 | import com.sun.tools.javac.util.*; | |
29 | import com.sun.tools.javac.tree.*; | |
30 | import com.sun.tools.javafx.tree.*; | |
31 | import java.util.Iterator; | |
32 | import java.util.NoSuchElementException; | |
33 | ||
34 | /** A class for environments, instances of which are passed as | |
35 | * arguments to tree visitors. Environments refer to important ancestors | |
36 | * of the subtree that's currently visited, such as the enclosing method, | |
37 | * the enclosing class, or the enclosing toplevel node. They also contain | |
38 | * a generic component, represented as a type parameter, to carry further | |
39 | * information specific to individual passes. | |
40 | * | |
41 | * <p><b>This is NOT part of any API supported by Sun Microsystems. If | |
42 | * you write code that depends on this, you do so at your own risk. | |
43 | * This code and its internal interfaces are subject to change or | |
44 | * deletion without notice.</b> | |
45 | */ | |
46 | public class JavafxEnv<A> implements Iterable<JavafxEnv<A>> { | |
47 | ||
48 | /** The next enclosing environment. | |
49 | */ | |
50 | public JavafxEnv<A> next; | |
51 | ||
52 | /** The environment enclosing the current class. | |
53 | */ | |
54 | public JavafxEnv<A> outer; | |
55 | ||
56 | /** The tree with which this environment is associated. | |
57 | */ | |
58 | public JCTree tree; | |
59 | ||
60 | /** The enclosing toplevel tree. | |
61 | */ | |
62 | public JCTree.JCCompilationUnit toplevel; | |
63 | ||
64 | /** The next enclosing class definition. | |
65 | */ | |
66 | public JFXClassDeclaration enclClass; | |
67 | ||
68 | /** The next enclosing method definition. | |
69 | */ | |
70 | public JFXFunctionDefinition enclMethod; | |
71 | ||
72 | /** A generic field for further information. | |
73 | */ | |
74 | public A info; | |
75 | ||
76 | /** Is this an environment for evaluating a base clause? | |
77 | */ | |
78 | 12978 | public boolean baseClause = false; |
79 | ||
80 | /** Create an outermost environment for a given (toplevel)tree, | |
81 | * with a given info field. | |
82 | */ | |
83 | 12978 | public JavafxEnv(JCTree tree, A info) { |
84 | 12978 | this.next = null; |
85 | 12978 | this.outer = null; |
86 | 12978 | this.tree = tree; |
87 | 12978 | this.toplevel = null; |
88 | 12978 | this.enclClass = null; |
89 | 12978 | this.enclMethod = null; |
90 | 12978 | this.info = info; |
91 | 12978 | } |
92 | ||
93 | /** Duplicate this environment, updating with given tree and info, | |
94 | * and copying all other fields. | |
95 | */ | |
96 | public JavafxEnv<A> dup(JCTree tree, A info) { | |
97 | 12288 | return dupto(new JavafxEnv<A>(tree, info)); |
98 | } | |
99 | ||
100 | /** Duplicate this environment into a given Environment, | |
101 | * using its tree and info, and copying all other fields. | |
102 | */ | |
103 | public JavafxEnv<A> dupto(JavafxEnv<A> that) { | |
104 | 12288 | that.next = this; |
105 | 12288 | that.outer = this.outer; |
106 | 12288 | that.toplevel = this.toplevel; |
107 | 12288 | that.enclClass = this.enclClass; |
108 | 12288 | that.enclMethod = this.enclMethod; |
109 | 12288 | return that; |
110 | } | |
111 | ||
112 | /** Duplicate this environment, updating with given tree, | |
113 | * and copying all other fields. | |
114 | */ | |
115 | public JavafxEnv<A> dup(JCTree tree) { | |
116 | 1589 | return dup(tree, this.info); |
117 | } | |
118 | ||
119 | /** Return closest enclosing environment which points to a tree with given tag. | |
120 | */ | |
121 | public JavafxEnv<A> enclosing(int tag) { | |
122 | 385 | JavafxEnv<A> env1 = this; |
123 | 770 | while (env1 != null && env1.tree.getTag() != tag) env1 = env1.next; |
124 | 385 | return env1; |
125 | } | |
126 | ||
127 | public String toString() { | |
128 | 0 | return "JavafxEnv[" + info + (outer == null ? "" : ",outer=" + outer) + "]"; |
129 | } | |
130 | ||
131 | public Iterator<JavafxEnv<A>> iterator() { | |
132 | 0 | return new Iterator<JavafxEnv<A>>() { |
133 | 0 | JavafxEnv<A> next = JavafxEnv.this; |
134 | public boolean hasNext() { | |
135 | 0 | return next.outer != null; |
136 | } | |
137 | public JavafxEnv<A> next() { | |
138 | 0 | if (hasNext()) { |
139 | 0 | JavafxEnv<A> current = next; |
140 | 0 | next = current.outer; |
141 | 0 | return current; |
142 | } | |
143 | 0 | throw new NoSuchElementException(); |
144 | ||
145 | } | |
146 | public void remove() { | |
147 | 0 | throw new UnsupportedOperationException(); |
148 | } | |
149 | }; | |
150 | } | |
151 | } |