1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
package com.sun.tools.javafx.comp; |
27 | |
|
28 | |
import com.sun.tools.javac.code.Flags; |
29 | |
import com.sun.tools.javac.code.Scope; |
30 | |
import com.sun.tools.javac.code.Symbol; |
31 | |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
32 | |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
33 | |
import com.sun.tools.javac.code.Symbol.TypeSymbol; |
34 | |
import com.sun.tools.javac.code.Type.ClassType; |
35 | |
import com.sun.tools.javac.code.Type.ErrorType; |
36 | |
import com.sun.tools.javac.comp.AttrContext; |
37 | |
import com.sun.tools.javac.comp.Enter; |
38 | |
import com.sun.tools.javac.comp.Env; |
39 | |
import com.sun.tools.javac.tree.JCTree; |
40 | |
import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
41 | |
import com.sun.tools.javac.util.Context; |
42 | |
import com.sun.tools.javac.util.List; |
43 | |
import com.sun.tools.javafx.tree.JFXBlockExpression; |
44 | |
|
45 | |
import static com.sun.tools.javac.code.Flags.*; |
46 | |
import static com.sun.tools.javac.code.Kinds.*; |
47 | |
import static com.sun.tools.javac.code.TypeTags.*; |
48 | |
|
49 | |
public class BlockExprEnter extends Enter { |
50 | |
public static Enter instance0(Context context) { |
51 | 0 | Enter instance = context.get(enterKey); |
52 | 0 | if (instance == null) |
53 | 0 | instance = new BlockExprEnter(context); |
54 | 0 | return instance; |
55 | |
} |
56 | |
|
57 | |
public static void preRegister(final Context context) { |
58 | 798 | context.put(enterKey, new Context.Factory<Enter>() { |
59 | |
public Enter make() { |
60 | 399 | return new BlockExprEnter(context); |
61 | |
} |
62 | |
}); |
63 | 399 | } |
64 | |
|
65 | |
protected BlockExprEnter(Context context) { |
66 | 399 | super(context); |
67 | 399 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
public void scan(JCTree tree) { |
72 | 0 | if(tree!=null) tree.accept(this); |
73 | 0 | } |
74 | |
|
75 | |
|
76 | |
|
77 | |
public void scan(List<? extends JCTree> trees) { |
78 | 0 | if (trees != null) |
79 | 0 | for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) |
80 | 0 | scan(l.head); |
81 | 0 | } |
82 | |
|
83 | |
|
84 | |
public void visitClassDef(JCClassDecl tree) { |
85 | 1772 | Symbol owner = env.info.scope.owner; |
86 | 1772 | Scope enclScope = enterScope(env); |
87 | |
ClassSymbol c; |
88 | 1772 | if (owner.kind == PCK) { |
89 | |
|
90 | 674 | PackageSymbol packge = (PackageSymbol)owner; |
91 | 2036 | for (Symbol q = packge; q != null && q.kind == PCK; q = q.owner) |
92 | 1362 | q.flags_field |= EXISTS; |
93 | 674 | c = reader.enterClass(tree.name, packge); |
94 | 674 | packge.members().enterIfAbsent(c); |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | 674 | } else { |
102 | 1098 | if (tree.name.len != 0 && |
103 | |
!chk.checkUniqueClassName(tree.pos(), tree.name, enclScope)) { |
104 | 0 | result = null; |
105 | 0 | return; |
106 | |
} |
107 | 1098 | if (owner.kind == TYP) { |
108 | |
|
109 | 483 | c = reader.enterClass(tree.name, (TypeSymbol)owner); |
110 | 483 | if ((owner.flags_field & INTERFACE) != 0) { |
111 | 0 | tree.mods.flags |= PUBLIC | STATIC; |
112 | |
} |
113 | |
} else { |
114 | |
|
115 | 615 | c = reader.defineClass(tree.name, owner); |
116 | 615 | c.flatname = chk.localClassName(c); |
117 | 615 | if (c.name.len != 0) |
118 | 26 | chk.checkTransparentClass(tree.pos(), c, env.info.scope); |
119 | |
} |
120 | |
} |
121 | 1772 | tree.sym = c; |
122 | |
|
123 | |
|
124 | 1772 | if (chk.compiled.get(c.flatname) != null) { |
125 | 0 | duplicateClass(tree.pos(), c); |
126 | 0 | result = new ErrorType(tree.name, (TypeSymbol)owner); |
127 | 0 | tree.sym = (ClassSymbol)result.tsym; |
128 | 0 | return; |
129 | |
} |
130 | 1772 | chk.compiled.put(c.flatname, c); |
131 | 1772 | enclScope.enter(c); |
132 | |
|
133 | |
|
134 | |
|
135 | 1772 | Env<AttrContext> localEnv = classEnv(tree, env); |
136 | 1772 | typeEnvs.put(c, localEnv); |
137 | |
|
138 | |
|
139 | 1772 | c.completer = memberEnter; |
140 | 1772 | boolean wasStatic = (tree.mods.flags & Flags.STATIC) != 0L; |
141 | 1772 | c.flags_field = chk.checkFlags(tree.pos(), (tree.mods.flags & ~(Flags.STATIC)), c, tree); |
142 | 1772 | if (wasStatic) { |
143 | 694 | c.flags_field |= Flags.STATIC; |
144 | |
} |
145 | |
|
146 | 1772 | c.sourcefile = env.toplevel.sourcefile; |
147 | 1772 | c.members_field = new Scope(c); |
148 | |
|
149 | 1772 | ClassType ct = (ClassType)c.type; |
150 | 1772 | if (owner.kind != PCK && (c.flags_field & STATIC) == 0) { |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | 167 | Symbol owner1 = owner; |
156 | |
while ((owner1.kind & (VAR | MTH)) != 0 && |
157 | 311 | (owner1.flags_field & STATIC) == 0) { |
158 | 144 | owner1 = owner1.owner; |
159 | |
} |
160 | 167 | if (owner1.kind == TYP) { |
161 | 144 | ct.setEnclosingType(owner1.type); |
162 | |
} |
163 | |
} |
164 | |
|
165 | |
|
166 | 1772 | ct.typarams_field = classEnter(tree.typarams, localEnv); |
167 | |
|
168 | |
|
169 | |
|
170 | 1772 | if (!c.isLocal() && uncompleted != null) uncompleted.append(c); |
171 | |
|
172 | |
|
173 | |
|
174 | 1772 | classEnter(tree.defs, localEnv); |
175 | |
|
176 | 1772 | result = c.type; |
177 | 1772 | } |
178 | |
|
179 | |
public void visitBlockExpression(JFXBlockExpression that) { |
180 | 0 | scan(that.stats); |
181 | 0 | scan(that.value); |
182 | 0 | } |
183 | |
} |