author | mcimadamore |
Mon, 26 Mar 2012 15:28:22 +0100 | |
changeset 12334 | 29e1bfdcba4e |
parent 12333 | 7b02d0529a97 |
child 12915 | 28cf1e0dafdc |
permissions | -rw-r--r-- |
10 | 1 |
/* |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2 |
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.comp; |
|
27 |
||
28 |
import java.util.*; |
|
29 |
import java.util.Set; |
|
30 |
import javax.lang.model.element.ElementKind; |
|
31 |
import javax.tools.JavaFileObject; |
|
32 |
||
33 |
import com.sun.tools.javac.code.*; |
|
34 |
import com.sun.tools.javac.jvm.*; |
|
35 |
import com.sun.tools.javac.tree.*; |
|
36 |
import com.sun.tools.javac.util.*; |
|
37 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
38 |
import com.sun.tools.javac.util.List; |
|
39 |
||
40 |
import com.sun.tools.javac.jvm.Target; |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
41 |
import com.sun.tools.javac.code.Lint.LintCategory; |
10 | 42 |
import com.sun.tools.javac.code.Symbol.*; |
43 |
import com.sun.tools.javac.tree.JCTree.*; |
|
44 |
import com.sun.tools.javac.code.Type.*; |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
45 |
import com.sun.tools.javac.comp.Check.CheckContext; |
10 | 46 |
|
47 |
import com.sun.source.tree.IdentifierTree; |
|
48 |
import com.sun.source.tree.MemberSelectTree; |
|
49 |
import com.sun.source.tree.TreeVisitor; |
|
50 |
import com.sun.source.util.SimpleTreeVisitor; |
|
51 |
||
52 |
import static com.sun.tools.javac.code.Flags.*; |
|
10950 | 53 |
import static com.sun.tools.javac.code.Flags.ANNOTATION; |
54 |
import static com.sun.tools.javac.code.Flags.BLOCK; |
|
10 | 55 |
import static com.sun.tools.javac.code.Kinds.*; |
10950 | 56 |
import static com.sun.tools.javac.code.Kinds.ERRONEOUS; |
10 | 57 |
import static com.sun.tools.javac.code.TypeTags.*; |
10950 | 58 |
import static com.sun.tools.javac.code.TypeTags.WILDCARD; |
59 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
|
10 | 60 |
|
61 |
/** This is the main context-dependent analysis phase in GJC. It |
|
62 |
* encompasses name resolution, type checking and constant folding as |
|
63 |
* subtasks. Some subtasks involve auxiliary classes. |
|
64 |
* @see Check |
|
65 |
* @see Resolve |
|
66 |
* @see ConstFold |
|
67 |
* @see Infer |
|
68 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
69 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
70 |
* If you write code that depends on this, you do so at your own risk. |
10 | 71 |
* This code and its internal interfaces are subject to change or |
72 |
* deletion without notice.</b> |
|
73 |
*/ |
|
74 |
public class Attr extends JCTree.Visitor { |
|
75 |
protected static final Context.Key<Attr> attrKey = |
|
76 |
new Context.Key<Attr>(); |
|
77 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
78 |
final Names names; |
10 | 79 |
final Log log; |
80 |
final Symtab syms; |
|
81 |
final Resolve rs; |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
82 |
final Infer infer; |
10 | 83 |
final Check chk; |
84 |
final MemberEnter memberEnter; |
|
85 |
final TreeMaker make; |
|
86 |
final ConstFold cfolder; |
|
87 |
final Enter enter; |
|
88 |
final Target target; |
|
89 |
final Types types; |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
941
diff
changeset
|
90 |
final JCDiagnostic.Factory diags; |
10 | 91 |
final Annotate annotate; |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
92 |
final DeferredLintHandler deferredLintHandler; |
10 | 93 |
|
94 |
public static Attr instance(Context context) { |
|
95 |
Attr instance = context.get(attrKey); |
|
96 |
if (instance == null) |
|
97 |
instance = new Attr(context); |
|
98 |
return instance; |
|
99 |
} |
|
100 |
||
101 |
protected Attr(Context context) { |
|
102 |
context.put(attrKey, this); |
|
103 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
104 |
names = Names.instance(context); |
10 | 105 |
log = Log.instance(context); |
106 |
syms = Symtab.instance(context); |
|
107 |
rs = Resolve.instance(context); |
|
108 |
chk = Check.instance(context); |
|
109 |
memberEnter = MemberEnter.instance(context); |
|
110 |
make = TreeMaker.instance(context); |
|
111 |
enter = Enter.instance(context); |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
112 |
infer = Infer.instance(context); |
10 | 113 |
cfolder = ConstFold.instance(context); |
114 |
target = Target.instance(context); |
|
115 |
types = Types.instance(context); |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
941
diff
changeset
|
116 |
diags = JCDiagnostic.Factory.instance(context); |
10 | 117 |
annotate = Annotate.instance(context); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
118 |
deferredLintHandler = DeferredLintHandler.instance(context); |
10 | 119 |
|
120 |
Options options = Options.instance(context); |
|
121 |
||
122 |
Source source = Source.instance(context); |
|
123 |
allowGenerics = source.allowGenerics(); |
|
124 |
allowVarargs = source.allowVarargs(); |
|
125 |
allowEnums = source.allowEnums(); |
|
126 |
allowBoxing = source.allowBoxing(); |
|
127 |
allowCovariantReturns = source.allowCovariantReturns(); |
|
128 |
allowAnonOuterThis = source.allowAnonOuterThis(); |
|
4142 | 129 |
allowStringsInSwitch = source.allowStringsInSwitch(); |
130 |
sourceName = source.name; |
|
6721 | 131 |
relax = (options.isSet("-retrofit") || |
132 |
options.isSet("-relax")); |
|
7081
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
133 |
findDiamonds = options.get("findDiamond") != null && |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
134 |
source.allowDiamond(); |
6721 | 135 |
useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning"); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
136 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
137 |
statInfo = new ResultInfo(NIL, Type.noType); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
138 |
varInfo = new ResultInfo(VAR, Type.noType); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
139 |
unknownExprInfo = new ResultInfo(VAL, Type.noType); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
140 |
unknownTypeInfo = new ResultInfo(TYP, Type.noType); |
10 | 141 |
} |
142 |
||
143 |
/** Switch: relax some constraints for retrofit mode. |
|
144 |
*/ |
|
145 |
boolean relax; |
|
146 |
||
147 |
/** Switch: support generics? |
|
148 |
*/ |
|
149 |
boolean allowGenerics; |
|
150 |
||
151 |
/** Switch: allow variable-arity methods. |
|
152 |
*/ |
|
153 |
boolean allowVarargs; |
|
154 |
||
155 |
/** Switch: support enums? |
|
156 |
*/ |
|
157 |
boolean allowEnums; |
|
158 |
||
159 |
/** Switch: support boxing and unboxing? |
|
160 |
*/ |
|
161 |
boolean allowBoxing; |
|
162 |
||
163 |
/** Switch: support covariant result types? |
|
164 |
*/ |
|
165 |
boolean allowCovariantReturns; |
|
166 |
||
167 |
/** Switch: allow references to surrounding object from anonymous |
|
168 |
* objects during constructor call? |
|
169 |
*/ |
|
170 |
boolean allowAnonOuterThis; |
|
171 |
||
7081
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
172 |
/** Switch: generates a warning if diamond can be safely applied |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
173 |
* to a given new expression |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
174 |
*/ |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
175 |
boolean findDiamonds; |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
176 |
|
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
177 |
/** |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
178 |
* Internally enables/disables diamond finder feature |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
179 |
*/ |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
180 |
static final boolean allowDiamondFinder = true; |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
181 |
|
10 | 182 |
/** |
183 |
* Switch: warn about use of variable before declaration? |
|
184 |
* RFE: 6425594 |
|
185 |
*/ |
|
186 |
boolean useBeforeDeclarationWarning; |
|
187 |
||
3661 | 188 |
/** |
4142 | 189 |
* Switch: allow strings in switch? |
190 |
*/ |
|
191 |
boolean allowStringsInSwitch; |
|
192 |
||
193 |
/** |
|
194 |
* Switch: name of source level; used for error reporting. |
|
195 |
*/ |
|
196 |
String sourceName; |
|
197 |
||
10 | 198 |
/** Check kind and type of given tree against protokind and prototype. |
199 |
* If check succeeds, store type in tree and return it. |
|
200 |
* If check fails, store errType in tree and return it. |
|
201 |
* No checks are performed if the prototype is a method type. |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
202 |
* It is not necessary in this case since we know that kind and type |
10 | 203 |
* are correct. |
204 |
* |
|
205 |
* @param tree The tree whose kind and type is checked |
|
206 |
* @param owntype The computed type of the tree |
|
207 |
* @param ownkind The computed kind of the tree |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
208 |
* @param resultInfo The expected result of the tree |
10 | 209 |
*/ |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
210 |
Type check(JCTree tree, Type owntype, int ownkind, ResultInfo resultInfo) { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
211 |
if (owntype.tag != ERROR && resultInfo.pt.tag != METHOD && resultInfo.pt.tag != FORALL) { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
212 |
if ((ownkind & ~resultInfo.pkind) == 0) { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
213 |
owntype = resultInfo.check(tree, owntype); |
10 | 214 |
} else { |
215 |
log.error(tree.pos(), "unexpected.type", |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
216 |
kindNames(resultInfo.pkind), |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
217 |
kindName(ownkind)); |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
218 |
owntype = types.createErrorType(owntype); |
10 | 219 |
} |
220 |
} |
|
221 |
tree.type = owntype; |
|
222 |
return owntype; |
|
223 |
} |
|
224 |
||
225 |
/** Is given blank final variable assignable, i.e. in a scope where it |
|
226 |
* may be assigned to even though it is final? |
|
227 |
* @param v The blank final variable. |
|
228 |
* @param env The current environment. |
|
229 |
*/ |
|
230 |
boolean isAssignableAsBlankFinal(VarSymbol v, Env<AttrContext> env) { |
|
231 |
Symbol owner = env.info.scope.owner; |
|
232 |
// owner refers to the innermost variable, method or |
|
233 |
// initializer block declaration at this point. |
|
234 |
return |
|
235 |
v.owner == owner |
|
236 |
|| |
|
237 |
((owner.name == names.init || // i.e. we are in a constructor |
|
238 |
owner.kind == VAR || // i.e. we are in a variable initializer |
|
239 |
(owner.flags() & BLOCK) != 0) // i.e. we are in an initializer block |
|
240 |
&& |
|
241 |
v.owner == owner.owner |
|
242 |
&& |
|
243 |
((v.flags() & STATIC) != 0) == Resolve.isStatic(env)); |
|
244 |
} |
|
245 |
||
246 |
/** Check that variable can be assigned to. |
|
247 |
* @param pos The current source code position. |
|
248 |
* @param v The assigned varaible |
|
249 |
* @param base If the variable is referred to in a Select, the part |
|
250 |
* to the left of the `.', null otherwise. |
|
251 |
* @param env The current environment. |
|
252 |
*/ |
|
253 |
void checkAssignable(DiagnosticPosition pos, VarSymbol v, JCTree base, Env<AttrContext> env) { |
|
254 |
if ((v.flags() & FINAL) != 0 && |
|
255 |
((v.flags() & HASINIT) != 0 |
|
256 |
|| |
|
257 |
!((base == null || |
|
10950 | 258 |
(base.hasTag(IDENT) && TreeInfo.name(base) == names._this)) && |
10 | 259 |
isAssignableAsBlankFinal(v, env)))) { |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
260 |
if (v.isResourceVariable()) { //TWR resource |
7211
163fe60f63de
6970016: Clean up ARM/try-with-resources implementation
mcimadamore
parents:
7208
diff
changeset
|
261 |
log.error(pos, "try.resource.may.not.be.assigned", v); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
262 |
} else { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
263 |
log.error(pos, "cant.assign.val.to.final.var", v); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
264 |
} |
7203
1153590927f7
6993963: Project Coin: Use precise exception analysis for effectively final catch parameters
mcimadamore
parents:
7081
diff
changeset
|
265 |
} else if ((v.flags() & EFFECTIVELY_FINAL) != 0) { |
1153590927f7
6993963: Project Coin: Use precise exception analysis for effectively final catch parameters
mcimadamore
parents:
7081
diff
changeset
|
266 |
v.flags_field &= ~EFFECTIVELY_FINAL; |
10 | 267 |
} |
268 |
} |
|
269 |
||
270 |
/** Does tree represent a static reference to an identifier? |
|
271 |
* It is assumed that tree is either a SELECT or an IDENT. |
|
272 |
* We have to weed out selects from non-type names here. |
|
273 |
* @param tree The candidate tree. |
|
274 |
*/ |
|
275 |
boolean isStaticReference(JCTree tree) { |
|
10950 | 276 |
if (tree.hasTag(SELECT)) { |
10 | 277 |
Symbol lsym = TreeInfo.symbol(((JCFieldAccess) tree).selected); |
278 |
if (lsym == null || lsym.kind != TYP) { |
|
279 |
return false; |
|
280 |
} |
|
281 |
} |
|
282 |
return true; |
|
283 |
} |
|
284 |
||
285 |
/** Is this symbol a type? |
|
286 |
*/ |
|
287 |
static boolean isType(Symbol sym) { |
|
288 |
return sym != null && sym.kind == TYP; |
|
289 |
} |
|
290 |
||
291 |
/** The current `this' symbol. |
|
292 |
* @param env The current environment. |
|
293 |
*/ |
|
294 |
Symbol thisSym(DiagnosticPosition pos, Env<AttrContext> env) { |
|
295 |
return rs.resolveSelf(pos, env, env.enclClass.sym, names._this); |
|
296 |
} |
|
297 |
||
298 |
/** Attribute a parsed identifier. |
|
299 |
* @param tree Parsed identifier name |
|
300 |
* @param topLevel The toplevel to use |
|
301 |
*/ |
|
302 |
public Symbol attribIdent(JCTree tree, JCCompilationUnit topLevel) { |
|
303 |
Env<AttrContext> localEnv = enter.topLevelEnv(topLevel); |
|
304 |
localEnv.enclClass = make.ClassDef(make.Modifiers(0), |
|
305 |
syms.errSymbol.name, |
|
306 |
null, null, null, null); |
|
307 |
localEnv.enclClass.sym = syms.errSymbol; |
|
308 |
return tree.accept(identAttributer, localEnv); |
|
309 |
} |
|
310 |
// where |
|
311 |
private TreeVisitor<Symbol,Env<AttrContext>> identAttributer = new IdentAttributer(); |
|
312 |
private class IdentAttributer extends SimpleTreeVisitor<Symbol,Env<AttrContext>> { |
|
313 |
@Override |
|
314 |
public Symbol visitMemberSelect(MemberSelectTree node, Env<AttrContext> env) { |
|
315 |
Symbol site = visit(node.getExpression(), env); |
|
316 |
if (site.kind == ERR) |
|
317 |
return site; |
|
318 |
Name name = (Name)node.getIdentifier(); |
|
319 |
if (site.kind == PCK) { |
|
320 |
env.toplevel.packge = (PackageSymbol)site; |
|
321 |
return rs.findIdentInPackage(env, (TypeSymbol)site, name, TYP | PCK); |
|
322 |
} else { |
|
323 |
env.enclClass.sym = (ClassSymbol)site; |
|
324 |
return rs.findMemberType(env, site.asType(), name, (TypeSymbol)site); |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
@Override |
|
329 |
public Symbol visitIdentifier(IdentifierTree node, Env<AttrContext> env) { |
|
330 |
return rs.findIdent(env, (Name)node.getName(), TYP | PCK); |
|
331 |
} |
|
332 |
} |
|
333 |
||
334 |
public Type coerce(Type etype, Type ttype) { |
|
335 |
return cfolder.coerce(etype, ttype); |
|
336 |
} |
|
337 |
||
338 |
public Type attribType(JCTree node, TypeSymbol sym) { |
|
339 |
Env<AttrContext> env = enter.typeEnvs.get(sym); |
|
340 |
Env<AttrContext> localEnv = env.dup(node, env.info.dup()); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
341 |
return attribTree(node, localEnv, unknownTypeInfo); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
342 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
343 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
344 |
public Type attribImportQualifier(JCImport tree, Env<AttrContext> env) { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
345 |
// Attribute qualifying package or class. |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
346 |
JCFieldAccess s = (JCFieldAccess)tree.qualid; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
347 |
return attribTree(s.selected, |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
348 |
env, |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
349 |
new ResultInfo(tree.staticImport ? TYP : (TYP | PCK), |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
350 |
Type.noType)); |
10 | 351 |
} |
352 |
||
353 |
public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) { |
|
354 |
breakTree = tree; |
|
3144
202fa249dc34
6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents:
2723
diff
changeset
|
355 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
10 | 356 |
try { |
357 |
attribExpr(expr, env); |
|
358 |
} catch (BreakAttr b) { |
|
359 |
return b.env; |
|
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
360 |
} catch (AssertionError ae) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
361 |
if (ae.getCause() instanceof BreakAttr) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
362 |
return ((BreakAttr)(ae.getCause())).env; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
363 |
} else { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
364 |
throw ae; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
365 |
} |
10 | 366 |
} finally { |
367 |
breakTree = null; |
|
368 |
log.useSource(prev); |
|
369 |
} |
|
370 |
return env; |
|
371 |
} |
|
372 |
||
373 |
public Env<AttrContext> attribStatToTree(JCTree stmt, Env<AttrContext> env, JCTree tree) { |
|
374 |
breakTree = tree; |
|
3144
202fa249dc34
6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents:
2723
diff
changeset
|
375 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
10 | 376 |
try { |
377 |
attribStat(stmt, env); |
|
378 |
} catch (BreakAttr b) { |
|
379 |
return b.env; |
|
6587
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
380 |
} catch (AssertionError ae) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
381 |
if (ae.getCause() instanceof BreakAttr) { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
382 |
return ((BreakAttr)(ae.getCause())).env; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
383 |
} else { |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
384 |
throw ae; |
344aa81a3b35
6956462: AssertionError exception thrown in the Compiler Tree API in JDK 7.
sundar
parents:
6582
diff
changeset
|
385 |
} |
10 | 386 |
} finally { |
387 |
breakTree = null; |
|
388 |
log.useSource(prev); |
|
389 |
} |
|
390 |
return env; |
|
391 |
} |
|
392 |
||
393 |
private JCTree breakTree = null; |
|
394 |
||
395 |
private static class BreakAttr extends RuntimeException { |
|
396 |
static final long serialVersionUID = -6924771130405446405L; |
|
397 |
private Env<AttrContext> env; |
|
398 |
private BreakAttr(Env<AttrContext> env) { |
|
399 |
this.env = env; |
|
400 |
} |
|
401 |
} |
|
402 |
||
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
403 |
class ResultInfo { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
404 |
int pkind; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
405 |
Type pt; |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
406 |
CheckContext checkContext; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
407 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
408 |
ResultInfo(int pkind, Type pt) { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
409 |
this(pkind, pt, chk.basicHandler); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
410 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
411 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
412 |
protected ResultInfo(int pkind, Type pt, CheckContext checkContext) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
413 |
this.pkind = pkind; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
414 |
this.pt = pt; |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
415 |
this.checkContext = checkContext; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
416 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
417 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
418 |
protected Type check(DiagnosticPosition pos, Type found) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
419 |
return chk.checkType(pos, found, pt, checkContext); |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
420 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
421 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
422 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
423 |
private final ResultInfo statInfo; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
424 |
private final ResultInfo varInfo; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
425 |
private final ResultInfo unknownExprInfo; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
426 |
private final ResultInfo unknownTypeInfo; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
427 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
428 |
Type pt() { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
429 |
return resultInfo.pt; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
430 |
} |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
431 |
|
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
432 |
int pkind() { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
433 |
return resultInfo.pkind; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
434 |
} |
10 | 435 |
|
436 |
/* ************************************************************************ |
|
437 |
* Visitor methods |
|
438 |
*************************************************************************/ |
|
439 |
||
440 |
/** Visitor argument: the current environment. |
|
441 |
*/ |
|
442 |
Env<AttrContext> env; |
|
443 |
||
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
444 |
/** Visitor argument: the currently expected attribution result. |
10 | 445 |
*/ |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
446 |
ResultInfo resultInfo; |
10 | 447 |
|
448 |
/** Visitor result: the computed type. |
|
449 |
*/ |
|
450 |
Type result; |
|
451 |
||
452 |
/** Visitor method: attribute a tree, catching any completion failure |
|
453 |
* exceptions. Return the tree's type. |
|
454 |
* |
|
455 |
* @param tree The tree to be visited. |
|
456 |
* @param env The environment visitor argument. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
457 |
* @param resultInfo The result info visitor argument. |
10 | 458 |
*/ |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
459 |
private Type attribTree(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { |
10 | 460 |
Env<AttrContext> prevEnv = this.env; |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
461 |
ResultInfo prevResult = this.resultInfo; |
10 | 462 |
try { |
463 |
this.env = env; |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
464 |
this.resultInfo = resultInfo; |
10 | 465 |
tree.accept(this); |
466 |
if (tree == breakTree) |
|
467 |
throw new BreakAttr(env); |
|
468 |
return result; |
|
469 |
} catch (CompletionFailure ex) { |
|
470 |
tree.type = syms.errType; |
|
471 |
return chk.completionError(tree.pos(), ex); |
|
472 |
} finally { |
|
473 |
this.env = prevEnv; |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
474 |
this.resultInfo = prevResult; |
10 | 475 |
} |
476 |
} |
|
477 |
||
478 |
/** Derived visitor method: attribute an expression tree. |
|
479 |
*/ |
|
480 |
public Type attribExpr(JCTree tree, Env<AttrContext> env, Type pt) { |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
481 |
return attribTree(tree, env, new ResultInfo(VAL, pt.tag != ERROR ? pt : Type.noType)); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
482 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
483 |
|
10 | 484 |
/** Derived visitor method: attribute an expression tree with |
485 |
* no constraints on the computed type. |
|
486 |
*/ |
|
487 |
Type attribExpr(JCTree tree, Env<AttrContext> env) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
488 |
return attribTree(tree, env, unknownExprInfo); |
10 | 489 |
} |
490 |
||
491 |
/** Derived visitor method: attribute a type tree. |
|
492 |
*/ |
|
493 |
Type attribType(JCTree tree, Env<AttrContext> env) { |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
494 |
Type result = attribType(tree, env, Type.noType); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
495 |
return result; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
496 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
497 |
|
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
498 |
/** Derived visitor method: attribute a type tree. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
499 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
500 |
Type attribType(JCTree tree, Env<AttrContext> env, Type pt) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
501 |
Type result = attribTree(tree, env, new ResultInfo(TYP, pt)); |
10 | 502 |
return result; |
503 |
} |
|
504 |
||
505 |
/** Derived visitor method: attribute a statement or definition tree. |
|
506 |
*/ |
|
507 |
public Type attribStat(JCTree tree, Env<AttrContext> env) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
508 |
return attribTree(tree, env, statInfo); |
10 | 509 |
} |
510 |
||
511 |
/** Attribute a list of expressions, returning a list of types. |
|
512 |
*/ |
|
513 |
List<Type> attribExprs(List<JCExpression> trees, Env<AttrContext> env, Type pt) { |
|
514 |
ListBuffer<Type> ts = new ListBuffer<Type>(); |
|
515 |
for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) |
|
516 |
ts.append(attribExpr(l.head, env, pt)); |
|
517 |
return ts.toList(); |
|
518 |
} |
|
519 |
||
520 |
/** Attribute a list of statements, returning nothing. |
|
521 |
*/ |
|
522 |
<T extends JCTree> void attribStats(List<T> trees, Env<AttrContext> env) { |
|
523 |
for (List<T> l = trees; l.nonEmpty(); l = l.tail) |
|
524 |
attribStat(l.head, env); |
|
525 |
} |
|
526 |
||
527 |
/** Attribute the arguments in a method call, returning a list of types. |
|
528 |
*/ |
|
529 |
List<Type> attribArgs(List<JCExpression> trees, Env<AttrContext> env) { |
|
530 |
ListBuffer<Type> argtypes = new ListBuffer<Type>(); |
|
531 |
for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) |
|
532 |
argtypes.append(chk.checkNonVoid( |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
533 |
l.head.pos(), types.upperBound(attribExpr(l.head, env, Infer.anyPoly)))); |
10 | 534 |
return argtypes.toList(); |
535 |
} |
|
536 |
||
537 |
/** Attribute a type argument list, returning a list of types. |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
538 |
* Caller is responsible for calling checkRefTypes. |
10 | 539 |
*/ |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
540 |
List<Type> attribAnyTypes(List<JCExpression> trees, Env<AttrContext> env) { |
10 | 541 |
ListBuffer<Type> argtypes = new ListBuffer<Type>(); |
542 |
for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
543 |
argtypes.append(attribType(l.head, env)); |
10 | 544 |
return argtypes.toList(); |
545 |
} |
|
546 |
||
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
547 |
/** Attribute a type argument list, returning a list of types. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
548 |
* Check that all the types are references. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
549 |
*/ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
550 |
List<Type> attribTypes(List<JCExpression> trees, Env<AttrContext> env) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
551 |
List<Type> types = attribAnyTypes(trees, env); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
552 |
return chk.checkRefTypes(trees, types); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
553 |
} |
10 | 554 |
|
555 |
/** |
|
556 |
* Attribute type variables (of generic classes or methods). |
|
557 |
* Compound types are attributed later in attribBounds. |
|
558 |
* @param typarams the type variables to enter |
|
559 |
* @param env the current environment |
|
560 |
*/ |
|
561 |
void attribTypeVariables(List<JCTypeParameter> typarams, Env<AttrContext> env) { |
|
562 |
for (JCTypeParameter tvar : typarams) { |
|
563 |
TypeVar a = (TypeVar)tvar.type; |
|
661
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
564 |
a.tsym.flags_field |= UNATTRIBUTED; |
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
565 |
a.bound = Type.noType; |
10 | 566 |
if (!tvar.bounds.isEmpty()) { |
567 |
List<Type> bounds = List.of(attribType(tvar.bounds.head, env)); |
|
568 |
for (JCExpression bound : tvar.bounds.tail) |
|
569 |
bounds = bounds.prepend(attribType(bound, env)); |
|
570 |
types.setBounds(a, bounds.reverse()); |
|
571 |
} else { |
|
572 |
// if no bounds are given, assume a single bound of |
|
573 |
// java.lang.Object. |
|
574 |
types.setBounds(a, List.of(syms.objectType)); |
|
575 |
} |
|
661
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
576 |
a.tsym.flags_field &= ~UNATTRIBUTED; |
10 | 577 |
} |
578 |
for (JCTypeParameter tvar : typarams) |
|
579 |
chk.checkNonCyclic(tvar.pos(), (TypeVar)tvar.type); |
|
580 |
attribStats(typarams, env); |
|
661
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
581 |
} |
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
582 |
|
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
583 |
void attribBounds(List<JCTypeParameter> typarams) { |
10 | 584 |
for (JCTypeParameter typaram : typarams) { |
585 |
Type bound = typaram.type.getUpperBound(); |
|
586 |
if (bound != null && bound.tsym instanceof ClassSymbol) { |
|
587 |
ClassSymbol c = (ClassSymbol)bound.tsym; |
|
588 |
if ((c.flags_field & COMPOUND) != 0) { |
|
8032 | 589 |
Assert.check((c.flags_field & UNATTRIBUTED) != 0, c); |
10 | 590 |
attribClass(typaram.pos(), c); |
591 |
} |
|
592 |
} |
|
593 |
} |
|
594 |
} |
|
595 |
||
596 |
/** |
|
597 |
* Attribute the type references in a list of annotations. |
|
598 |
*/ |
|
599 |
void attribAnnotationTypes(List<JCAnnotation> annotations, |
|
600 |
Env<AttrContext> env) { |
|
601 |
for (List<JCAnnotation> al = annotations; al.nonEmpty(); al = al.tail) { |
|
602 |
JCAnnotation a = al.head; |
|
603 |
attribType(a.annotationType, env); |
|
604 |
} |
|
605 |
} |
|
606 |
||
8225 | 607 |
/** |
608 |
* Attribute a "lazy constant value". |
|
609 |
* @param env The env for the const value |
|
610 |
* @param initializer The initializer for the const value |
|
611 |
* @param type The expected type, or null |
|
612 |
* @see VarSymbol#setlazyConstValue |
|
613 |
*/ |
|
614 |
public Object attribLazyConstantValue(Env<AttrContext> env, |
|
615 |
JCTree.JCExpression initializer, |
|
616 |
Type type) { |
|
617 |
||
618 |
// in case no lint value has been set up for this env, scan up |
|
619 |
// env stack looking for smallest enclosing env for which it is set. |
|
620 |
Env<AttrContext> lintEnv = env; |
|
621 |
while (lintEnv.info.lint == null) |
|
622 |
lintEnv = lintEnv.next; |
|
623 |
||
624 |
// Having found the enclosing lint value, we can initialize the lint value for this class |
|
10459
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
625 |
// ... but ... |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
626 |
// There's a problem with evaluating annotations in the right order, such that |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
627 |
// env.info.enclVar.attributes_field might not yet have been evaluated, and so might be |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
628 |
// null. In that case, calling augment will throw an NPE. To avoid this, for now we |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
629 |
// revert to the jdk 6 behavior and ignore the (unevaluated) attributes. |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
630 |
if (env.info.enclVar.attributes_field == null) |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
631 |
env.info.lint = lintEnv.info.lint; |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
632 |
else |
3908f37df0fc
7073508: Regression: NullPointerException at com.sun.tools.javac.code.Lint$AugmentVisitor.augment
jjg
parents:
10198
diff
changeset
|
633 |
env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.attributes_field, env.info.enclVar.flags()); |
8225 | 634 |
|
635 |
Lint prevLint = chk.setLint(env.info.lint); |
|
636 |
JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); |
|
637 |
||
638 |
try { |
|
639 |
Type itype = attribExpr(initializer, env, type); |
|
640 |
if (itype.constValue() != null) |
|
641 |
return coerce(itype, type).constValue(); |
|
642 |
else |
|
643 |
return null; |
|
644 |
} finally { |
|
645 |
env.info.lint = prevLint; |
|
646 |
log.useSource(prevSource); |
|
647 |
} |
|
648 |
} |
|
649 |
||
10 | 650 |
/** Attribute type reference in an `extends' or `implements' clause. |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
651 |
* Supertypes of anonymous inner classes are usually already attributed. |
10 | 652 |
* |
653 |
* @param tree The tree making up the type reference. |
|
654 |
* @param env The environment current at the reference. |
|
655 |
* @param classExpected true if only a class is expected here. |
|
656 |
* @param interfaceExpected true if only an interface is expected here. |
|
657 |
*/ |
|
658 |
Type attribBase(JCTree tree, |
|
659 |
Env<AttrContext> env, |
|
660 |
boolean classExpected, |
|
661 |
boolean interfaceExpected, |
|
662 |
boolean checkExtensible) { |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
663 |
Type t = tree.type != null ? |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
664 |
tree.type : |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
665 |
attribType(tree, env); |
10 | 666 |
return checkBase(t, tree, env, classExpected, interfaceExpected, checkExtensible); |
667 |
} |
|
668 |
Type checkBase(Type t, |
|
669 |
JCTree tree, |
|
670 |
Env<AttrContext> env, |
|
671 |
boolean classExpected, |
|
672 |
boolean interfaceExpected, |
|
673 |
boolean checkExtensible) { |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6351
diff
changeset
|
674 |
if (t.isErroneous()) |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6351
diff
changeset
|
675 |
return t; |
10 | 676 |
if (t.tag == TYPEVAR && !classExpected && !interfaceExpected) { |
677 |
// check that type variable is already visible |
|
678 |
if (t.getUpperBound() == null) { |
|
679 |
log.error(tree.pos(), "illegal.forward.ref"); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
680 |
return types.createErrorType(t); |
10 | 681 |
} |
682 |
} else { |
|
683 |
t = chk.checkClassType(tree.pos(), t, checkExtensible|!allowGenerics); |
|
684 |
} |
|
685 |
if (interfaceExpected && (t.tsym.flags() & INTERFACE) == 0) { |
|
686 |
log.error(tree.pos(), "intf.expected.here"); |
|
687 |
// return errType is necessary since otherwise there might |
|
688 |
// be undetected cycles which cause attribution to loop |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
689 |
return types.createErrorType(t); |
10 | 690 |
} else if (checkExtensible && |
691 |
classExpected && |
|
692 |
(t.tsym.flags() & INTERFACE) != 0) { |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6351
diff
changeset
|
693 |
log.error(tree.pos(), "no.intf.expected.here"); |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
694 |
return types.createErrorType(t); |
10 | 695 |
} |
696 |
if (checkExtensible && |
|
697 |
((t.tsym.flags() & FINAL) != 0)) { |
|
698 |
log.error(tree.pos(), |
|
699 |
"cant.inherit.from.final", t.tsym); |
|
700 |
} |
|
701 |
chk.checkNonCyclic(tree.pos(), t); |
|
702 |
return t; |
|
703 |
} |
|
704 |
||
705 |
public void visitClassDef(JCClassDecl tree) { |
|
706 |
// Local classes have not been entered yet, so we need to do it now: |
|
707 |
if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) |
|
708 |
enter.classEnter(tree, env); |
|
709 |
||
710 |
ClassSymbol c = tree.sym; |
|
711 |
if (c == null) { |
|
712 |
// exit in case something drastic went wrong during enter. |
|
713 |
result = null; |
|
714 |
} else { |
|
715 |
// make sure class has been completed: |
|
716 |
c.complete(); |
|
717 |
||
718 |
// If this class appears as an anonymous class |
|
719 |
// in a superclass constructor call where |
|
720 |
// no explicit outer instance is given, |
|
721 |
// disable implicit outer instance from being passed. |
|
722 |
// (This would be an illegal access to "this before super"). |
|
723 |
if (env.info.isSelfCall && |
|
10950 | 724 |
env.tree.hasTag(NEWCLASS) && |
10 | 725 |
((JCNewClass) env.tree).encl == null) |
726 |
{ |
|
727 |
c.flags_field |= NOOUTERTHIS; |
|
728 |
} |
|
729 |
attribClass(tree.pos(), c); |
|
730 |
result = tree.type = c.type; |
|
731 |
} |
|
732 |
} |
|
733 |
||
734 |
public void visitMethodDef(JCMethodDecl tree) { |
|
735 |
MethodSymbol m = tree.sym; |
|
736 |
||
737 |
Lint lint = env.info.lint.augment(m.attributes_field, m.flags()); |
|
738 |
Lint prevLint = chk.setLint(lint); |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
739 |
MethodSymbol prevMethod = chk.setMethod(m); |
10 | 740 |
try { |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
741 |
deferredLintHandler.flush(tree.pos()); |
10 | 742 |
chk.checkDeprecatedAnnotation(tree.pos(), m); |
743 |
||
661
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
744 |
attribBounds(tree.typarams); |
10 | 745 |
|
746 |
// If we override any other methods, check that we do so properly. |
|
747 |
// JLS ??? |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
748 |
if (m.isStatic()) { |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
749 |
chk.checkHideClashes(tree.pos(), env.enclClass.type, m); |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
750 |
} else { |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
751 |
chk.checkOverrideClashes(tree.pos(), env.enclClass.type, m); |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8239
diff
changeset
|
752 |
} |
10 | 753 |
chk.checkOverride(tree, m); |
754 |
||
755 |
// Create a new environment with local scope |
|
756 |
// for attributing the method. |
|
757 |
Env<AttrContext> localEnv = memberEnter.methodEnv(tree, env); |
|
758 |
||
759 |
localEnv.info.lint = lint; |
|
760 |
||
761 |
// Enter all type parameters into the local method scope. |
|
762 |
for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) |
|
763 |
localEnv.info.scope.enterIfAbsent(l.head.type.tsym); |
|
764 |
||
765 |
ClassSymbol owner = env.enclClass.sym; |
|
766 |
if ((owner.flags() & ANNOTATION) != 0 && |
|
767 |
tree.params.nonEmpty()) |
|
768 |
log.error(tree.params.head.pos(), |
|
769 |
"intf.annotation.members.cant.have.params"); |
|
770 |
||
771 |
// Attribute all value parameters. |
|
772 |
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { |
|
773 |
attribStat(l.head, localEnv); |
|
774 |
} |
|
775 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
776 |
chk.checkVarargsMethodDecl(localEnv, tree); |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5654
diff
changeset
|
777 |
|
10 | 778 |
// Check that type parameters are well-formed. |
1358 | 779 |
chk.validate(tree.typarams, localEnv); |
10 | 780 |
|
781 |
// Check that result type is well-formed. |
|
1358 | 782 |
chk.validate(tree.restype, localEnv); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
783 |
|
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
784 |
// annotation method checks |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
785 |
if ((owner.flags() & ANNOTATION) != 0) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
786 |
// annotation method cannot have throws clause |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
787 |
if (tree.thrown.nonEmpty()) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
788 |
log.error(tree.thrown.head.pos(), |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
789 |
"throws.not.allowed.in.intf.annotation"); |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
790 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
791 |
// annotation method cannot declare type-parameters |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
792 |
if (tree.typarams.nonEmpty()) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
793 |
log.error(tree.typarams.head.pos(), |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
794 |
"intf.annotation.members.cant.have.type.params"); |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
795 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
796 |
// validate annotation method's return type (could be an annotation type) |
10 | 797 |
chk.validateAnnotationType(tree.restype); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
798 |
// ensure that annotation method does not clash with members of Object/Annotation |
10 | 799 |
chk.validateAnnotationMethod(tree.pos(), m); |
800 |
||
6347
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
801 |
if (tree.defaultValue != null) { |
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
802 |
// if default value is an annotation, check it is a well-formed |
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
803 |
// annotation value (e.g. no duplicate values, no missing values, etc.) |
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
804 |
chk.validateAnnotationTree(tree.defaultValue); |
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6344
diff
changeset
|
805 |
} |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
806 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6154
diff
changeset
|
807 |
|
10 | 808 |
for (List<JCExpression> l = tree.thrown; l.nonEmpty(); l = l.tail) |
809 |
chk.checkType(l.head.pos(), l.head.type, syms.throwableType); |
|
810 |
||
811 |
if (tree.body == null) { |
|
812 |
// Empty bodies are only allowed for |
|
813 |
// abstract, native, or interface methods, or for methods |
|
814 |
// in a retrofit signature class. |
|
815 |
if ((owner.flags() & INTERFACE) == 0 && |
|
816 |
(tree.mods.flags & (ABSTRACT | NATIVE)) == 0 && |
|
817 |
!relax) |
|
818 |
log.error(tree.pos(), "missing.meth.body.or.decl.abstract"); |
|
819 |
if (tree.defaultValue != null) { |
|
820 |
if ((owner.flags() & ANNOTATION) == 0) |
|
821 |
log.error(tree.pos(), |
|
822 |
"default.allowed.in.intf.annotation.member"); |
|
823 |
} |
|
824 |
} else if ((owner.flags() & INTERFACE) != 0) { |
|
825 |
log.error(tree.body.pos(), "intf.meth.cant.have.body"); |
|
826 |
} else if ((tree.mods.flags & ABSTRACT) != 0) { |
|
827 |
log.error(tree.pos(), "abstract.meth.cant.have.body"); |
|
828 |
} else if ((tree.mods.flags & NATIVE) != 0) { |
|
829 |
log.error(tree.pos(), "native.meth.cant.have.body"); |
|
830 |
} else { |
|
831 |
// Add an implicit super() call unless an explicit call to |
|
832 |
// super(...) or this(...) is given |
|
833 |
// or we are compiling class java.lang.Object. |
|
834 |
if (tree.name == names.init && owner.type != syms.objectType) { |
|
835 |
JCBlock body = tree.body; |
|
836 |
if (body.stats.isEmpty() || |
|
837 |
!TreeInfo.isSelfCall(body.stats.head)) { |
|
838 |
body.stats = body.stats. |
|
839 |
prepend(memberEnter.SuperCall(make.at(body.pos), |
|
840 |
List.<Type>nil(), |
|
841 |
List.<JCVariableDecl>nil(), |
|
842 |
false)); |
|
843 |
} else if ((env.enclClass.sym.flags() & ENUM) != 0 && |
|
844 |
(tree.mods.flags & GENERATEDCONSTR) == 0 && |
|
845 |
TreeInfo.isSuperCall(body.stats.head)) { |
|
846 |
// enum constructors are not allowed to call super |
|
847 |
// directly, so make sure there aren't any super calls |
|
848 |
// in enum constructors, except in the compiler |
|
849 |
// generated one. |
|
850 |
log.error(tree.body.stats.head.pos(), |
|
851 |
"call.to.super.not.allowed.in.enum.ctor", |
|
852 |
env.enclClass.sym); |
|
853 |
} |
|
854 |
} |
|
855 |
||
856 |
// Attribute method body. |
|
857 |
attribStat(tree.body, localEnv); |
|
858 |
} |
|
859 |
localEnv.info.scope.leave(); |
|
860 |
result = tree.type = m.type; |
|
861 |
chk.validateAnnotations(tree.mods.annotations, m); |
|
862 |
} |
|
863 |
finally { |
|
864 |
chk.setLint(prevLint); |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
865 |
chk.setMethod(prevMethod); |
10 | 866 |
} |
867 |
} |
|
868 |
||
869 |
public void visitVarDef(JCVariableDecl tree) { |
|
870 |
// Local variables have not been entered yet, so we need to do it now: |
|
871 |
if (env.info.scope.owner.kind == MTH) { |
|
872 |
if (tree.sym != null) { |
|
873 |
// parameters have already been entered |
|
874 |
env.info.scope.enter(tree.sym); |
|
875 |
} else { |
|
876 |
memberEnter.memberEnter(tree, env); |
|
877 |
annotate.flush(); |
|
878 |
} |
|
7203
1153590927f7
6993963: Project Coin: Use precise exception analysis for effectively final catch parameters
mcimadamore
parents:
7081
diff
changeset
|
879 |
tree.sym.flags_field |= EFFECTIVELY_FINAL; |
10 | 880 |
} |
881 |
||
882 |
VarSymbol v = tree.sym; |
|
883 |
Lint lint = env.info.lint.augment(v.attributes_field, v.flags()); |
|
884 |
Lint prevLint = chk.setLint(lint); |
|
885 |
||
1538
3cbbc9424f43
6763518: Impossible to suppress raw-type warnings
mcimadamore
parents:
1534
diff
changeset
|
886 |
// Check that the variable's declared type is well-formed. |
3cbbc9424f43
6763518: Impossible to suppress raw-type warnings
mcimadamore
parents:
1534
diff
changeset
|
887 |
chk.validate(tree.vartype, env); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
888 |
deferredLintHandler.flush(tree.pos()); |
1538
3cbbc9424f43
6763518: Impossible to suppress raw-type warnings
mcimadamore
parents:
1534
diff
changeset
|
889 |
|
10 | 890 |
try { |
891 |
chk.checkDeprecatedAnnotation(tree.pos(), v); |
|
892 |
||
893 |
if (tree.init != null) { |
|
10950 | 894 |
if ((v.flags_field & FINAL) != 0 && !tree.init.hasTag(NEWCLASS)) { |
10 | 895 |
// In this case, `v' is final. Ensure that it's initializer is |
896 |
// evaluated. |
|
897 |
v.getConstValue(); // ensure initializer is evaluated |
|
898 |
} else { |
|
899 |
// Attribute initializer in a new environment |
|
900 |
// with the declared variable as owner. |
|
901 |
// Check that initializer conforms to variable's declared type. |
|
902 |
Env<AttrContext> initEnv = memberEnter.initEnv(tree, env); |
|
903 |
initEnv.info.lint = lint; |
|
904 |
// In order to catch self-references, we set the variable's |
|
905 |
// declaration position to maximal possible value, effectively |
|
906 |
// marking the variable as undefined. |
|
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
907 |
initEnv.info.enclVar = v; |
10 | 908 |
attribExpr(tree.init, initEnv, v.type); |
909 |
} |
|
910 |
} |
|
911 |
result = tree.type = v.type; |
|
912 |
chk.validateAnnotations(tree.mods.annotations, v); |
|
913 |
} |
|
914 |
finally { |
|
915 |
chk.setLint(prevLint); |
|
916 |
} |
|
917 |
} |
|
918 |
||
919 |
public void visitSkip(JCSkip tree) { |
|
920 |
result = null; |
|
921 |
} |
|
922 |
||
923 |
public void visitBlock(JCBlock tree) { |
|
924 |
if (env.info.scope.owner.kind == TYP) { |
|
925 |
// Block is a static or instance initializer; |
|
926 |
// let the owner of the environment be a freshly |
|
927 |
// created BLOCK-method. |
|
928 |
Env<AttrContext> localEnv = |
|
929 |
env.dup(tree, env.info.dup(env.info.scope.dupUnshared())); |
|
930 |
localEnv.info.scope.owner = |
|
931 |
new MethodSymbol(tree.flags | BLOCK, names.empty, null, |
|
932 |
env.info.scope.owner); |
|
933 |
if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; |
|
934 |
attribStats(tree.stats, localEnv); |
|
935 |
} else { |
|
936 |
// Create a new local environment with a local scope. |
|
937 |
Env<AttrContext> localEnv = |
|
938 |
env.dup(tree, env.info.dup(env.info.scope.dup())); |
|
939 |
attribStats(tree.stats, localEnv); |
|
940 |
localEnv.info.scope.leave(); |
|
941 |
} |
|
942 |
result = null; |
|
943 |
} |
|
944 |
||
945 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
946 |
attribStat(tree.body, env.dup(tree)); |
|
947 |
attribExpr(tree.cond, env, syms.booleanType); |
|
948 |
result = null; |
|
949 |
} |
|
950 |
||
951 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
952 |
attribExpr(tree.cond, env, syms.booleanType); |
|
953 |
attribStat(tree.body, env.dup(tree)); |
|
954 |
result = null; |
|
955 |
} |
|
956 |
||
957 |
public void visitForLoop(JCForLoop tree) { |
|
958 |
Env<AttrContext> loopEnv = |
|
959 |
env.dup(env.tree, env.info.dup(env.info.scope.dup())); |
|
960 |
attribStats(tree.init, loopEnv); |
|
961 |
if (tree.cond != null) attribExpr(tree.cond, loopEnv, syms.booleanType); |
|
962 |
loopEnv.tree = tree; // before, we were not in loop! |
|
963 |
attribStats(tree.step, loopEnv); |
|
964 |
attribStat(tree.body, loopEnv); |
|
965 |
loopEnv.info.scope.leave(); |
|
966 |
result = null; |
|
967 |
} |
|
968 |
||
969 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
970 |
Env<AttrContext> loopEnv = |
|
971 |
env.dup(env.tree, env.info.dup(env.info.scope.dup())); |
|
972 |
attribStat(tree.var, loopEnv); |
|
973 |
Type exprType = types.upperBound(attribExpr(tree.expr, loopEnv)); |
|
974 |
chk.checkNonVoid(tree.pos(), exprType); |
|
975 |
Type elemtype = types.elemtype(exprType); // perhaps expr is an array? |
|
976 |
if (elemtype == null) { |
|
977 |
// or perhaps expr implements Iterable<T>? |
|
978 |
Type base = types.asSuper(exprType, syms.iterableType.tsym); |
|
979 |
if (base == null) { |
|
8045 | 980 |
log.error(tree.expr.pos(), |
981 |
"foreach.not.applicable.to.type", |
|
982 |
exprType, |
|
983 |
diags.fragment("type.req.array.or.iterable")); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
984 |
elemtype = types.createErrorType(exprType); |
10 | 985 |
} else { |
986 |
List<Type> iterableParams = base.allparams(); |
|
987 |
elemtype = iterableParams.isEmpty() |
|
988 |
? syms.objectType |
|
989 |
: types.upperBound(iterableParams.head); |
|
990 |
} |
|
991 |
} |
|
992 |
chk.checkType(tree.expr.pos(), elemtype, tree.var.sym.type); |
|
993 |
loopEnv.tree = tree; // before, we were not in loop! |
|
994 |
attribStat(tree.body, loopEnv); |
|
995 |
loopEnv.info.scope.leave(); |
|
996 |
result = null; |
|
997 |
} |
|
998 |
||
999 |
public void visitLabelled(JCLabeledStatement tree) { |
|
1000 |
// Check that label is not used in an enclosing statement |
|
1001 |
Env<AttrContext> env1 = env; |
|
10950 | 1002 |
while (env1 != null && !env1.tree.hasTag(CLASSDEF)) { |
1003 |
if (env1.tree.hasTag(LABELLED) && |
|
10 | 1004 |
((JCLabeledStatement) env1.tree).label == tree.label) { |
1005 |
log.error(tree.pos(), "label.already.in.use", |
|
1006 |
tree.label); |
|
1007 |
break; |
|
1008 |
} |
|
1009 |
env1 = env1.next; |
|
1010 |
} |
|
1011 |
||
1012 |
attribStat(tree.body, env.dup(tree)); |
|
1013 |
result = null; |
|
1014 |
} |
|
1015 |
||
1016 |
public void visitSwitch(JCSwitch tree) { |
|
1017 |
Type seltype = attribExpr(tree.selector, env); |
|
1018 |
||
1019 |
Env<AttrContext> switchEnv = |
|
1020 |
env.dup(tree, env.info.dup(env.info.scope.dup())); |
|
1021 |
||
1022 |
boolean enumSwitch = |
|
1023 |
allowEnums && |
|
1024 |
(seltype.tsym.flags() & Flags.ENUM) != 0; |
|
4142 | 1025 |
boolean stringSwitch = false; |
1026 |
if (types.isSameType(seltype, syms.stringType)) { |
|
1027 |
if (allowStringsInSwitch) { |
|
1028 |
stringSwitch = true; |
|
1029 |
} else { |
|
1030 |
log.error(tree.selector.pos(), "string.switch.not.supported.in.source", sourceName); |
|
1031 |
} |
|
1032 |
} |
|
1033 |
if (!enumSwitch && !stringSwitch) |
|
10 | 1034 |
seltype = chk.checkType(tree.selector.pos(), seltype, syms.intType); |
1035 |
||
1036 |
// Attribute all cases and |
|
1037 |
// check that there are no duplicate case labels or default clauses. |
|
1038 |
Set<Object> labels = new HashSet<Object>(); // The set of case labels. |
|
1039 |
boolean hasDefault = false; // Is there a default label? |
|
1040 |
for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) { |
|
1041 |
JCCase c = l.head; |
|
1042 |
Env<AttrContext> caseEnv = |
|
1043 |
switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup())); |
|
1044 |
if (c.pat != null) { |
|
1045 |
if (enumSwitch) { |
|
1046 |
Symbol sym = enumConstant(c.pat, seltype); |
|
1047 |
if (sym == null) { |
|
8045 | 1048 |
log.error(c.pat.pos(), "enum.label.must.be.unqualified.enum"); |
10 | 1049 |
} else if (!labels.add(sym)) { |
1050 |
log.error(c.pos(), "duplicate.case.label"); |
|
1051 |
} |
|
1052 |
} else { |
|
1053 |
Type pattype = attribExpr(c.pat, switchEnv, seltype); |
|
1054 |
if (pattype.tag != ERROR) { |
|
1055 |
if (pattype.constValue() == null) { |
|
4142 | 1056 |
log.error(c.pat.pos(), |
1057 |
(stringSwitch ? "string.const.req" : "const.expr.req")); |
|
10 | 1058 |
} else if (labels.contains(pattype.constValue())) { |
1059 |
log.error(c.pos(), "duplicate.case.label"); |
|
1060 |
} else { |
|
1061 |
labels.add(pattype.constValue()); |
|
1062 |
} |
|
1063 |
} |
|
1064 |
} |
|
1065 |
} else if (hasDefault) { |
|
1066 |
log.error(c.pos(), "duplicate.default.label"); |
|
1067 |
} else { |
|
1068 |
hasDefault = true; |
|
1069 |
} |
|
1070 |
attribStats(c.stats, caseEnv); |
|
1071 |
caseEnv.info.scope.leave(); |
|
1072 |
addVars(c.stats, switchEnv.info.scope); |
|
1073 |
} |
|
1074 |
||
1075 |
switchEnv.info.scope.leave(); |
|
1076 |
result = null; |
|
1077 |
} |
|
1078 |
// where |
|
1079 |
/** Add any variables defined in stats to the switch scope. */ |
|
1080 |
private static void addVars(List<JCStatement> stats, Scope switchScope) { |
|
1081 |
for (;stats.nonEmpty(); stats = stats.tail) { |
|
1082 |
JCTree stat = stats.head; |
|
10950 | 1083 |
if (stat.hasTag(VARDEF)) |
10 | 1084 |
switchScope.enter(((JCVariableDecl) stat).sym); |
1085 |
} |
|
1086 |
} |
|
1087 |
// where |
|
1088 |
/** Return the selected enumeration constant symbol, or null. */ |
|
1089 |
private Symbol enumConstant(JCTree tree, Type enumType) { |
|
10950 | 1090 |
if (!tree.hasTag(IDENT)) { |
10 | 1091 |
log.error(tree.pos(), "enum.label.must.be.unqualified.enum"); |
1092 |
return syms.errSymbol; |
|
1093 |
} |
|
1094 |
JCIdent ident = (JCIdent)tree; |
|
1095 |
Name name = ident.name; |
|
1096 |
for (Scope.Entry e = enumType.tsym.members().lookup(name); |
|
1097 |
e.scope != null; e = e.next()) { |
|
1098 |
if (e.sym.kind == VAR) { |
|
1099 |
Symbol s = ident.sym = e.sym; |
|
1100 |
((VarSymbol)s).getConstValue(); // ensure initializer is evaluated |
|
1101 |
ident.type = s.type; |
|
1102 |
return ((s.flags_field & Flags.ENUM) == 0) |
|
1103 |
? null : s; |
|
1104 |
} |
|
1105 |
} |
|
1106 |
return null; |
|
1107 |
} |
|
1108 |
||
1109 |
public void visitSynchronized(JCSynchronized tree) { |
|
1110 |
chk.checkRefType(tree.pos(), attribExpr(tree.lock, env)); |
|
1111 |
attribStat(tree.body, env); |
|
1112 |
result = null; |
|
1113 |
} |
|
1114 |
||
1115 |
public void visitTry(JCTry tree) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1116 |
// Create a new local environment with a local |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1117 |
Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup())); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1118 |
boolean isTryWithResource = tree.resources.nonEmpty(); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1119 |
// Create a nested environment for attributing the try block if needed |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1120 |
Env<AttrContext> tryEnv = isTryWithResource ? |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1121 |
env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) : |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1122 |
localEnv; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1123 |
// Attribute resource declarations |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1124 |
for (JCTree resource : tree.resources) { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1125 |
CheckContext twrContext = new Check.NestedCheckContext(resultInfo.checkContext) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1126 |
@Override |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1127 |
public void report(DiagnosticPosition pos, Type found, Type req, JCDiagnostic details) { |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1128 |
chk.basicHandler.report(pos, found, req, diags.fragment("try.not.applicable.to.type", found)); |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1129 |
} |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1130 |
}; |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1131 |
ResultInfo twrResult = new ResultInfo(VAL, syms.autoCloseableType, twrContext); |
10950 | 1132 |
if (resource.hasTag(VARDEF)) { |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1133 |
attribStat(resource, tryEnv); |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1134 |
twrResult.check(resource, resource.type); |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1135 |
|
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1136 |
//check that resource type cannot throw InterruptedException |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1137 |
checkAutoCloseable(resource.pos(), localEnv, resource.type); |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1138 |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1139 |
VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1140 |
var.setData(ElementKind.RESOURCE_VARIABLE); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1141 |
} else { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1142 |
attribTree(resource, tryEnv, twrResult); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1143 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1144 |
} |
10 | 1145 |
// Attribute body |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1146 |
attribStat(tree.body, tryEnv); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1147 |
if (isTryWithResource) |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1148 |
tryEnv.info.scope.leave(); |
10 | 1149 |
|
1150 |
// Attribute catch clauses |
|
1151 |
for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { |
|
1152 |
JCCatch c = l.head; |
|
1153 |
Env<AttrContext> catchEnv = |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1154 |
localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup())); |
10 | 1155 |
Type ctype = attribStat(c.param, catchEnv); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5489
diff
changeset
|
1156 |
if (TreeInfo.isMultiCatch(c)) { |
7203
1153590927f7
6993963: Project Coin: Use precise exception analysis for effectively final catch parameters
mcimadamore
parents:
7081
diff
changeset
|
1157 |
//multi-catch parameter is implicitly marked as final |
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
9079
diff
changeset
|
1158 |
c.param.sym.flags_field |= FINAL | UNION; |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5489
diff
changeset
|
1159 |
} |
7073
c27644ae5855
6993301: catch parameters do not have correct kind (i.e. ElementKind.EXCEPTION_PARAMETER)
jjg
parents:
6721
diff
changeset
|
1160 |
if (c.param.sym.kind == Kinds.VAR) { |
10 | 1161 |
c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER); |
1162 |
} |
|
1163 |
chk.checkType(c.param.vartype.pos(), |
|
1164 |
chk.checkClassType(c.param.vartype.pos(), ctype), |
|
1165 |
syms.throwableType); |
|
1166 |
attribStat(c.body, catchEnv); |
|
1167 |
catchEnv.info.scope.leave(); |
|
1168 |
} |
|
1169 |
||
1170 |
// Attribute finalizer |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1171 |
if (tree.finalizer != null) attribStat(tree.finalizer, localEnv); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1172 |
|
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
1173 |
localEnv.info.scope.leave(); |
10 | 1174 |
result = null; |
1175 |
} |
|
1176 |
||
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1177 |
void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) { |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1178 |
if (!resource.isErroneous() && |
12013
fdcc73079b81
7148025: javac should not warn about InterrupttedException on the declaration of AutoCloseable itself
darcy
parents:
11144
diff
changeset
|
1179 |
types.asSuper(resource, syms.autoCloseableType.tsym) != null && |
fdcc73079b81
7148025: javac should not warn about InterrupttedException on the declaration of AutoCloseable itself
darcy
parents:
11144
diff
changeset
|
1180 |
!types.isSameType(resource, syms.autoCloseableType)) { // Don't emit warning for AutoCloseable itself |
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1181 |
Symbol close = syms.noSymbol; |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1182 |
boolean prevDeferDiags = log.deferDiagnostics; |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1183 |
Queue<JCDiagnostic> prevDeferredDiags = log.deferredDiagnostics; |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1184 |
try { |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1185 |
log.deferDiagnostics = true; |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1186 |
log.deferredDiagnostics = ListBuffer.lb(); |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1187 |
close = rs.resolveQualifiedMethod(pos, |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1188 |
env, |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1189 |
resource, |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1190 |
names.close, |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1191 |
List.<Type>nil(), |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1192 |
List.<Type>nil()); |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1193 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1194 |
finally { |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1195 |
log.deferDiagnostics = prevDeferDiags; |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1196 |
log.deferredDiagnostics = prevDeferredDiags; |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1197 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1198 |
if (close.kind == MTH && |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1199 |
close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1200 |
chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) && |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1201 |
env.info.lint.isEnabled(LintCategory.TRY)) { |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1202 |
log.warning(LintCategory.TRY, pos, "try.resource.throws.interrupted.exc", resource); |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1203 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1204 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1205 |
} |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
1206 |
|
10 | 1207 |
public void visitConditional(JCConditional tree) { |
1208 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1209 |
attribExpr(tree.truepart, env); |
|
1210 |
attribExpr(tree.falsepart, env); |
|
1211 |
result = check(tree, |
|
1212 |
capture(condType(tree.pos(), tree.cond.type, |
|
1213 |
tree.truepart.type, tree.falsepart.type)), |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1214 |
VAL, resultInfo); |
10 | 1215 |
} |
1216 |
//where |
|
1217 |
/** Compute the type of a conditional expression, after |
|
1218 |
* checking that it exists. See Spec 15.25. |
|
1219 |
* |
|
1220 |
* @param pos The source position to be used for |
|
1221 |
* error diagnostics. |
|
1222 |
* @param condtype The type of the expression's condition. |
|
1223 |
* @param thentype The type of the expression's then-part. |
|
1224 |
* @param elsetype The type of the expression's else-part. |
|
1225 |
*/ |
|
1226 |
private Type condType(DiagnosticPosition pos, |
|
1227 |
Type condtype, |
|
1228 |
Type thentype, |
|
1229 |
Type elsetype) { |
|
1230 |
Type ctype = condType1(pos, condtype, thentype, elsetype); |
|
1231 |
||
1232 |
// If condition and both arms are numeric constants, |
|
1233 |
// evaluate at compile-time. |
|
1234 |
return ((condtype.constValue() != null) && |
|
1235 |
(thentype.constValue() != null) && |
|
1236 |
(elsetype.constValue() != null)) |
|
1237 |
? cfolder.coerce(condtype.isTrue()?thentype:elsetype, ctype) |
|
1238 |
: ctype; |
|
1239 |
} |
|
1240 |
/** Compute the type of a conditional expression, after |
|
1241 |
* checking that it exists. Does not take into |
|
1242 |
* account the special case where condition and both arms |
|
1243 |
* are constants. |
|
1244 |
* |
|
1245 |
* @param pos The source position to be used for error |
|
1246 |
* diagnostics. |
|
1247 |
* @param condtype The type of the expression's condition. |
|
1248 |
* @param thentype The type of the expression's then-part. |
|
1249 |
* @param elsetype The type of the expression's else-part. |
|
1250 |
*/ |
|
1251 |
private Type condType1(DiagnosticPosition pos, Type condtype, |
|
1252 |
Type thentype, Type elsetype) { |
|
1253 |
// If same type, that is the result |
|
1254 |
if (types.isSameType(thentype, elsetype)) |
|
1255 |
return thentype.baseType(); |
|
1256 |
||
1257 |
Type thenUnboxed = (!allowBoxing || thentype.isPrimitive()) |
|
1258 |
? thentype : types.unboxedType(thentype); |
|
1259 |
Type elseUnboxed = (!allowBoxing || elsetype.isPrimitive()) |
|
1260 |
? elsetype : types.unboxedType(elsetype); |
|
1261 |
||
1262 |
// Otherwise, if both arms can be converted to a numeric |
|
1263 |
// type, return the least numeric type that fits both arms |
|
1264 |
// (i.e. return larger of the two, or return int if one |
|
1265 |
// arm is short, the other is char). |
|
1266 |
if (thenUnboxed.isPrimitive() && elseUnboxed.isPrimitive()) { |
|
1267 |
// If one arm has an integer subrange type (i.e., byte, |
|
1268 |
// short, or char), and the other is an integer constant |
|
1269 |
// that fits into the subrange, return the subrange type. |
|
1270 |
if (thenUnboxed.tag < INT && elseUnboxed.tag == INT && |
|
1271 |
types.isAssignable(elseUnboxed, thenUnboxed)) |
|
1272 |
return thenUnboxed.baseType(); |
|
1273 |
if (elseUnboxed.tag < INT && thenUnboxed.tag == INT && |
|
1274 |
types.isAssignable(thenUnboxed, elseUnboxed)) |
|
1275 |
return elseUnboxed.baseType(); |
|
1276 |
||
1277 |
for (int i = BYTE; i < VOID; i++) { |
|
1278 |
Type candidate = syms.typeOfTag[i]; |
|
1279 |
if (types.isSubtype(thenUnboxed, candidate) && |
|
1280 |
types.isSubtype(elseUnboxed, candidate)) |
|
1281 |
return candidate; |
|
1282 |
} |
|
1283 |
} |
|
1284 |
||
1285 |
// Those were all the cases that could result in a primitive |
|
1286 |
if (allowBoxing) { |
|
1287 |
if (thentype.isPrimitive()) |
|
1288 |
thentype = types.boxedClass(thentype).type; |
|
1289 |
if (elsetype.isPrimitive()) |
|
1290 |
elsetype = types.boxedClass(elsetype).type; |
|
1291 |
} |
|
1292 |
||
1293 |
if (types.isSubtype(thentype, elsetype)) |
|
1294 |
return elsetype.baseType(); |
|
1295 |
if (types.isSubtype(elsetype, thentype)) |
|
1296 |
return thentype.baseType(); |
|
1297 |
||
1298 |
if (!allowBoxing || thentype.tag == VOID || elsetype.tag == VOID) { |
|
1299 |
log.error(pos, "neither.conditional.subtype", |
|
1300 |
thentype, elsetype); |
|
1301 |
return thentype.baseType(); |
|
1302 |
} |
|
1303 |
||
1304 |
// both are known to be reference types. The result is |
|
1305 |
// lub(thentype,elsetype). This cannot fail, as it will |
|
1306 |
// always be possible to infer "Object" if nothing better. |
|
1307 |
return types.lub(thentype.baseType(), elsetype.baseType()); |
|
1308 |
} |
|
1309 |
||
1310 |
public void visitIf(JCIf tree) { |
|
1311 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1312 |
attribStat(tree.thenpart, env); |
|
1313 |
if (tree.elsepart != null) |
|
1314 |
attribStat(tree.elsepart, env); |
|
1315 |
chk.checkEmptyIf(tree); |
|
1316 |
result = null; |
|
1317 |
} |
|
1318 |
||
1319 |
public void visitExec(JCExpressionStatement tree) { |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
1320 |
//a fresh environment is required for 292 inference to work properly --- |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
1321 |
//see Infer.instantiatePolymorphicSignatureInstance() |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
1322 |
Env<AttrContext> localEnv = env.dup(tree); |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
1323 |
attribExpr(tree.expr, localEnv); |
10 | 1324 |
result = null; |
1325 |
} |
|
1326 |
||
1327 |
public void visitBreak(JCBreak tree) { |
|
1328 |
tree.target = findJumpTarget(tree.pos(), tree.getTag(), tree.label, env); |
|
1329 |
result = null; |
|
1330 |
} |
|
1331 |
||
1332 |
public void visitContinue(JCContinue tree) { |
|
1333 |
tree.target = findJumpTarget(tree.pos(), tree.getTag(), tree.label, env); |
|
1334 |
result = null; |
|
1335 |
} |
|
1336 |
//where |
|
1337 |
/** Return the target of a break or continue statement, if it exists, |
|
1338 |
* report an error if not. |
|
1339 |
* Note: The target of a labelled break or continue is the |
|
1340 |
* (non-labelled) statement tree referred to by the label, |
|
1341 |
* not the tree representing the labelled statement itself. |
|
1342 |
* |
|
1343 |
* @param pos The position to be used for error diagnostics |
|
1344 |
* @param tag The tag of the jump statement. This is either |
|
1345 |
* Tree.BREAK or Tree.CONTINUE. |
|
1346 |
* @param label The label of the jump statement, or null if no |
|
1347 |
* label is given. |
|
1348 |
* @param env The environment current at the jump statement. |
|
1349 |
*/ |
|
1350 |
private JCTree findJumpTarget(DiagnosticPosition pos, |
|
10950 | 1351 |
JCTree.Tag tag, |
10 | 1352 |
Name label, |
1353 |
Env<AttrContext> env) { |
|
1354 |
// Search environments outwards from the point of jump. |
|
1355 |
Env<AttrContext> env1 = env; |
|
1356 |
LOOP: |
|
1357 |
while (env1 != null) { |
|
1358 |
switch (env1.tree.getTag()) { |
|
10950 | 1359 |
case LABELLED: |
10 | 1360 |
JCLabeledStatement labelled = (JCLabeledStatement)env1.tree; |
1361 |
if (label == labelled.label) { |
|
1362 |
// If jump is a continue, check that target is a loop. |
|
10950 | 1363 |
if (tag == CONTINUE) { |
1364 |
if (!labelled.body.hasTag(DOLOOP) && |
|
1365 |
!labelled.body.hasTag(WHILELOOP) && |
|
1366 |
!labelled.body.hasTag(FORLOOP) && |
|
1367 |
!labelled.body.hasTag(FOREACHLOOP)) |
|
10 | 1368 |
log.error(pos, "not.loop.label", label); |
1369 |
// Found labelled statement target, now go inwards |
|
1370 |
// to next non-labelled tree. |
|
1371 |
return TreeInfo.referencedStatement(labelled); |
|
1372 |
} else { |
|
1373 |
return labelled; |
|
1374 |
} |
|
1375 |
} |
|
1376 |
break; |
|
10950 | 1377 |
case DOLOOP: |
1378 |
case WHILELOOP: |
|
1379 |
case FORLOOP: |
|
1380 |
case FOREACHLOOP: |
|
10 | 1381 |
if (label == null) return env1.tree; |
1382 |
break; |
|
10950 | 1383 |
case SWITCH: |
1384 |
if (label == null && tag == BREAK) return env1.tree; |
|
10 | 1385 |
break; |
10950 | 1386 |
case METHODDEF: |
1387 |
case CLASSDEF: |
|
10 | 1388 |
break LOOP; |
1389 |
default: |
|
1390 |
} |
|
1391 |
env1 = env1.next; |
|
1392 |
} |
|
1393 |
if (label != null) |
|
1394 |
log.error(pos, "undef.label", label); |
|
10950 | 1395 |
else if (tag == CONTINUE) |
10 | 1396 |
log.error(pos, "cont.outside.loop"); |
1397 |
else |
|
1398 |
log.error(pos, "break.outside.switch.loop"); |
|
1399 |
return null; |
|
1400 |
} |
|
1401 |
||
1402 |
public void visitReturn(JCReturn tree) { |
|
1403 |
// Check that there is an enclosing method which is |
|
1404 |
// nested within than the enclosing class. |
|
1405 |
if (env.enclMethod == null || |
|
1406 |
env.enclMethod.sym.owner != env.enclClass.sym) { |
|
1407 |
log.error(tree.pos(), "ret.outside.meth"); |
|
1408 |
||
1409 |
} else { |
|
1410 |
// Attribute return expression, if it exists, and check that |
|
1411 |
// it conforms to result type of enclosing method. |
|
1412 |
Symbol m = env.enclMethod.sym; |
|
1413 |
if (m.type.getReturnType().tag == VOID) { |
|
1414 |
if (tree.expr != null) |
|
1415 |
log.error(tree.expr.pos(), |
|
1416 |
"cant.ret.val.from.meth.decl.void"); |
|
1417 |
} else if (tree.expr == null) { |
|
1418 |
log.error(tree.pos(), "missing.ret.val"); |
|
1419 |
} else { |
|
1420 |
attribExpr(tree.expr, env, m.type.getReturnType()); |
|
1421 |
} |
|
1422 |
} |
|
1423 |
result = null; |
|
1424 |
} |
|
1425 |
||
1426 |
public void visitThrow(JCThrow tree) { |
|
1427 |
attribExpr(tree.expr, env, syms.throwableType); |
|
1428 |
result = null; |
|
1429 |
} |
|
1430 |
||
1431 |
public void visitAssert(JCAssert tree) { |
|
1432 |
attribExpr(tree.cond, env, syms.booleanType); |
|
1433 |
if (tree.detail != null) { |
|
1434 |
chk.checkNonVoid(tree.detail.pos(), attribExpr(tree.detail, env)); |
|
1435 |
} |
|
1436 |
result = null; |
|
1437 |
} |
|
1438 |
||
1439 |
/** Visitor method for method invocations. |
|
1440 |
* NOTE: The method part of an application will have in its type field |
|
1441 |
* the return type of the method, not the method's type itself! |
|
1442 |
*/ |
|
1443 |
public void visitApply(JCMethodInvocation tree) { |
|
1444 |
// The local environment of a method application is |
|
1445 |
// a new environment nested in the current one. |
|
1446 |
Env<AttrContext> localEnv = env.dup(tree, env.info.dup()); |
|
1447 |
||
1448 |
// The types of the actual method arguments. |
|
1449 |
List<Type> argtypes; |
|
1450 |
||
1451 |
// The types of the actual method type arguments. |
|
1452 |
List<Type> typeargtypes = null; |
|
1453 |
||
1454 |
Name methName = TreeInfo.name(tree.meth); |
|
1455 |
||
1456 |
boolean isConstructorCall = |
|
1457 |
methName == names._this || methName == names._super; |
|
1458 |
||
1459 |
if (isConstructorCall) { |
|
1460 |
// We are seeing a ...this(...) or ...super(...) call. |
|
1461 |
// Check that this is the first statement in a constructor. |
|
1462 |
if (checkFirstConstructorStat(tree, env)) { |
|
1463 |
||
1464 |
// Record the fact |
|
1465 |
// that this is a constructor call (using isSelfCall). |
|
1466 |
localEnv.info.isSelfCall = true; |
|
1467 |
||
1468 |
// Attribute arguments, yielding list of argument types. |
|
1469 |
argtypes = attribArgs(tree.args, localEnv); |
|
1470 |
typeargtypes = attribTypes(tree.typeargs, localEnv); |
|
1471 |
||
1472 |
// Variable `site' points to the class in which the called |
|
1473 |
// constructor is defined. |
|
1474 |
Type site = env.enclClass.sym.type; |
|
1475 |
if (methName == names._super) { |
|
1476 |
if (site == syms.objectType) { |
|
1477 |
log.error(tree.meth.pos(), "no.superclass", site); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
1478 |
site = types.createErrorType(syms.objectType); |
10 | 1479 |
} else { |
1480 |
site = types.supertype(site); |
|
1481 |
} |
|
1482 |
} |
|
1483 |
||
1484 |
if (site.tag == CLASS) { |
|
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1485 |
Type encl = site.getEnclosingType(); |
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1486 |
while (encl != null && encl.tag == TYPEVAR) |
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1487 |
encl = encl.getUpperBound(); |
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1488 |
if (encl.tag == CLASS) { |
10 | 1489 |
// we are calling a nested class |
1490 |
||
10950 | 1491 |
if (tree.meth.hasTag(SELECT)) { |
10 | 1492 |
JCTree qualifier = ((JCFieldAccess) tree.meth).selected; |
1493 |
||
1494 |
// We are seeing a prefixed call, of the form |
|
1495 |
// <expr>.super(...). |
|
1496 |
// Check that the prefix expression conforms |
|
1497 |
// to the outer instance type of the class. |
|
1498 |
chk.checkRefType(qualifier.pos(), |
|
1499 |
attribExpr(qualifier, localEnv, |
|
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
1500 |
encl)); |
10 | 1501 |
} else if (methName == names._super) { |
1502 |
// qualifier omitted; check for existence |
|
1503 |
// of an appropriate implicit qualifier. |
|
1504 |
rs.resolveImplicitThis(tree.meth.pos(), |
|
8622
4f032629a0fd
6541876: "Enclosing Instance" error new in 1.6
mcimadamore
parents:
8616
diff
changeset
|
1505 |
localEnv, site, true); |
10 | 1506 |
} |
10950 | 1507 |
} else if (tree.meth.hasTag(SELECT)) { |
10 | 1508 |
log.error(tree.meth.pos(), "illegal.qual.not.icls", |
1509 |
site.tsym); |
|
1510 |
} |
|
1511 |
||
1512 |
// if we're calling a java.lang.Enum constructor, |
|
1513 |
// prefix the implicit String and int parameters |
|
1514 |
if (site.tsym == syms.enumSym && allowEnums) |
|
1515 |
argtypes = argtypes.prepend(syms.intType).prepend(syms.stringType); |
|
1516 |
||
1517 |
// Resolve the called constructor under the assumption |
|
1518 |
// that we are referring to a superclass instance of the |
|
1519 |
// current instance (JLS ???). |
|
1520 |
boolean selectSuperPrev = localEnv.info.selectSuper; |
|
1521 |
localEnv.info.selectSuper = true; |
|
1522 |
localEnv.info.varArgs = false; |
|
1523 |
Symbol sym = rs.resolveConstructor( |
|
1524 |
tree.meth.pos(), localEnv, site, argtypes, typeargtypes); |
|
1525 |
localEnv.info.selectSuper = selectSuperPrev; |
|
1526 |
||
1527 |
// Set method symbol to resolved constructor... |
|
1528 |
TreeInfo.setSymbol(tree.meth, sym); |
|
1529 |
||
1530 |
// ...and check that it is legal in the current context. |
|
1531 |
// (this will also set the tree's type) |
|
1532 |
Type mpt = newMethTemplate(argtypes, typeargtypes); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1533 |
checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt), |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1534 |
tree.varargsElement != null); |
10 | 1535 |
} |
1536 |
// Otherwise, `site' is an error type and we do nothing |
|
1537 |
} |
|
1538 |
result = tree.type = syms.voidType; |
|
1539 |
} else { |
|
1540 |
// Otherwise, we are seeing a regular method call. |
|
1541 |
// Attribute the arguments, yielding list of argument types, ... |
|
1542 |
argtypes = attribArgs(tree.args, localEnv); |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
1543 |
typeargtypes = attribAnyTypes(tree.typeargs, localEnv); |
10 | 1544 |
|
1545 |
// ... and attribute the method using as a prototype a methodtype |
|
1546 |
// whose formal argument types is exactly the list of actual |
|
1547 |
// arguments (this will also set the method symbol). |
|
1548 |
Type mpt = newMethTemplate(argtypes, typeargtypes); |
|
1549 |
localEnv.info.varArgs = false; |
|
1550 |
Type mtype = attribExpr(tree.meth, localEnv, mpt); |
|
1551 |
||
1552 |
// Compute the result type. |
|
1553 |
Type restype = mtype.getReturnType(); |
|
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6594
diff
changeset
|
1554 |
if (restype.tag == WILDCARD) |
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6594
diff
changeset
|
1555 |
throw new AssertionError(mtype); |
10 | 1556 |
|
1557 |
// as a special case, array.clone() has a result that is |
|
1558 |
// the same as static type of the array being cloned |
|
10950 | 1559 |
if (tree.meth.hasTag(SELECT) && |
10 | 1560 |
allowCovariantReturns && |
1561 |
methName == names.clone && |
|
1562 |
types.isArray(((JCFieldAccess) tree.meth).selected.type)) |
|
1563 |
restype = ((JCFieldAccess) tree.meth).selected.type; |
|
1564 |
||
1565 |
// as a special case, x.getClass() has type Class<? extends |X|> |
|
1566 |
if (allowGenerics && |
|
1567 |
methName == names.getClass && tree.args.isEmpty()) { |
|
10950 | 1568 |
Type qualifier = (tree.meth.hasTag(SELECT)) |
10 | 1569 |
? ((JCFieldAccess) tree.meth).selected.type |
1570 |
: env.enclClass.sym.type; |
|
1571 |
restype = new |
|
1572 |
ClassType(restype.getEnclosingType(), |
|
1573 |
List.<Type>of(new WildcardType(types.erasure(qualifier), |
|
1574 |
BoundKind.EXTENDS, |
|
1575 |
syms.boundClass)), |
|
1576 |
restype.tsym); |
|
1577 |
} |
|
1578 |
||
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
8032
diff
changeset
|
1579 |
chk.checkRefTypes(tree.typeargs, typeargtypes); |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
1580 |
|
10 | 1581 |
// Check that value of resulting type is admissible in the |
1582 |
// current context. Also, capture the return type |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1583 |
result = check(tree, capture(restype), VAL, resultInfo); |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
1584 |
|
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
1585 |
if (localEnv.info.varArgs) |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
1586 |
Assert.check(result.isErroneous() || tree.varargsElement != null); |
10 | 1587 |
} |
1358 | 1588 |
chk.validate(tree.typeargs, localEnv); |
10 | 1589 |
} |
1590 |
//where |
|
1591 |
/** Check that given application node appears as first statement |
|
1592 |
* in a constructor call. |
|
1593 |
* @param tree The application node |
|
1594 |
* @param env The environment current at the application. |
|
1595 |
*/ |
|
1596 |
boolean checkFirstConstructorStat(JCMethodInvocation tree, Env<AttrContext> env) { |
|
1597 |
JCMethodDecl enclMethod = env.enclMethod; |
|
1598 |
if (enclMethod != null && enclMethod.name == names.init) { |
|
1599 |
JCBlock body = enclMethod.body; |
|
10950 | 1600 |
if (body.stats.head.hasTag(EXEC) && |
10 | 1601 |
((JCExpressionStatement) body.stats.head).expr == tree) |
1602 |
return true; |
|
1603 |
} |
|
1604 |
log.error(tree.pos(),"call.must.be.first.stmt.in.ctor", |
|
1605 |
TreeInfo.name(tree.meth)); |
|
1606 |
return false; |
|
1607 |
} |
|
1608 |
||
1609 |
/** Obtain a method type with given argument types. |
|
1610 |
*/ |
|
1611 |
Type newMethTemplate(List<Type> argtypes, List<Type> typeargtypes) { |
|
1612 |
MethodType mt = new MethodType(argtypes, null, null, syms.methodClass); |
|
1613 |
return (typeargtypes == null) ? mt : (Type)new ForAll(typeargtypes, mt); |
|
1614 |
} |
|
1615 |
||
1616 |
public void visitNewClass(JCNewClass tree) { |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
1617 |
Type owntype = types.createErrorType(tree.type); |
10 | 1618 |
|
1619 |
// The local environment of a class creation is |
|
1620 |
// a new environment nested in the current one. |
|
1621 |
Env<AttrContext> localEnv = env.dup(tree, env.info.dup()); |
|
1622 |
||
1623 |
// The anonymous inner class definition of the new expression, |
|
1624 |
// if one is defined by it. |
|
1625 |
JCClassDecl cdef = tree.def; |
|
1626 |
||
1627 |
// If enclosing class is given, attribute it, and |
|
1628 |
// complete class name to be fully qualified |
|
1629 |
JCExpression clazz = tree.clazz; // Class field following new |
|
1630 |
JCExpression clazzid = // Identifier in class field |
|
10950 | 1631 |
(clazz.hasTag(TYPEAPPLY)) |
10 | 1632 |
? ((JCTypeApply) clazz).clazz |
1633 |
: clazz; |
|
1634 |
||
1635 |
JCExpression clazzid1 = clazzid; // The same in fully qualified form |
|
1636 |
||
1637 |
if (tree.encl != null) { |
|
1638 |
// We are seeing a qualified new, of the form |
|
1639 |
// <expr>.new C <...> (...) ... |
|
1640 |
// In this case, we let clazz stand for the name of the |
|
1641 |
// allocated class C prefixed with the type of the qualifier |
|
1642 |
// expression, so that we can |
|
1643 |
// resolve it with standard techniques later. I.e., if |
|
1644 |
// <expr> has type T, then <expr>.new C <...> (...) |
|
1645 |
// yields a clazz T.C. |
|
1646 |
Type encltype = chk.checkRefType(tree.encl.pos(), |
|
1647 |
attribExpr(tree.encl, env)); |
|
1648 |
clazzid1 = make.at(clazz.pos).Select(make.Type(encltype), |
|
1649 |
((JCIdent) clazzid).name); |
|
10950 | 1650 |
if (clazz.hasTag(TYPEAPPLY)) |
10 | 1651 |
clazz = make.at(tree.pos). |
1652 |
TypeApply(clazzid1, |
|
1653 |
((JCTypeApply) clazz).arguments); |
|
1654 |
else |
|
1655 |
clazz = clazzid1; |
|
1656 |
} |
|
1657 |
||
1658 |
// Attribute clazz expression and store |
|
1659 |
// symbol + type back into the attributed tree. |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1660 |
Type clazztype = attribType(clazz, env); |
8635
383a416a2bdf
7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents:
8625
diff
changeset
|
1661 |
clazztype = chk.checkDiamond(tree, clazztype); |
1358 | 1662 |
chk.validate(clazz, localEnv); |
10 | 1663 |
if (tree.encl != null) { |
1664 |
// We have to work in this case to store |
|
1665 |
// symbol + type back into the attributed tree. |
|
1666 |
tree.clazz.type = clazztype; |
|
1667 |
TreeInfo.setSymbol(clazzid, TreeInfo.symbol(clazzid1)); |
|
1668 |
clazzid.type = ((JCIdent) clazzid).sym.type; |
|
1669 |
if (!clazztype.isErroneous()) { |
|
1670 |
if (cdef != null && clazztype.tsym.isInterface()) { |
|
1671 |
log.error(tree.encl.pos(), "anon.class.impl.intf.no.qual.for.new"); |
|
1672 |
} else if (clazztype.tsym.isStatic()) { |
|
1673 |
log.error(tree.encl.pos(), "qualified.new.of.static.class", clazztype.tsym); |
|
1674 |
} |
|
1675 |
} |
|
1676 |
} else if (!clazztype.tsym.isInterface() && |
|
1677 |
clazztype.getEnclosingType().tag == CLASS) { |
|
1678 |
// Check for the existence of an apropos outer instance |
|
1679 |
rs.resolveImplicitThis(tree.pos(), env, clazztype); |
|
1680 |
} |
|
1681 |
||
1682 |
// Attribute constructor arguments. |
|
1683 |
List<Type> argtypes = attribArgs(tree.args, localEnv); |
|
1684 |
List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); |
|
1685 |
||
8635
383a416a2bdf
7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents:
8625
diff
changeset
|
1686 |
if (TreeInfo.isDiamond(tree) && !clazztype.isErroneous()) { |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1687 |
clazztype = attribDiamond(localEnv, tree, clazztype, argtypes, typeargtypes); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1688 |
clazz.type = clazztype; |
7081
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
1689 |
} else if (allowDiamondFinder && |
8635
383a416a2bdf
7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents:
8625
diff
changeset
|
1690 |
tree.def == null && |
383a416a2bdf
7020044: Project Coin: diamond erroneous allowed on some anonymous inner classes
mcimadamore
parents:
8625
diff
changeset
|
1691 |
!clazztype.isErroneous() && |
7081
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
1692 |
clazztype.getTypeArguments().nonEmpty() && |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
1693 |
findDiamonds) { |
7618
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1694 |
boolean prevDeferDiags = log.deferDiagnostics; |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1695 |
Queue<JCDiagnostic> prevDeferredDiags = log.deferredDiagnostics; |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1696 |
Type inferred = null; |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1697 |
try { |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1698 |
//disable diamond-related diagnostics |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1699 |
log.deferDiagnostics = true; |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1700 |
log.deferredDiagnostics = ListBuffer.lb(); |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1701 |
inferred = attribDiamond(localEnv, |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1702 |
tree, |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1703 |
clazztype, |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1704 |
argtypes, |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1705 |
typeargtypes); |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1706 |
} |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1707 |
finally { |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1708 |
log.deferDiagnostics = prevDeferDiags; |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1709 |
log.deferredDiagnostics = prevDeferredDiags; |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1710 |
} |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1711 |
if (inferred != null && |
c933cd84d33e
7002837: Diamond: javac generates diamond inference errors when in 'finder' mode
mcimadamore
parents:
7211
diff
changeset
|
1712 |
!inferred.isErroneous() && |
7081
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
1713 |
inferred.tag == CLASS && |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1714 |
types.isAssignable(inferred, pt().tag == NONE ? clazztype : pt(), Warner.noWarnings)) { |
7081
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
1715 |
String key = types.isSameType(clazztype, inferred) ? |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
1716 |
"diamond.redundant.args" : |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
1717 |
"diamond.redundant.args.1"; |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
1718 |
log.warning(tree.clazz.pos(), key, clazztype, inferred); |
94cfc5b65bed
6939780: add a warning to detect diamond sites
mcimadamore
parents:
7074
diff
changeset
|
1719 |
} |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1720 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1721 |
|
10 | 1722 |
// If we have made no mistakes in the class type... |
1723 |
if (clazztype.tag == CLASS) { |
|
1724 |
// Enums may not be instantiated except implicitly |
|
1725 |
if (allowEnums && |
|
1726 |
(clazztype.tsym.flags_field&Flags.ENUM) != 0 && |
|
10950 | 1727 |
(!env.tree.hasTag(VARDEF) || |
10 | 1728 |
(((JCVariableDecl) env.tree).mods.flags&Flags.ENUM) == 0 || |
1729 |
((JCVariableDecl) env.tree).init != tree)) |
|
1730 |
log.error(tree.pos(), "enum.cant.be.instantiated"); |
|
1731 |
// Check that class is not abstract |
|
1732 |
if (cdef == null && |
|
1733 |
(clazztype.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { |
|
1734 |
log.error(tree.pos(), "abstract.cant.be.instantiated", |
|
1735 |
clazztype.tsym); |
|
1736 |
} else if (cdef != null && clazztype.tsym.isInterface()) { |
|
1737 |
// Check that no constructor arguments are given to |
|
1738 |
// anonymous classes implementing an interface |
|
1739 |
if (!argtypes.isEmpty()) |
|
1740 |
log.error(tree.args.head.pos(), "anon.class.impl.intf.no.args"); |
|
1741 |
||
1742 |
if (!typeargtypes.isEmpty()) |
|
1743 |
log.error(tree.typeargs.head.pos(), "anon.class.impl.intf.no.typeargs"); |
|
1744 |
||
1745 |
// Error recovery: pretend no arguments were supplied. |
|
1746 |
argtypes = List.nil(); |
|
1747 |
typeargtypes = List.nil(); |
|
1748 |
} |
|
1749 |
||
1750 |
// Resolve the called constructor under the assumption |
|
1751 |
// that we are referring to a superclass instance of the |
|
1752 |
// current instance (JLS ???). |
|
1753 |
else { |
|
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1754 |
//the following code alters some of the fields in the current |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1755 |
//AttrContext - hence, the current context must be dup'ed in |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1756 |
//order to avoid downstream failures |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1757 |
Env<AttrContext> rsEnv = localEnv.dup(tree); |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1758 |
rsEnv.info.selectSuper = cdef != null; |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1759 |
rsEnv.info.varArgs = false; |
10 | 1760 |
tree.constructor = rs.resolveConstructor( |
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1761 |
tree.pos(), rsEnv, clazztype, argtypes, typeargtypes); |
6343
655c0db5643b
6857948: Calling a constructor with a doubly bogus argument causes an internal error
mcimadamore
parents:
6342
diff
changeset
|
1762 |
tree.constructorType = tree.constructor.type.isErroneous() ? |
655c0db5643b
6857948: Calling a constructor with a doubly bogus argument causes an internal error
mcimadamore
parents:
6342
diff
changeset
|
1763 |
syms.errType : |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
1764 |
checkConstructor(clazztype, |
6343
655c0db5643b
6857948: Calling a constructor with a doubly bogus argument causes an internal error
mcimadamore
parents:
6342
diff
changeset
|
1765 |
tree.constructor, |
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1766 |
rsEnv, |
6343
655c0db5643b
6857948: Calling a constructor with a doubly bogus argument causes an internal error
mcimadamore
parents:
6342
diff
changeset
|
1767 |
tree.args, |
655c0db5643b
6857948: Calling a constructor with a doubly bogus argument causes an internal error
mcimadamore
parents:
6342
diff
changeset
|
1768 |
argtypes, |
655c0db5643b
6857948: Calling a constructor with a doubly bogus argument causes an internal error
mcimadamore
parents:
6342
diff
changeset
|
1769 |
typeargtypes, |
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1770 |
rsEnv.info.varArgs); |
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1771 |
if (rsEnv.info.varArgs) |
8032 | 1772 |
Assert.check(tree.constructorType.isErroneous() || tree.varargsElement != null); |
10 | 1773 |
} |
1774 |
||
1775 |
if (cdef != null) { |
|
1776 |
// We are seeing an anonymous class instance creation. |
|
1777 |
// In this case, the class instance creation |
|
1778 |
// expression |
|
1779 |
// |
|
1780 |
// E.new <typeargs1>C<typargs2>(args) { ... } |
|
1781 |
// |
|
1782 |
// is represented internally as |
|
1783 |
// |
|
1784 |
// E . new <typeargs1>C<typargs2>(args) ( class <empty-name> { ... } ) . |
|
1785 |
// |
|
1786 |
// This expression is then *transformed* as follows: |
|
1787 |
// |
|
1788 |
// (1) add a STATIC flag to the class definition |
|
1789 |
// if the current environment is static |
|
1790 |
// (2) add an extends or implements clause |
|
1791 |
// (3) add a constructor. |
|
1792 |
// |
|
1793 |
// For instance, if C is a class, and ET is the type of E, |
|
1794 |
// the expression |
|
1795 |
// |
|
1796 |
// E.new <typeargs1>C<typargs2>(args) { ... } |
|
1797 |
// |
|
1798 |
// is translated to (where X is a fresh name and typarams is the |
|
1799 |
// parameter list of the super constructor): |
|
1800 |
// |
|
1801 |
// new <typeargs1>X(<*nullchk*>E, args) where |
|
1802 |
// X extends C<typargs2> { |
|
1803 |
// <typarams> X(ET e, args) { |
|
1804 |
// e.<typeargs1>super(args) |
|
1805 |
// } |
|
1806 |
// ... |
|
1807 |
// } |
|
1808 |
if (Resolve.isStatic(env)) cdef.mods.flags |= STATIC; |
|
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
1809 |
|
10 | 1810 |
if (clazztype.tsym.isInterface()) { |
1811 |
cdef.implementing = List.of(clazz); |
|
1812 |
} else { |
|
1813 |
cdef.extending = clazz; |
|
1814 |
} |
|
1815 |
||
1816 |
attribStat(cdef, localEnv); |
|
1817 |
||
1818 |
// If an outer instance is given, |
|
1819 |
// prefix it to the constructor arguments |
|
1820 |
// and delete it from the new expression |
|
1821 |
if (tree.encl != null && !clazztype.tsym.isInterface()) { |
|
1822 |
tree.args = tree.args.prepend(makeNullCheck(tree.encl)); |
|
1823 |
argtypes = argtypes.prepend(tree.encl.type); |
|
1824 |
tree.encl = null; |
|
1825 |
} |
|
1826 |
||
1827 |
// Reassign clazztype and recompute constructor. |
|
1828 |
clazztype = cdef.sym.type; |
|
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1829 |
boolean useVarargs = tree.varargsElement != null; |
10 | 1830 |
Symbol sym = rs.resolveConstructor( |
1831 |
tree.pos(), localEnv, clazztype, argtypes, |
|
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1832 |
typeargtypes, true, useVarargs); |
8032 | 1833 |
Assert.check(sym.kind < AMBIGUOUS || tree.constructor.type.isErroneous()); |
10 | 1834 |
tree.constructor = sym; |
3556
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1835 |
if (tree.constructor.kind > ERRONEOUS) { |
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1836 |
tree.constructorType = syms.errType; |
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1837 |
} |
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1838 |
else { |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
1839 |
tree.constructorType = checkConstructor(clazztype, |
3556
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1840 |
tree.constructor, |
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1841 |
localEnv, |
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1842 |
tree.args, |
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1843 |
argtypes, |
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1844 |
typeargtypes, |
9724
1eab738591a7
7043922: Regression: internal compiler error for nested anonymous inner class featuring varargs constructor
mcimadamore
parents:
9599
diff
changeset
|
1845 |
useVarargs); |
3556
08a404c6ff0f
6840059: regression: javac silently crashes when resolving erroneous anonymous inner constructor
mcimadamore
parents:
3149
diff
changeset
|
1846 |
} |
10 | 1847 |
} |
1848 |
||
1849 |
if (tree.constructor != null && tree.constructor.kind == MTH) |
|
1850 |
owntype = clazztype; |
|
1851 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1852 |
result = check(tree, owntype, VAL, resultInfo); |
1358 | 1853 |
chk.validate(tree.typeargs, localEnv); |
10 | 1854 |
} |
1855 |
||
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1856 |
Type attribDiamond(Env<AttrContext> env, |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1857 |
final JCNewClass tree, |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1858 |
Type clazztype, |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1859 |
List<Type> argtypes, |
6344
f190fb7fdd2d
6975275: diamond implementation needs some cleanup
mcimadamore
parents:
6343
diff
changeset
|
1860 |
List<Type> typeargtypes) { |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1861 |
if (clazztype.isErroneous() || |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1862 |
clazztype.isInterface()) { |
5649
c9e7ce44b173
6946618: sqe test fails: javac/generics/NewOnTypeParm in pit jdk7 b91 in all platforms.
mcimadamore
parents:
5492
diff
changeset
|
1863 |
//if the type of the instance creation expression is erroneous, |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1864 |
//or if it's an interface, or if something prevented us to form a valid |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1865 |
//mapping, return the (possibly erroneous) type unchanged |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1866 |
return clazztype; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1867 |
} |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1868 |
|
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1869 |
//dup attribution environment and augment the set of inference variables |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1870 |
Env<AttrContext> localEnv = env.dup(tree); |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1871 |
|
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1872 |
ClassType site = new ClassType(clazztype.getEnclosingType(), |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1873 |
clazztype.tsym.type.getTypeArguments(), |
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1874 |
clazztype.tsym); |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1875 |
|
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1876 |
//if the type of the instance creation expression is a class type |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1877 |
//apply method resolution inference (JLS 15.12.2.7). The return type |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1878 |
//of the resolved constructor will be a partially instantiated type |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1879 |
Symbol constructor = rs.resolveDiamond(tree.pos(), |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1880 |
localEnv, |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1881 |
site, |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1882 |
argtypes, |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1883 |
typeargtypes); |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1884 |
|
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1885 |
if (constructor.kind == MTH) { |
12078
7470e05d486b
7148164: attribution code for diamond should not rely on mutable state
mcimadamore
parents:
12013
diff
changeset
|
1886 |
clazztype = checkMethod(site, |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1887 |
constructor, |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1888 |
localEnv, |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1889 |
tree.args, |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1890 |
argtypes, |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1891 |
typeargtypes, |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1892 |
localEnv.info.varArgs).getReturnType(); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1893 |
} else { |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1894 |
clazztype = syms.errType; |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1895 |
} |
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
9074
diff
changeset
|
1896 |
|
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1897 |
if (clazztype.tag == FORALL && !resultInfo.pt.isErroneous()) { |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1898 |
try { |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1899 |
clazztype = resultInfo.checkContext.rawInstantiatePoly((ForAll)clazztype, pt(), Warner.noWarnings); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1900 |
} catch (Infer.InferenceException ex) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1901 |
//an error occurred while inferring uninstantiated type-variables |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1902 |
resultInfo.checkContext.report(tree.clazz.pos(), clazztype, resultInfo.pt, |
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1903 |
diags.fragment("cant.apply.diamond.1", diags.fragment("diamond", clazztype.tsym), ex.diagnostic)); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1904 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1905 |
} |
12334
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1906 |
|
29e1bfdcba4e
7151492: Encapsulate check logic into Attr.ResultInfo
mcimadamore
parents:
12333
diff
changeset
|
1907 |
return chk.checkClassType(tree.clazz.pos(), clazztype, true); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1908 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1909 |
|
10 | 1910 |
/** Make an attributed null check tree. |
1911 |
*/ |
|
1912 |
public JCExpression makeNullCheck(JCExpression arg) { |
|
1913 |
// optimization: X.this is never null; skip null check |
|
1914 |
Name name = TreeInfo.name(arg); |
|
1915 |
if (name == names._this || name == names._super) return arg; |
|
1916 |
||
10950 | 1917 |
JCTree.Tag optag = NULLCHK; |
10 | 1918 |
JCUnary tree = make.at(arg.pos).Unary(optag, arg); |
1919 |
tree.operator = syms.nullcheck; |
|
1920 |
tree.type = arg.type; |
|
1921 |
return tree; |
|
1922 |
} |
|
1923 |
||
1924 |
public void visitNewArray(JCNewArray tree) { |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
1925 |
Type owntype = types.createErrorType(tree.type); |
10 | 1926 |
Type elemtype; |
1927 |
if (tree.elemtype != null) { |
|
1928 |
elemtype = attribType(tree.elemtype, env); |
|
1358 | 1929 |
chk.validate(tree.elemtype, env); |
10 | 1930 |
owntype = elemtype; |
1931 |
for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { |
|
1932 |
attribExpr(l.head, env, syms.intType); |
|
1933 |
owntype = new ArrayType(owntype, syms.arrayClass); |
|
1934 |
} |
|
1935 |
} else { |
|
1936 |
// we are seeing an untyped aggregate { ... } |
|
1937 |
// this is allowed only if the prototype is an array |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1938 |
if (pt().tag == ARRAY) { |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1939 |
elemtype = types.elemtype(pt()); |
10 | 1940 |
} else { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1941 |
if (pt().tag != ERROR) { |
10 | 1942 |
log.error(tree.pos(), "illegal.initializer.for.type", |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1943 |
pt()); |
10 | 1944 |
} |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1945 |
elemtype = types.createErrorType(pt()); |
10 | 1946 |
} |
1947 |
} |
|
1948 |
if (tree.elems != null) { |
|
1949 |
attribExprs(tree.elems, env, elemtype); |
|
1950 |
owntype = new ArrayType(elemtype, syms.arrayClass); |
|
1951 |
} |
|
1952 |
if (!types.isReifiable(elemtype)) |
|
1953 |
log.error(tree.pos(), "generic.array.creation"); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1954 |
result = check(tree, owntype, VAL, resultInfo); |
10 | 1955 |
} |
1956 |
||
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10950
diff
changeset
|
1957 |
@Override |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10950
diff
changeset
|
1958 |
public void visitLambda(JCLambda that) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10950
diff
changeset
|
1959 |
throw new UnsupportedOperationException("Lambda expression not supported yet"); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10950
diff
changeset
|
1960 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10950
diff
changeset
|
1961 |
|
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1962 |
@Override |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1963 |
public void visitReference(JCMemberReference that) { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1964 |
throw new UnsupportedOperationException("Member references not supported yet"); |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1965 |
} |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1966 |
|
10 | 1967 |
public void visitParens(JCParens tree) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1968 |
Type owntype = attribTree(tree.expr, env, resultInfo); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1969 |
result = check(tree, owntype, pkind(), resultInfo); |
10 | 1970 |
Symbol sym = TreeInfo.symbol(tree); |
1971 |
if (sym != null && (sym.kind&(TYP|PCK)) != 0) |
|
1972 |
log.error(tree.pos(), "illegal.start.of.type"); |
|
1973 |
} |
|
1974 |
||
1975 |
public void visitAssign(JCAssign tree) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1976 |
Type owntype = attribTree(tree.lhs, env.dup(tree), varInfo); |
10 | 1977 |
Type capturedType = capture(owntype); |
1978 |
attribExpr(tree.rhs, env, owntype); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1979 |
result = check(tree, capturedType, VAL, resultInfo); |
10 | 1980 |
} |
1981 |
||
1982 |
public void visitAssignop(JCAssignOp tree) { |
|
1983 |
// Attribute arguments. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
1984 |
Type owntype = attribTree(tree.lhs, env, varInfo); |
10 | 1985 |
Type operand = attribExpr(tree.rhs, env); |
1986 |
// Find operator. |
|
1987 |
Symbol operator = tree.operator = rs.resolveBinaryOperator( |
|
10950 | 1988 |
tree.pos(), tree.getTag().noAssignOp(), env, |
10 | 1989 |
owntype, operand); |
1990 |
||
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
1991 |
if (operator.kind == MTH && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
1992 |
!owntype.isErroneous() && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
1993 |
!operand.isErroneous()) { |
10 | 1994 |
chk.checkOperator(tree.pos(), |
1995 |
(OperatorSymbol)operator, |
|
10950 | 1996 |
tree.getTag().noAssignOp(), |
10 | 1997 |
owntype, |
1998 |
operand); |
|
166 | 1999 |
chk.checkDivZero(tree.rhs.pos(), operator, operand); |
2000 |
chk.checkCastable(tree.rhs.pos(), |
|
2001 |
operator.type.getReturnType(), |
|
2002 |
owntype); |
|
10 | 2003 |
} |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2004 |
result = check(tree, owntype, VAL, resultInfo); |
10 | 2005 |
} |
2006 |
||
2007 |
public void visitUnary(JCUnary tree) { |
|
2008 |
// Attribute arguments. |
|
10950 | 2009 |
Type argtype = (tree.getTag().isIncOrDecUnaryOp()) |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2010 |
? attribTree(tree.arg, env, varInfo) |
10 | 2011 |
: chk.checkNonVoid(tree.arg.pos(), attribExpr(tree.arg, env)); |
2012 |
||
2013 |
// Find operator. |
|
2014 |
Symbol operator = tree.operator = |
|
2015 |
rs.resolveUnaryOperator(tree.pos(), tree.getTag(), env, argtype); |
|
2016 |
||
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2017 |
Type owntype = types.createErrorType(tree.type); |
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2018 |
if (operator.kind == MTH && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2019 |
!argtype.isErroneous()) { |
10950 | 2020 |
owntype = (tree.getTag().isIncOrDecUnaryOp()) |
10 | 2021 |
? tree.arg.type |
2022 |
: operator.type.getReturnType(); |
|
2023 |
int opc = ((OperatorSymbol)operator).opcode; |
|
2024 |
||
2025 |
// If the argument is constant, fold it. |
|
2026 |
if (argtype.constValue() != null) { |
|
2027 |
Type ctype = cfolder.fold1(opc, argtype); |
|
2028 |
if (ctype != null) { |
|
2029 |
owntype = cfolder.coerce(ctype, owntype); |
|
2030 |
||
2031 |
// Remove constant types from arguments to |
|
2032 |
// conserve space. The parser will fold concatenations |
|
2033 |
// of string literals; the code here also |
|
2034 |
// gets rid of intermediate results when some of the |
|
2035 |
// operands are constant identifiers. |
|
2036 |
if (tree.arg.type.tsym == syms.stringType.tsym) { |
|
2037 |
tree.arg.type = syms.stringType; |
|
2038 |
} |
|
2039 |
} |
|
2040 |
} |
|
2041 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2042 |
result = check(tree, owntype, VAL, resultInfo); |
10 | 2043 |
} |
2044 |
||
2045 |
public void visitBinary(JCBinary tree) { |
|
2046 |
// Attribute arguments. |
|
2047 |
Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env)); |
|
2048 |
Type right = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.rhs, env)); |
|
2049 |
||
2050 |
// Find operator. |
|
2051 |
Symbol operator = tree.operator = |
|
2052 |
rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right); |
|
2053 |
||
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2054 |
Type owntype = types.createErrorType(tree.type); |
8237
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2055 |
if (operator.kind == MTH && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2056 |
!left.isErroneous() && |
d5ef8db7ad09
5017953: spurious cascaded diagnostics when name not found
mcimadamore
parents:
8236
diff
changeset
|
2057 |
!right.isErroneous()) { |
10 | 2058 |
owntype = operator.type.getReturnType(); |
2059 |
int opc = chk.checkOperator(tree.lhs.pos(), |
|
2060 |
(OperatorSymbol)operator, |
|
2061 |
tree.getTag(), |
|
2062 |
left, |
|
2063 |
right); |
|
2064 |
||
2065 |
// If both arguments are constants, fold them. |
|
2066 |
if (left.constValue() != null && right.constValue() != null) { |
|
2067 |
Type ctype = cfolder.fold2(opc, left, right); |
|
2068 |
if (ctype != null) { |
|
2069 |
owntype = cfolder.coerce(ctype, owntype); |
|
2070 |
||
2071 |
// Remove constant types from arguments to |
|
2072 |
// conserve space. The parser will fold concatenations |
|
2073 |
// of string literals; the code here also |
|
2074 |
// gets rid of intermediate results when some of the |
|
2075 |
// operands are constant identifiers. |
|
2076 |
if (tree.lhs.type.tsym == syms.stringType.tsym) { |
|
2077 |
tree.lhs.type = syms.stringType; |
|
2078 |
} |
|
2079 |
if (tree.rhs.type.tsym == syms.stringType.tsym) { |
|
2080 |
tree.rhs.type = syms.stringType; |
|
2081 |
} |
|
2082 |
} |
|
2083 |
} |
|
2084 |
||
2085 |
// Check that argument types of a reference ==, != are |
|
2086 |
// castable to each other, (JLS???). |
|
2087 |
if ((opc == ByteCodes.if_acmpeq || opc == ByteCodes.if_acmpne)) { |
|
2088 |
if (!types.isCastable(left, right, new Warner(tree.pos()))) { |
|
2089 |
log.error(tree.pos(), "incomparable.types", left, right); |
|
2090 |
} |
|
2091 |
} |
|
2092 |
||
2093 |
chk.checkDivZero(tree.rhs.pos(), operator, right); |
|
2094 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2095 |
result = check(tree, owntype, VAL, resultInfo); |
10 | 2096 |
} |
2097 |
||
2098 |
public void visitTypeCast(JCTypeCast tree) { |
|
2099 |
Type clazztype = attribType(tree.clazz, env); |
|
6351 | 2100 |
chk.validate(tree.clazz, env, false); |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
2101 |
//a fresh environment is required for 292 inference to work properly --- |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
2102 |
//see Infer.instantiatePolymorphicSignatureInstance() |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
2103 |
Env<AttrContext> localEnv = env.dup(tree); |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6587
diff
changeset
|
2104 |
Type exprtype = attribExpr(tree.expr, localEnv, Infer.anyPoly); |
10 | 2105 |
Type owntype = chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
2106 |
if (exprtype.constValue() != null) |
|
2107 |
owntype = cfolder.coerce(exprtype, owntype); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2108 |
result = check(tree, capture(owntype), VAL, resultInfo); |
12333
7b02d0529a97
7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents:
12087
diff
changeset
|
2109 |
chk.checkRedundantCast(localEnv, tree); |
10 | 2110 |
} |
2111 |
||
2112 |
public void visitTypeTest(JCInstanceOf tree) { |
|
2113 |
Type exprtype = chk.checkNullOrRefType( |
|
2114 |
tree.expr.pos(), attribExpr(tree.expr, env)); |
|
2115 |
Type clazztype = chk.checkReifiableReferenceType( |
|
2116 |
tree.clazz.pos(), attribType(tree.clazz, env)); |
|
6351 | 2117 |
chk.validate(tree.clazz, env, false); |
10 | 2118 |
chk.checkCastable(tree.expr.pos(), exprtype, clazztype); |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2119 |
result = check(tree, syms.booleanType, VAL, resultInfo); |
10 | 2120 |
} |
2121 |
||
2122 |
public void visitIndexed(JCArrayAccess tree) { |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2123 |
Type owntype = types.createErrorType(tree.type); |
10 | 2124 |
Type atype = attribExpr(tree.indexed, env); |
2125 |
attribExpr(tree.index, env, syms.intType); |
|
2126 |
if (types.isArray(atype)) |
|
2127 |
owntype = types.elemtype(atype); |
|
2128 |
else if (atype.tag != ERROR) |
|
2129 |
log.error(tree.pos(), "array.req.but.found", atype); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2130 |
if ((pkind() & VAR) == 0) owntype = capture(owntype); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2131 |
result = check(tree, owntype, VAR, resultInfo); |
10 | 2132 |
} |
2133 |
||
2134 |
public void visitIdent(JCIdent tree) { |
|
2135 |
Symbol sym; |
|
2136 |
boolean varArgs = false; |
|
2137 |
||
2138 |
// Find symbol |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2139 |
if (pt().tag == METHOD || pt().tag == FORALL) { |
10 | 2140 |
// If we are looking for a method, the prototype `pt' will be a |
2141 |
// method type with the type of the call's arguments as parameters. |
|
2142 |
env.info.varArgs = false; |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2143 |
sym = rs.resolveMethod(tree.pos(), env, tree.name, pt().getParameterTypes(), pt().getTypeArguments()); |
10 | 2144 |
varArgs = env.info.varArgs; |
2145 |
} else if (tree.sym != null && tree.sym.kind != VAR) { |
|
2146 |
sym = tree.sym; |
|
2147 |
} else { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2148 |
sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind()); |
10 | 2149 |
} |
2150 |
tree.sym = sym; |
|
2151 |
||
2152 |
// (1) Also find the environment current for the class where |
|
2153 |
// sym is defined (`symEnv'). |
|
2154 |
// Only for pre-tiger versions (1.4 and earlier): |
|
2155 |
// (2) Also determine whether we access symbol out of an anonymous |
|
2156 |
// class in a this or super call. This is illegal for instance |
|
2157 |
// members since such classes don't carry a this$n link. |
|
2158 |
// (`noOuterThisPath'). |
|
2159 |
Env<AttrContext> symEnv = env; |
|
2160 |
boolean noOuterThisPath = false; |
|
2161 |
if (env.enclClass.sym.owner.kind != PCK && // we are in an inner class |
|
2162 |
(sym.kind & (VAR | MTH | TYP)) != 0 && |
|
2163 |
sym.owner.kind == TYP && |
|
2164 |
tree.name != names._this && tree.name != names._super) { |
|
2165 |
||
2166 |
// Find environment in which identifier is defined. |
|
2167 |
while (symEnv.outer != null && |
|
2168 |
!sym.isMemberOf(symEnv.enclClass.sym, types)) { |
|
2169 |
if ((symEnv.enclClass.sym.flags() & NOOUTERTHIS) != 0) |
|
2170 |
noOuterThisPath = !allowAnonOuterThis; |
|
2171 |
symEnv = symEnv.outer; |
|
2172 |
} |
|
2173 |
} |
|
2174 |
||
2175 |
// If symbol is a variable, ... |
|
2176 |
if (sym.kind == VAR) { |
|
2177 |
VarSymbol v = (VarSymbol)sym; |
|
2178 |
||
2179 |
// ..., evaluate its initializer, if it has one, and check for |
|
2180 |
// illegal forward reference. |
|
2181 |
checkInit(tree, env, v, false); |
|
2182 |
||
2183 |
// If symbol is a local variable accessed from an embedded |
|
2184 |
// inner class check that it is final. |
|
2185 |
if (v.owner.kind == MTH && |
|
2186 |
v.owner != env.info.scope.owner && |
|
2187 |
(v.flags_field & FINAL) == 0) { |
|
2188 |
log.error(tree.pos(), |
|
2189 |
"local.var.accessed.from.icls.needs.final", |
|
2190 |
v); |
|
2191 |
} |
|
2192 |
||
2193 |
// If we are expecting a variable (as opposed to a value), check |
|
2194 |
// that the variable is assignable in the current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2195 |
if (pkind() == VAR) |
10 | 2196 |
checkAssignable(tree.pos(), v, null, env); |
2197 |
} |
|
2198 |
||
2199 |
// In a constructor body, |
|
2200 |
// if symbol is a field or instance method, check that it is |
|
2201 |
// not accessed before the supertype constructor is called. |
|
2202 |
if ((symEnv.info.isSelfCall || noOuterThisPath) && |
|
2203 |
(sym.kind & (VAR | MTH)) != 0 && |
|
2204 |
sym.owner.kind == TYP && |
|
2205 |
(sym.flags() & STATIC) == 0) { |
|
2206 |
chk.earlyRefError(tree.pos(), sym.kind == VAR ? sym : thisSym(tree.pos(), env)); |
|
2207 |
} |
|
2208 |
Env<AttrContext> env1 = env; |
|
512
53e498fa5c0e
6657499: javac 1.6.0 fails to compile class with inner class
mcimadamore
parents:
511
diff
changeset
|
2209 |
if (sym.kind != ERR && sym.kind != TYP && sym.owner != null && sym.owner != env1.enclClass.sym) { |
10 | 2210 |
// If the found symbol is inaccessible, then it is |
2211 |
// accessed through an enclosing instance. Locate this |
|
2212 |
// enclosing instance: |
|
2213 |
while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym)) |
|
2214 |
env1 = env1.outer; |
|
2215 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2216 |
result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo, varArgs); |
10 | 2217 |
} |
2218 |
||
2219 |
public void visitSelect(JCFieldAccess tree) { |
|
2220 |
// Determine the expected kind of the qualifier expression. |
|
2221 |
int skind = 0; |
|
2222 |
if (tree.name == names._this || tree.name == names._super || |
|
2223 |
tree.name == names._class) |
|
2224 |
{ |
|
2225 |
skind = TYP; |
|
2226 |
} else { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2227 |
if ((pkind() & PCK) != 0) skind = skind | PCK; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2228 |
if ((pkind() & TYP) != 0) skind = skind | TYP | PCK; |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2229 |
if ((pkind() & (VAL | MTH)) != 0) skind = skind | VAL | TYP; |
10 | 2230 |
} |
2231 |
||
2232 |
// Attribute the qualifier expression, and determine its symbol (if any). |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2233 |
Type site = attribTree(tree.selected, env, new ResultInfo(skind, Infer.anyPoly)); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2234 |
if ((pkind() & (PCK | TYP)) == 0) |
10 | 2235 |
site = capture(site); // Capture field access |
2236 |
||
2237 |
// don't allow T.class T[].class, etc |
|
2238 |
if (skind == TYP) { |
|
2239 |
Type elt = site; |
|
2240 |
while (elt.tag == ARRAY) |
|
2241 |
elt = ((ArrayType)elt).elemtype; |
|
2242 |
if (elt.tag == TYPEVAR) { |
|
2243 |
log.error(tree.pos(), "type.var.cant.be.deref"); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2244 |
result = types.createErrorType(tree.type); |
10 | 2245 |
return; |
2246 |
} |
|
2247 |
} |
|
2248 |
||
2249 |
// If qualifier symbol is a type or `super', assert `selectSuper' |
|
2250 |
// for the selection. This is relevant for determining whether |
|
2251 |
// protected symbols are accessible. |
|
2252 |
Symbol sitesym = TreeInfo.symbol(tree.selected); |
|
2253 |
boolean selectSuperPrev = env.info.selectSuper; |
|
2254 |
env.info.selectSuper = |
|
2255 |
sitesym != null && |
|
2256 |
sitesym.name == names._super; |
|
2257 |
||
2258 |
// If selected expression is polymorphic, strip |
|
2259 |
// type parameters and remember in env.info.tvars, so that |
|
2260 |
// they can be added later (in Attr.checkId and Infer.instantiateMethod). |
|
2261 |
if (tree.selected.type.tag == FORALL) { |
|
2262 |
ForAll pstype = (ForAll)tree.selected.type; |
|
2263 |
env.info.tvars = pstype.tvars; |
|
2264 |
site = tree.selected.type = pstype.qtype; |
|
2265 |
} |
|
2266 |
||
2267 |
// Determine the symbol represented by the selection. |
|
2268 |
env.info.varArgs = false; |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2269 |
Symbol sym = selectSym(tree, sitesym, site, env, resultInfo); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2270 |
if (sym.exists() && !isType(sym) && (pkind() & (PCK | TYP)) != 0) { |
10 | 2271 |
site = capture(site); |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2272 |
sym = selectSym(tree, sitesym, site, env, resultInfo); |
10 | 2273 |
} |
2274 |
boolean varArgs = env.info.varArgs; |
|
2275 |
tree.sym = sym; |
|
2276 |
||
511
b3b5eadd2bca
6450290: Capture of nested wildcards causes type error
mcimadamore
parents:
325
diff
changeset
|
2277 |
if (site.tag == TYPEVAR && !isType(sym) && sym.kind != ERR) { |
b3b5eadd2bca
6450290: Capture of nested wildcards causes type error
mcimadamore
parents:
325
diff
changeset
|
2278 |
while (site.tag == TYPEVAR) site = site.getUpperBound(); |
b3b5eadd2bca
6450290: Capture of nested wildcards causes type error
mcimadamore
parents:
325
diff
changeset
|
2279 |
site = capture(site); |
b3b5eadd2bca
6450290: Capture of nested wildcards causes type error
mcimadamore
parents:
325
diff
changeset
|
2280 |
} |
10 | 2281 |
|
2282 |
// If that symbol is a variable, ... |
|
2283 |
if (sym.kind == VAR) { |
|
2284 |
VarSymbol v = (VarSymbol)sym; |
|
2285 |
||
2286 |
// ..., evaluate its initializer, if it has one, and check for |
|
2287 |
// illegal forward reference. |
|
2288 |
checkInit(tree, env, v, true); |
|
2289 |
||
2290 |
// If we are expecting a variable (as opposed to a value), check |
|
2291 |
// that the variable is assignable in the current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2292 |
if (pkind() == VAR) |
10 | 2293 |
checkAssignable(tree.pos(), v, tree.selected, env); |
2294 |
} |
|
2295 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2296 |
if (sitesym != null && |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2297 |
sitesym.kind == VAR && |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2298 |
((VarSymbol)sitesym).isResourceVariable() && |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2299 |
sym.kind == MTH && |
9079
e512a7712be3
7032633: javac -Xlint:all warns about flush() within try on an auto-closeable resource
mcimadamore
parents:
9076
diff
changeset
|
2300 |
sym.name.equals(names.close) && |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2301 |
sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) && |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2302 |
env.info.lint.isEnabled(LintCategory.TRY)) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2303 |
log.warning(LintCategory.TRY, tree, "try.explicit.close.call"); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2304 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
2305 |
|
10 | 2306 |
// Disallow selecting a type from an expression |
2307 |
if (isType(sym) && (sitesym==null || (sitesym.kind&(TYP|PCK)) == 0)) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2308 |
tree.type = check(tree.selected, pt(), |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2309 |
sitesym == null ? VAL : sitesym.kind, new ResultInfo(TYP|PCK, pt())); |
10 | 2310 |
} |
2311 |
||
2312 |
if (isType(sitesym)) { |
|
2313 |
if (sym.name == names._this) { |
|
2314 |
// If `C' is the currently compiled class, check that |
|
2315 |
// C.this' does not appear in a call to a super(...) |
|
2316 |
if (env.info.isSelfCall && |
|
2317 |
site.tsym == env.enclClass.sym) { |
|
2318 |
chk.earlyRefError(tree.pos(), sym); |
|
2319 |
} |
|
2320 |
} else { |
|
2321 |
// Check if type-qualified fields or methods are static (JLS) |
|
2322 |
if ((sym.flags() & STATIC) == 0 && |
|
2323 |
sym.name != names._super && |
|
2324 |
(sym.kind == VAR || sym.kind == MTH)) { |
|
2325 |
rs.access(rs.new StaticError(sym), |
|
2326 |
tree.pos(), site, sym.name, true); |
|
2327 |
} |
|
2328 |
} |
|
5002
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
5001
diff
changeset
|
2329 |
} else if (sym.kind != ERR && (sym.flags() & STATIC) != 0 && sym.name != names._class) { |
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
5001
diff
changeset
|
2330 |
// If the qualified item is not a type and the selected item is static, report |
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
5001
diff
changeset
|
2331 |
// a warning. Make allowance for the class of an array type e.g. Object[].class) |
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
5001
diff
changeset
|
2332 |
chk.warnStatic(tree, "static.not.qualified.by.type", Kinds.kindName(sym.kind), sym.owner); |
10 | 2333 |
} |
2334 |
||
2335 |
// If we are selecting an instance member via a `super', ... |
|
2336 |
if (env.info.selectSuper && (sym.flags() & STATIC) == 0) { |
|
2337 |
||
2338 |
// Check that super-qualified symbols are not abstract (JLS) |
|
2339 |
rs.checkNonAbstract(tree.pos(), sym); |
|
2340 |
||
2341 |
if (site.isRaw()) { |
|
2342 |
// Determine argument types for site. |
|
2343 |
Type site1 = types.asSuper(env.enclClass.sym.type, site.tsym); |
|
2344 |
if (site1 != null) site = site1; |
|
2345 |
} |
|
2346 |
} |
|
2347 |
||
2348 |
env.info.selectSuper = selectSuperPrev; |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2349 |
result = checkId(tree, site, sym, env, resultInfo, varArgs); |
10 | 2350 |
env.info.tvars = List.nil(); |
2351 |
} |
|
2352 |
//where |
|
2353 |
/** Determine symbol referenced by a Select expression, |
|
2354 |
* |
|
2355 |
* @param tree The select tree. |
|
2356 |
* @param site The type of the selected expression, |
|
2357 |
* @param env The current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2358 |
* @param resultInfo The current result. |
10 | 2359 |
*/ |
2360 |
private Symbol selectSym(JCFieldAccess tree, |
|
8045 | 2361 |
Symbol location, |
10 | 2362 |
Type site, |
2363 |
Env<AttrContext> env, |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2364 |
ResultInfo resultInfo) { |
10 | 2365 |
DiagnosticPosition pos = tree.pos(); |
2366 |
Name name = tree.name; |
|
2367 |
switch (site.tag) { |
|
2368 |
case PACKAGE: |
|
2369 |
return rs.access( |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2370 |
rs.findIdentInPackage(env, site.tsym, name, resultInfo.pkind), |
8045 | 2371 |
pos, location, site, name, true); |
10 | 2372 |
case ARRAY: |
2373 |
case CLASS: |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2374 |
if (resultInfo.pt.tag == METHOD || resultInfo.pt.tag == FORALL) { |
10 | 2375 |
return rs.resolveQualifiedMethod( |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2376 |
pos, env, location, site, name, resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments()); |
10 | 2377 |
} else if (name == names._this || name == names._super) { |
2378 |
return rs.resolveSelf(pos, env, site.tsym, name); |
|
2379 |
} else if (name == names._class) { |
|
2380 |
// In this case, we have already made sure in |
|
2381 |
// visitSelect that qualifier expression is a type. |
|
2382 |
Type t = syms.classType; |
|
2383 |
List<Type> typeargs = allowGenerics |
|
2384 |
? List.of(types.erasure(site)) |
|
2385 |
: List.<Type>nil(); |
|
2386 |
t = new ClassType(t.getEnclosingType(), typeargs, t.tsym); |
|
2387 |
return new VarSymbol( |
|
2388 |
STATIC | PUBLIC | FINAL, names._class, t, site.tsym); |
|
2389 |
} else { |
|
2390 |
// We are seeing a plain identifier as selector. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2391 |
Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind); |
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2392 |
if ((resultInfo.pkind & ERRONEOUS) == 0) |
8045 | 2393 |
sym = rs.access(sym, pos, location, site, name, true); |
10 | 2394 |
return sym; |
2395 |
} |
|
2396 |
case WILDCARD: |
|
2397 |
throw new AssertionError(tree); |
|
2398 |
case TYPEVAR: |
|
2399 |
// Normally, site.getUpperBound() shouldn't be null. |
|
2400 |
// It should only happen during memberEnter/attribBase |
|
8045 | 2401 |
// when determining the super type which *must* beac |
10 | 2402 |
// done before attributing the type variables. In |
2403 |
// other words, we are seeing this illegal program: |
|
2404 |
// class B<T> extends A<T.foo> {} |
|
2405 |
Symbol sym = (site.getUpperBound() != null) |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2406 |
? selectSym(tree, location, capture(site.getUpperBound()), env, resultInfo) |
10 | 2407 |
: null; |
3559
58cfcc0f1aa9
6569404: Cannot instantiate an inner class of a type variable
mcimadamore
parents:
3556
diff
changeset
|
2408 |
if (sym == null) { |
10 | 2409 |
log.error(pos, "type.var.cant.be.deref"); |
2410 |
return syms.errSymbol; |
|
2411 |
} else { |
|
1528
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1358
diff
changeset
|
2412 |
Symbol sym2 = (sym.flags() & Flags.PRIVATE) != 0 ? |
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1358
diff
changeset
|
2413 |
rs.new AccessError(env, site, sym) : |
441d4ec466de
6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents:
1358
diff
changeset
|
2414 |
sym; |
8045 | 2415 |
rs.access(sym2, pos, location, site, name, true); |
10 | 2416 |
return sym; |
2417 |
} |
|
2418 |
case ERROR: |
|
2419 |
// preserve identifier names through errors |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2420 |
return types.createErrorType(name, site.tsym, site).tsym; |
10 | 2421 |
default: |
2422 |
// The qualifier expression is of a primitive type -- only |
|
2423 |
// .class is allowed for these. |
|
2424 |
if (name == names._class) { |
|
2425 |
// In this case, we have already made sure in Select that |
|
2426 |
// qualifier expression is a type. |
|
2427 |
Type t = syms.classType; |
|
2428 |
Type arg = types.boxedClass(site).type; |
|
2429 |
t = new ClassType(t.getEnclosingType(), List.of(arg), t.tsym); |
|
2430 |
return new VarSymbol( |
|
2431 |
STATIC | PUBLIC | FINAL, names._class, t, site.tsym); |
|
2432 |
} else { |
|
2433 |
log.error(pos, "cant.deref", site); |
|
2434 |
return syms.errSymbol; |
|
2435 |
} |
|
2436 |
} |
|
2437 |
} |
|
2438 |
||
2439 |
/** Determine type of identifier or select expression and check that |
|
2440 |
* (1) the referenced symbol is not deprecated |
|
2441 |
* (2) the symbol's type is safe (@see checkSafe) |
|
2442 |
* (3) if symbol is a variable, check that its type and kind are |
|
2443 |
* compatible with the prototype and protokind. |
|
2444 |
* (4) if symbol is an instance field of a raw type, |
|
2445 |
* which is being assigned to, issue an unchecked warning if its |
|
2446 |
* type changes under erasure. |
|
2447 |
* (5) if symbol is an instance method of a raw type, issue an |
|
2448 |
* unchecked warning if its argument types change under erasure. |
|
2449 |
* If checks succeed: |
|
2450 |
* If symbol is a constant, return its constant type |
|
2451 |
* else if symbol is a method, return its result type |
|
2452 |
* otherwise return its type. |
|
2453 |
* Otherwise return errType. |
|
2454 |
* |
|
2455 |
* @param tree The syntax tree representing the identifier |
|
2456 |
* @param site If this is a select, the type of the selected |
|
2457 |
* expression, otherwise the type of the current class. |
|
2458 |
* @param sym The symbol representing the identifier. |
|
2459 |
* @param env The current environment. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2460 |
* @param resultInfo The expected result |
10 | 2461 |
*/ |
2462 |
Type checkId(JCTree tree, |
|
2463 |
Type site, |
|
2464 |
Symbol sym, |
|
2465 |
Env<AttrContext> env, |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2466 |
ResultInfo resultInfo, |
10 | 2467 |
boolean useVarargs) { |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2468 |
if (resultInfo.pt.isErroneous()) return types.createErrorType(site); |
10 | 2469 |
Type owntype; // The computed type of this identifier occurrence. |
2470 |
switch (sym.kind) { |
|
2471 |
case TYP: |
|
2472 |
// For types, the computed type equals the symbol's type, |
|
2473 |
// except for two situations: |
|
2474 |
owntype = sym.type; |
|
2475 |
if (owntype.tag == CLASS) { |
|
2476 |
Type ownOuter = owntype.getEnclosingType(); |
|
2477 |
||
2478 |
// (a) If the symbol's type is parameterized, erase it |
|
2479 |
// because no type parameters were given. |
|
2480 |
// We recover generic outer type later in visitTypeApply. |
|
2481 |
if (owntype.tsym.type.getTypeArguments().nonEmpty()) { |
|
2482 |
owntype = types.erasure(owntype); |
|
2483 |
} |
|
2484 |
||
2485 |
// (b) If the symbol's type is an inner class, then |
|
2486 |
// we have to interpret its outer type as a superclass |
|
2487 |
// of the site type. Example: |
|
2488 |
// |
|
2489 |
// class Tree<A> { class Visitor { ... } } |
|
2490 |
// class PointTree extends Tree<Point> { ... } |
|
2491 |
// ...PointTree.Visitor... |
|
2492 |
// |
|
2493 |
// Then the type of the last expression above is |
|
2494 |
// Tree<Point>.Visitor. |
|
2495 |
else if (ownOuter.tag == CLASS && site != ownOuter) { |
|
2496 |
Type normOuter = site; |
|
2497 |
if (normOuter.tag == CLASS) |
|
2498 |
normOuter = types.asEnclosingSuper(site, ownOuter.tsym); |
|
2499 |
if (normOuter == null) // perhaps from an import |
|
2500 |
normOuter = types.erasure(ownOuter); |
|
2501 |
if (normOuter != ownOuter) |
|
2502 |
owntype = new ClassType( |
|
2503 |
normOuter, List.<Type>nil(), owntype.tsym); |
|
2504 |
} |
|
2505 |
} |
|
2506 |
break; |
|
2507 |
case VAR: |
|
2508 |
VarSymbol v = (VarSymbol)sym; |
|
2509 |
// Test (4): if symbol is an instance field of a raw type, |
|
2510 |
// which is being assigned to, issue an unchecked warning if |
|
2511 |
// its type changes under erasure. |
|
2512 |
if (allowGenerics && |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2513 |
resultInfo.pkind == VAR && |
10 | 2514 |
v.owner.kind == TYP && |
2515 |
(v.flags() & STATIC) == 0 && |
|
2516 |
(site.tag == CLASS || site.tag == TYPEVAR)) { |
|
2517 |
Type s = types.asOuterSuper(site, v.owner); |
|
2518 |
if (s != null && |
|
2519 |
s.isRaw() && |
|
2520 |
!types.isSameType(v.type, v.erasure(types))) { |
|
2521 |
chk.warnUnchecked(tree.pos(), |
|
2522 |
"unchecked.assign.to.var", |
|
2523 |
v, s); |
|
2524 |
} |
|
2525 |
} |
|
2526 |
// The computed type of a variable is the type of the |
|
2527 |
// variable symbol, taken as a member of the site type. |
|
2528 |
owntype = (sym.owner.kind == TYP && |
|
2529 |
sym.name != names._this && sym.name != names._super) |
|
2530 |
? types.memberType(site, sym) |
|
2531 |
: sym.type; |
|
2532 |
||
2533 |
if (env.info.tvars.nonEmpty()) { |
|
2534 |
Type owntype1 = new ForAll(env.info.tvars, owntype); |
|
2535 |
for (List<Type> l = env.info.tvars; l.nonEmpty(); l = l.tail) |
|
2536 |
if (!owntype.contains(l.head)) { |
|
2537 |
log.error(tree.pos(), "undetermined.type", owntype1); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2538 |
owntype1 = types.createErrorType(owntype1); |
10 | 2539 |
} |
2540 |
owntype = owntype1; |
|
2541 |
} |
|
2542 |
||
2543 |
// If the variable is a constant, record constant value in |
|
2544 |
// computed type. |
|
2545 |
if (v.getConstValue() != null && isStaticReference(tree)) |
|
2546 |
owntype = owntype.constType(v.getConstValue()); |
|
2547 |
||
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2548 |
if (resultInfo.pkind == VAL) { |
10 | 2549 |
owntype = capture(owntype); // capture "names as expressions" |
2550 |
} |
|
2551 |
break; |
|
2552 |
case MTH: { |
|
2553 |
JCMethodInvocation app = (JCMethodInvocation)env.tree; |
|
2554 |
owntype = checkMethod(site, sym, env, app.args, |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2555 |
resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments(), |
10 | 2556 |
env.info.varArgs); |
2557 |
break; |
|
2558 |
} |
|
2559 |
case PCK: case ERR: |
|
2560 |
owntype = sym.type; |
|
2561 |
break; |
|
2562 |
default: |
|
2563 |
throw new AssertionError("unexpected kind: " + sym.kind + |
|
2564 |
" in tree " + tree); |
|
2565 |
} |
|
2566 |
||
2567 |
// Test (1): emit a `deprecation' warning if symbol is deprecated. |
|
2568 |
// (for constructors, the error was given when the constructor was |
|
2569 |
// resolved) |
|
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
2570 |
|
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
2571 |
if (sym.name != names.init) { |
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
2572 |
chk.checkDeprecated(tree.pos(), env.info.scope.owner, sym); |
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
2573 |
chk.checkSunAPI(tree.pos(), sym); |
3661 | 2574 |
} |
10 | 2575 |
|
2576 |
// Test (3): if symbol is a variable, check that its type and |
|
2577 |
// kind are compatible with the prototype and protokind. |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2578 |
return check(tree, owntype, sym.kind, resultInfo); |
10 | 2579 |
} |
2580 |
||
2581 |
/** Check that variable is initialized and evaluate the variable's |
|
2582 |
* initializer, if not yet done. Also check that variable is not |
|
2583 |
* referenced before it is defined. |
|
2584 |
* @param tree The tree making up the variable reference. |
|
2585 |
* @param env The current environment. |
|
2586 |
* @param v The variable's symbol. |
|
2587 |
*/ |
|
2588 |
private void checkInit(JCTree tree, |
|
2589 |
Env<AttrContext> env, |
|
2590 |
VarSymbol v, |
|
2591 |
boolean onlyWarning) { |
|
2592 |
// System.err.println(v + " " + ((v.flags() & STATIC) != 0) + " " + |
|
2593 |
// tree.pos + " " + v.pos + " " + |
|
2594 |
// Resolve.isStatic(env));//DEBUG |
|
2595 |
||
2596 |
// A forward reference is diagnosed if the declaration position |
|
2597 |
// of the variable is greater than the current tree position |
|
2598 |
// and the tree and variable definition occur in the same class |
|
2599 |
// definition. Note that writes don't count as references. |
|
2600 |
// This check applies only to class and instance |
|
2601 |
// variables. Local variables follow different scope rules, |
|
2602 |
// and are subject to definite assignment checking. |
|
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
2603 |
if ((env.info.enclVar == v || v.pos > tree.pos) && |
10 | 2604 |
v.owner.kind == TYP && |
2605 |
canOwnInitializer(env.info.scope.owner) && |
|
2606 |
v.owner == env.info.scope.owner.enclClass() && |
|
2607 |
((v.flags() & STATIC) != 0) == Resolve.isStatic(env) && |
|
10950 | 2608 |
(!env.tree.hasTag(ASSIGN) || |
10 | 2609 |
TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) { |
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
2610 |
String suffix = (env.info.enclVar == v) ? |
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
2611 |
"self.ref" : "forward.ref"; |
325
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2612 |
if (!onlyWarning || isStaticEnumField(v)) { |
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
2613 |
log.error(tree.pos(), "illegal." + suffix); |
10 | 2614 |
} else if (useBeforeDeclarationWarning) { |
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
1040
diff
changeset
|
2615 |
log.warning(tree.pos(), suffix, v); |
10 | 2616 |
} |
2617 |
} |
|
2618 |
||
2619 |
v.getConstValue(); // ensure initializer is evaluated |
|
2620 |
||
2621 |
checkEnumInitializer(tree, env, v); |
|
2622 |
} |
|
2623 |
||
2624 |
/** |
|
2625 |
* Check for illegal references to static members of enum. In |
|
2626 |
* an enum type, constructors and initializers may not |
|
2627 |
* reference its static members unless they are constant. |
|
2628 |
* |
|
2629 |
* @param tree The tree making up the variable reference. |
|
2630 |
* @param env The current environment. |
|
2631 |
* @param v The variable's symbol. |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9300
diff
changeset
|
2632 |
* @jls section 8.9 Enums |
10 | 2633 |
*/ |
2634 |
private void checkEnumInitializer(JCTree tree, Env<AttrContext> env, VarSymbol v) { |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9300
diff
changeset
|
2635 |
// JLS: |
10 | 2636 |
// |
2637 |
// "It is a compile-time error to reference a static field |
|
2638 |
// of an enum type that is not a compile-time constant |
|
2639 |
// (15.28) from constructors, instance initializer blocks, |
|
2640 |
// or instance variable initializer expressions of that |
|
2641 |
// type. It is a compile-time error for the constructors, |
|
2642 |
// instance initializer blocks, or instance variable |
|
2643 |
// initializer expressions of an enum constant e to refer |
|
2644 |
// to itself or to an enum constant of the same type that |
|
2645 |
// is declared to the right of e." |
|
325
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2646 |
if (isStaticEnumField(v)) { |
10 | 2647 |
ClassSymbol enclClass = env.info.scope.owner.enclClass(); |
2648 |
||
2649 |
if (enclClass == null || enclClass.owner == null) |
|
2650 |
return; |
|
2651 |
||
2652 |
// See if the enclosing class is the enum (or a |
|
2653 |
// subclass thereof) declaring v. If not, this |
|
2654 |
// reference is OK. |
|
2655 |
if (v.owner != enclClass && !types.isSubtype(enclClass.type, v.owner.type)) |
|
2656 |
return; |
|
2657 |
||
2658 |
// If the reference isn't from an initializer, then |
|
2659 |
// the reference is OK. |
|
2660 |
if (!Resolve.isInitializer(env)) |
|
2661 |
return; |
|
2662 |
||
2663 |
log.error(tree.pos(), "illegal.enum.static.ref"); |
|
2664 |
} |
|
2665 |
} |
|
2666 |
||
325
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2667 |
/** Is the given symbol a static, non-constant field of an Enum? |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2668 |
* Note: enum literals should not be regarded as such |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2669 |
*/ |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2670 |
private boolean isStaticEnumField(VarSymbol v) { |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2671 |
return Flags.isEnum(v.owner) && |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2672 |
Flags.isStatic(v) && |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2673 |
!Flags.isConstant(v) && |
44df0e9643b4
6509042: javac rejects class literals in enum constructors
mcimadamore
parents:
166
diff
changeset
|
2674 |
v.name != names._class; |
10 | 2675 |
} |
2676 |
||
2677 |
/** Can the given symbol be the owner of code which forms part |
|
2678 |
* if class initialization? This is the case if the symbol is |
|
2679 |
* a type or field, or if the symbol is the synthetic method. |
|
2680 |
* owning a block. |
|
2681 |
*/ |
|
2682 |
private boolean canOwnInitializer(Symbol sym) { |
|
2683 |
return |
|
2684 |
(sym.kind & (VAR | TYP)) != 0 || |
|
2685 |
(sym.kind == MTH && (sym.flags() & BLOCK) != 0); |
|
2686 |
} |
|
2687 |
||
2688 |
Warner noteWarner = new Warner(); |
|
2689 |
||
2690 |
/** |
|
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2691 |
* Check that method arguments conform to its instantiation. |
10 | 2692 |
**/ |
2693 |
public Type checkMethod(Type site, |
|
2694 |
Symbol sym, |
|
2695 |
Env<AttrContext> env, |
|
2696 |
final List<JCExpression> argtrees, |
|
2697 |
List<Type> argtypes, |
|
2698 |
List<Type> typeargtypes, |
|
2699 |
boolean useVarargs) { |
|
2700 |
// Test (5): if symbol is an instance method of a raw type, issue |
|
2701 |
// an unchecked warning if its argument types change under erasure. |
|
2702 |
if (allowGenerics && |
|
2703 |
(sym.flags() & STATIC) == 0 && |
|
2704 |
(site.tag == CLASS || site.tag == TYPEVAR)) { |
|
2705 |
Type s = types.asOuterSuper(site, sym.owner); |
|
2706 |
if (s != null && s.isRaw() && |
|
2707 |
!types.isSameTypes(sym.type.getParameterTypes(), |
|
2708 |
sym.erasure(types).getParameterTypes())) { |
|
2709 |
chk.warnUnchecked(env.tree.pos(), |
|
2710 |
"unchecked.call.mbr.of.raw.type", |
|
2711 |
sym, s); |
|
2712 |
} |
|
2713 |
} |
|
2714 |
||
2715 |
// Compute the identifier's instantiated type. |
|
2716 |
// For methods, we need to compute the instance type by |
|
2717 |
// Resolve.instantiate from the symbol's type as well as |
|
2718 |
// any type arguments and value arguments. |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2719 |
noteWarner.clear(); |
10 | 2720 |
Type owntype = rs.instantiate(env, |
2721 |
site, |
|
2722 |
sym, |
|
2723 |
argtypes, |
|
2724 |
typeargtypes, |
|
2725 |
true, |
|
2726 |
useVarargs, |
|
2727 |
noteWarner); |
|
2728 |
||
12087
31eeebc3ef49
7151802: compiler update caused sqe test failed
mcimadamore
parents:
12081
diff
changeset
|
2729 |
boolean unchecked = noteWarner.hasNonSilentLint(LintCategory.UNCHECKED); |
31eeebc3ef49
7151802: compiler update caused sqe test failed
mcimadamore
parents:
12081
diff
changeset
|
2730 |
|
10 | 2731 |
// If this fails, something went wrong; we should not have |
2732 |
// found the identifier in the first place. |
|
2733 |
if (owntype == null) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2734 |
if (!pt().isErroneous()) |
10 | 2735 |
log.error(env.tree.pos(), |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2736 |
"internal.error.cant.instantiate", |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2737 |
sym, site, |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2738 |
Type.toString(pt().getParameterTypes())); |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2739 |
owntype = types.createErrorType(site); |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2740 |
return types.createErrorType(site); |
12087
31eeebc3ef49
7151802: compiler update caused sqe test failed
mcimadamore
parents:
12081
diff
changeset
|
2741 |
} else if (owntype.getReturnType().tag == FORALL && !unchecked) { |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2742 |
return owntype; |
10 | 2743 |
} else { |
12087
31eeebc3ef49
7151802: compiler update caused sqe test failed
mcimadamore
parents:
12081
diff
changeset
|
2744 |
return chk.checkMethod(owntype, sym, env, argtrees, argtypes, useVarargs, unchecked); |
10 | 2745 |
} |
12080
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2746 |
} |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2747 |
|
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2748 |
/** |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2749 |
* Check that constructor arguments conform to its instantiation. |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2750 |
**/ |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2751 |
public Type checkConstructor(Type site, |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2752 |
Symbol sym, |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2753 |
Env<AttrContext> env, |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2754 |
final List<JCExpression> argtrees, |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2755 |
List<Type> argtypes, |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2756 |
List<Type> typeargtypes, |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2757 |
boolean useVarargs) { |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2758 |
Type owntype = checkMethod(site, sym, env, argtrees, argtypes, typeargtypes, useVarargs); |
23101f54df44
7144506: Attr.checkMethod should be called after inference variables have been fixed
mcimadamore
parents:
12078
diff
changeset
|
2759 |
chk.checkType(env.tree.pos(), owntype.getReturnType(), syms.voidType); |
10 | 2760 |
return owntype; |
2761 |
} |
|
2762 |
||
2763 |
public void visitLiteral(JCLiteral tree) { |
|
2764 |
result = check( |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2765 |
tree, litType(tree.typetag).constType(tree.value), VAL, resultInfo); |
10 | 2766 |
} |
2767 |
//where |
|
2768 |
/** Return the type of a literal with given type tag. |
|
2769 |
*/ |
|
2770 |
Type litType(int tag) { |
|
2771 |
return (tag == TypeTags.CLASS) ? syms.stringType : syms.typeOfTag[tag]; |
|
2772 |
} |
|
2773 |
||
2774 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2775 |
result = check(tree, syms.typeOfTag[tree.typetag], TYP, resultInfo); |
10 | 2776 |
} |
2777 |
||
2778 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
2779 |
Type etype = attribType(tree.elemtype, env); |
|
2780 |
Type type = new ArrayType(etype, syms.arrayClass); |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2781 |
result = check(tree, type, TYP, resultInfo); |
10 | 2782 |
} |
2783 |
||
2784 |
/** Visitor method for parameterized types. |
|
2785 |
* Bound checking is left until later, since types are attributed |
|
2786 |
* before supertype structure is completely known |
|
2787 |
*/ |
|
2788 |
public void visitTypeApply(JCTypeApply tree) { |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2789 |
Type owntype = types.createErrorType(tree.type); |
10 | 2790 |
|
2791 |
// Attribute functor part of application and make sure it's a class. |
|
2792 |
Type clazztype = chk.checkClassType(tree.clazz.pos(), attribType(tree.clazz, env)); |
|
2793 |
||
2794 |
// Attribute type parameters |
|
2795 |
List<Type> actuals = attribTypes(tree.arguments, env); |
|
2796 |
||
2797 |
if (clazztype.tag == CLASS) { |
|
2798 |
List<Type> formals = clazztype.tsym.type.getTypeArguments(); |
|
10198
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
2799 |
if (actuals.isEmpty()) //diamond |
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
2800 |
actuals = formals; |
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
2801 |
|
84698d93792c
7046778: Project Coin: problem with diamond and member inner classes
mcimadamore
parents:
10187
diff
changeset
|
2802 |
if (actuals.length() == formals.length()) { |
10 | 2803 |
List<Type> a = actuals; |
2804 |
List<Type> f = formals; |
|
2805 |
while (a.nonEmpty()) { |
|
2806 |
a.head = a.head.withTypeVar(f.head); |
|
2807 |
a = a.tail; |
|
2808 |
f = f.tail; |
|
2809 |
} |
|
2810 |
// Compute the proper generic outer |
|
2811 |
Type clazzOuter = clazztype.getEnclosingType(); |
|
2812 |
if (clazzOuter.tag == CLASS) { |
|
2813 |
Type site; |
|
3149 | 2814 |
JCExpression clazz = TreeInfo.typeIn(tree.clazz); |
10950 | 2815 |
if (clazz.hasTag(IDENT)) { |
10 | 2816 |
site = env.enclClass.sym.type; |
10950 | 2817 |
} else if (clazz.hasTag(SELECT)) { |
3149 | 2818 |
site = ((JCFieldAccess) clazz).selected.type; |
10 | 2819 |
} else throw new AssertionError(""+tree); |
2820 |
if (clazzOuter.tag == CLASS && site != clazzOuter) { |
|
2821 |
if (site.tag == CLASS) |
|
2822 |
site = types.asOuterSuper(site, clazzOuter.tsym); |
|
2823 |
if (site == null) |
|
2824 |
site = types.erasure(clazzOuter); |
|
2825 |
clazzOuter = site; |
|
2826 |
} |
|
2827 |
} |
|
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
2828 |
owntype = new ClassType(clazzOuter, actuals, clazztype.tsym); |
10 | 2829 |
} else { |
2830 |
if (formals.length() != 0) { |
|
2831 |
log.error(tree.pos(), "wrong.number.type.args", |
|
2832 |
Integer.toString(formals.length())); |
|
2833 |
} else { |
|
2834 |
log.error(tree.pos(), "type.doesnt.take.params", clazztype.tsym); |
|
2835 |
} |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1045
diff
changeset
|
2836 |
owntype = types.createErrorType(tree.type); |
10 | 2837 |
} |
2838 |
} |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2839 |
result = check(tree, owntype, TYP, resultInfo); |
10 | 2840 |
} |
2841 |
||
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
9079
diff
changeset
|
2842 |
public void visitTypeUnion(JCTypeUnion tree) { |
7622
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
2843 |
ListBuffer<Type> multicatchTypes = ListBuffer.lb(); |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2844 |
ListBuffer<Type> all_multicatchTypes = null; // lazy, only if needed |
7622
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
2845 |
for (JCExpression typeTree : tree.alternatives) { |
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
2846 |
Type ctype = attribType(typeTree, env); |
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
2847 |
ctype = chk.checkType(typeTree.pos(), |
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
2848 |
chk.checkClassType(typeTree.pos(), ctype), |
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
2849 |
syms.throwableType); |
9074
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2850 |
if (!ctype.isErroneous()) { |
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
9079
diff
changeset
|
2851 |
//check that alternatives of a union type are pairwise |
9074
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2852 |
//unrelated w.r.t. subtyping |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2853 |
if (chk.intersects(ctype, multicatchTypes.toList())) { |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2854 |
for (Type t : multicatchTypes) { |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2855 |
boolean sub = types.isSubtype(ctype, t); |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2856 |
boolean sup = types.isSubtype(t, ctype); |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2857 |
if (sub || sup) { |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2858 |
//assume 'a' <: 'b' |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2859 |
Type a = sub ? ctype : t; |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2860 |
Type b = sub ? t : ctype; |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2861 |
log.error(typeTree.pos(), "multicatch.types.must.be.disjoint", a, b); |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2862 |
} |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2863 |
} |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2864 |
} |
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2865 |
multicatchTypes.append(ctype); |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2866 |
if (all_multicatchTypes != null) |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2867 |
all_multicatchTypes.append(ctype); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2868 |
} else { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2869 |
if (all_multicatchTypes == null) { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2870 |
all_multicatchTypes = ListBuffer.lb(); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2871 |
all_multicatchTypes.appendList(multicatchTypes); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2872 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2873 |
all_multicatchTypes.append(ctype); |
9074
76b505d19026
7030606: Project-coin: multi-catch types should be pairwise disjoint
mcimadamore
parents:
8845
diff
changeset
|
2874 |
} |
7622
ee16e77d07f0
7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
mcimadamore
parents:
7618
diff
changeset
|
2875 |
} |
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2876 |
Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, resultInfo); |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2877 |
if (t.tag == CLASS) { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2878 |
List<Type> alternatives = |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2879 |
((all_multicatchTypes == null) ? multicatchTypes : all_multicatchTypes).toList(); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2880 |
t = new UnionClassType((ClassType) t, alternatives); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2881 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
9303
diff
changeset
|
2882 |
tree.type = result = t; |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5489
diff
changeset
|
2883 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5489
diff
changeset
|
2884 |
|
10 | 2885 |
public void visitTypeParameter(JCTypeParameter tree) { |
2886 |
TypeVar a = (TypeVar)tree.type; |
|
2887 |
Set<Type> boundSet = new HashSet<Type>(); |
|
2888 |
if (a.bound.isErroneous()) |
|
2889 |
return; |
|
2890 |
List<Type> bs = types.getBounds(a); |
|
2891 |
if (tree.bounds.nonEmpty()) { |
|
2892 |
// accept class or interface or typevar as first bound. |
|
2893 |
Type b = checkBase(bs.head, tree.bounds.head, env, false, false, false); |
|
2894 |
boundSet.add(types.erasure(b)); |
|
1532
ae41c47516e5
6680106: StackOverFlowError for Cyclic inheritance in TypeParameters with ArrayType Bounds
mcimadamore
parents:
1528
diff
changeset
|
2895 |
if (b.isErroneous()) { |
ae41c47516e5
6680106: StackOverFlowError for Cyclic inheritance in TypeParameters with ArrayType Bounds
mcimadamore
parents:
1528
diff
changeset
|
2896 |
a.bound = b; |
ae41c47516e5
6680106: StackOverFlowError for Cyclic inheritance in TypeParameters with ArrayType Bounds
mcimadamore
parents:
1528
diff
changeset
|
2897 |
} |
ae41c47516e5
6680106: StackOverFlowError for Cyclic inheritance in TypeParameters with ArrayType Bounds
mcimadamore
parents:
1528
diff
changeset
|
2898 |
else if (b.tag == TYPEVAR) { |
10 | 2899 |
// if first bound was a typevar, do not accept further bounds. |
2900 |
if (tree.bounds.tail.nonEmpty()) { |
|
2901 |
log.error(tree.bounds.tail.head.pos(), |
|
2902 |
"type.var.may.not.be.followed.by.other.bounds"); |
|
2903 |
tree.bounds = List.of(tree.bounds.head); |
|
164
c1e219636b4e
6608214: Exception throw while analysing a file with error
mcimadamore
parents:
163
diff
changeset
|
2904 |
a.bound = bs.head; |
10 | 2905 |
} |
2906 |
} else { |
|
2907 |
// if first bound was a class or interface, accept only interfaces |
|
2908 |
// as further bounds. |
|
2909 |
for (JCExpression bound : tree.bounds.tail) { |
|
2910 |
bs = bs.tail; |
|
2911 |
Type i = checkBase(bs.head, bound, env, false, true, false); |
|
1532
ae41c47516e5
6680106: StackOverFlowError for Cyclic inheritance in TypeParameters with ArrayType Bounds
mcimadamore
parents:
1528
diff
changeset
|
2912 |
if (i.isErroneous()) |
ae41c47516e5
6680106: StackOverFlowError for Cyclic inheritance in TypeParameters with ArrayType Bounds
mcimadamore
parents:
1528
diff
changeset
|
2913 |
a.bound = i; |
ae41c47516e5
6680106: StackOverFlowError for Cyclic inheritance in TypeParameters with ArrayType Bounds
mcimadamore
parents:
1528
diff
changeset
|
2914 |
else if (i.tag == CLASS) |
10 | 2915 |
chk.checkNotRepeated(bound.pos(), types.erasure(i), boundSet); |
2916 |
} |
|
2917 |
} |
|
2918 |
} |
|
2919 |
bs = types.getBounds(a); |
|
2920 |
||
2921 |
// in case of multiple bounds ... |
|
2922 |
if (bs.length() > 1) { |
|
2923 |
// ... the variable's bound is a class type flagged COMPOUND |
|
2924 |
// (see comment for TypeVar.bound). |
|
2925 |
// In this case, generate a class tree that represents the |
|
2926 |
// bound class, ... |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8622
diff
changeset
|
2927 |
JCExpression extending; |
10 | 2928 |
List<JCExpression> implementing; |
2929 |
if ((bs.head.tsym.flags() & INTERFACE) == 0) { |
|
2930 |
extending = tree.bounds.head; |
|
2931 |
implementing = tree.bounds.tail; |
|
2932 |
} else { |
|
2933 |
extending = null; |
|
2934 |
implementing = tree.bounds; |
|
2935 |
} |
|
2936 |
JCClassDecl cd = make.at(tree.pos).ClassDef( |
|
2937 |
make.Modifiers(PUBLIC | ABSTRACT), |
|
2938 |
tree.name, List.<JCTypeParameter>nil(), |
|
2939 |
extending, implementing, List.<JCTree>nil()); |
|
2940 |
||
2941 |
ClassSymbol c = (ClassSymbol)a.getUpperBound().tsym; |
|
8032 | 2942 |
Assert.check((c.flags() & COMPOUND) != 0); |
10 | 2943 |
cd.sym = c; |
2944 |
c.sourcefile = env.toplevel.sourcefile; |
|
2945 |
||
2946 |
// ... and attribute the bound class |
|
2947 |
c.flags_field |= UNATTRIBUTED; |
|
2948 |
Env<AttrContext> cenv = enter.classEnv(cd, env); |
|
2949 |
enter.typeEnvs.put(c, cenv); |
|
2950 |
} |
|
2951 |
} |
|
2952 |
||
2953 |
||
2954 |
public void visitWildcard(JCWildcard tree) { |
|
2955 |
//- System.err.println("visitWildcard("+tree+");");//DEBUG |
|
2956 |
Type type = (tree.kind.kind == BoundKind.UNBOUND) |
|
2957 |
? syms.objectType |
|
2958 |
: attribType(tree.inner, env); |
|
2959 |
result = check(tree, new WildcardType(chk.checkRefType(tree.pos(), type), |
|
2960 |
tree.kind.kind, |
|
2961 |
syms.boundClass), |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2962 |
TYP, resultInfo); |
10 | 2963 |
} |
2964 |
||
2965 |
public void visitAnnotation(JCAnnotation tree) { |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2966 |
log.error(tree.pos(), "annotation.not.valid.for.type", pt()); |
10 | 2967 |
result = tree.type = syms.errType; |
2968 |
} |
|
2969 |
||
2970 |
public void visitErroneous(JCErroneous tree) { |
|
2971 |
if (tree.errs != null) |
|
2972 |
for (JCTree err : tree.errs) |
|
12081
42f541476d14
7133238: Merge proto-kind and proto-type into a single result class
mcimadamore
parents:
12080
diff
changeset
|
2973 |
attribTree(err, env, new ResultInfo(ERR, pt())); |
10 | 2974 |
result = tree.type = syms.errType; |
2975 |
} |
|
2976 |
||
2977 |
/** Default visitor method for all other trees. |
|
2978 |
*/ |
|
2979 |
public void visitTree(JCTree tree) { |
|
2980 |
throw new AssertionError(); |
|
2981 |
} |
|
2982 |
||
8845 | 2983 |
/** |
2984 |
* Attribute an env for either a top level tree or class declaration. |
|
2985 |
*/ |
|
2986 |
public void attrib(Env<AttrContext> env) { |
|
10950 | 2987 |
if (env.tree.hasTag(TOPLEVEL)) |
8845 | 2988 |
attribTopLevel(env); |
2989 |
else |
|
2990 |
attribClass(env.tree.pos(), env.enclClass.sym); |
|
2991 |
} |
|
2992 |
||
2993 |
/** |
|
2994 |
* Attribute a top level tree. These trees are encountered when the |
|
2995 |
* package declaration has annotations. |
|
2996 |
*/ |
|
2997 |
public void attribTopLevel(Env<AttrContext> env) { |
|
2998 |
JCCompilationUnit toplevel = env.toplevel; |
|
2999 |
try { |
|
3000 |
annotate.flush(); |
|
3001 |
chk.validateAnnotations(toplevel.packageAnnotations, toplevel.packge); |
|
3002 |
} catch (CompletionFailure ex) { |
|
3003 |
chk.completionError(toplevel.pos(), ex); |
|
3004 |
} |
|
3005 |
} |
|
3006 |
||
10 | 3007 |
/** Main method: attribute class definition associated with given class symbol. |
3008 |
* reporting completion failures at the given position. |
|
3009 |
* @param pos The source position at which completion errors are to be |
|
3010 |
* reported. |
|
3011 |
* @param c The class symbol whose definition will be attributed. |
|
3012 |
*/ |
|
3013 |
public void attribClass(DiagnosticPosition pos, ClassSymbol c) { |
|
3014 |
try { |
|
3015 |
annotate.flush(); |
|
3016 |
attribClass(c); |
|
3017 |
} catch (CompletionFailure ex) { |
|
3018 |
chk.completionError(pos, ex); |
|
3019 |
} |
|
3020 |
} |
|
3021 |
||
3022 |
/** Attribute class definition associated with given class symbol. |
|
3023 |
* @param c The class symbol whose definition will be attributed. |
|
3024 |
*/ |
|
3025 |
void attribClass(ClassSymbol c) throws CompletionFailure { |
|
3026 |
if (c.type.tag == ERROR) return; |
|
3027 |
||
3028 |
// Check for cycles in the inheritance graph, which can arise from |
|
3029 |
// ill-formed class files. |
|
3030 |
chk.checkNonCyclic(null, c.type); |
|
3031 |
||
3032 |
Type st = types.supertype(c.type); |
|
3033 |
if ((c.flags_field & Flags.COMPOUND) == 0) { |
|
3034 |
// First, attribute superclass. |
|
3035 |
if (st.tag == CLASS) |
|
3036 |
attribClass((ClassSymbol)st.tsym); |
|
3037 |
||
3038 |
// Next attribute owner, if it is a class. |
|
3039 |
if (c.owner.kind == TYP && c.owner.type.tag == CLASS) |
|
3040 |
attribClass((ClassSymbol)c.owner); |
|
3041 |
} |
|
3042 |
||
3043 |
// The previous operations might have attributed the current class |
|
3044 |
// if there was a cycle. So we test first whether the class is still |
|
3045 |
// UNATTRIBUTED. |
|
3046 |
if ((c.flags_field & UNATTRIBUTED) != 0) { |
|
3047 |
c.flags_field &= ~UNATTRIBUTED; |
|
3048 |
||
3049 |
// Get environment current at the point of class definition. |
|
3050 |
Env<AttrContext> env = enter.typeEnvs.get(c); |
|
3051 |
||
3052 |
// The info.lint field in the envs stored in enter.typeEnvs is deliberately uninitialized, |
|
3053 |
// because the annotations were not available at the time the env was created. Therefore, |
|
3054 |
// we look up the environment chain for the first enclosing environment for which the |
|
3055 |
// lint value is set. Typically, this is the parent env, but might be further if there |
|
3056 |
// are any envs created as a result of TypeParameter nodes. |
|
3057 |
Env<AttrContext> lintEnv = env; |
|
3058 |
while (lintEnv.info.lint == null) |
|
3059 |
lintEnv = lintEnv.next; |
|
3060 |
||
3061 |
// Having found the enclosing lint value, we can initialize the lint value for this class |
|
3062 |
env.info.lint = lintEnv.info.lint.augment(c.attributes_field, c.flags()); |
|
3063 |
||
3064 |
Lint prevLint = chk.setLint(env.info.lint); |
|
3065 |
JavaFileObject prev = log.useSource(c.sourcefile); |
|
3066 |
||
3067 |
try { |
|
3068 |
// java.lang.Enum may not be subclassed by a non-enum |
|
3069 |
if (st.tsym == syms.enumSym && |
|
3070 |
((c.flags_field & (Flags.ENUM|Flags.COMPOUND)) == 0)) |
|
3071 |
log.error(env.tree.pos(), "enum.no.subclassing"); |
|
3072 |
||
3073 |
// Enums may not be extended by source-level classes |
|
3074 |
if (st.tsym != null && |
|
3075 |
((st.tsym.flags_field & Flags.ENUM) != 0) && |
|
941
2589047a9c5d
6675483: Javac rejects multiple type-variable bound declarations starting with an enum type
mcimadamore
parents:
939
diff
changeset
|
3076 |
((c.flags_field & (Flags.ENUM | Flags.COMPOUND)) == 0) && |
10 | 3077 |
!target.compilerBootstrap(c)) { |
3078 |
log.error(env.tree.pos(), "enum.types.not.extensible"); |
|
3079 |
} |
|
3080 |
attribClassBody(env, c); |
|
3081 |
||
3082 |
chk.checkDeprecatedAnnotation(env.tree.pos(), c); |
|
3083 |
} finally { |
|
3084 |
log.useSource(prev); |
|
3085 |
chk.setLint(prevLint); |
|
3086 |
} |
|
3087 |
||
3088 |
} |
|
3089 |
} |
|
3090 |
||
3091 |
public void visitImport(JCImport tree) { |
|
3092 |
// nothing to do |
|
3093 |
} |
|
3094 |
||
3095 |
/** Finish the attribution of a class. */ |
|
3096 |
private void attribClassBody(Env<AttrContext> env, ClassSymbol c) { |
|
3097 |
JCClassDecl tree = (JCClassDecl)env.tree; |
|
8032 | 3098 |
Assert.check(c == tree.sym); |
10 | 3099 |
|
3100 |
// Validate annotations |
|
3101 |
chk.validateAnnotations(tree.mods.annotations, c); |
|
3102 |
||
3103 |
// Validate type parameters, supertype and interfaces. |
|
661
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
512
diff
changeset
|
3104 |
attribBounds(tree.typarams); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3105 |
if (!c.isAnonymous()) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3106 |
//already checked if anonymous |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3107 |
chk.validate(tree.typarams, env); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3108 |
chk.validate(tree.extending, env); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3109 |
chk.validate(tree.implementing, env); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3110 |
} |
10 | 3111 |
|
3112 |
// If this is a non-abstract class, check that it has no abstract |
|
3113 |
// methods or unimplemented methods of an implemented interface. |
|
3114 |
if ((c.flags() & (ABSTRACT | INTERFACE)) == 0) { |
|
3115 |
if (!relax) |
|
3116 |
chk.checkAllDefined(tree.pos(), c); |
|
3117 |
} |
|
3118 |
||
3119 |
if ((c.flags() & ANNOTATION) != 0) { |
|
3120 |
if (tree.implementing.nonEmpty()) |
|
3121 |
log.error(tree.implementing.head.pos(), |
|
3122 |
"cant.extend.intf.annotation"); |
|
3123 |
if (tree.typarams.nonEmpty()) |
|
3124 |
log.error(tree.typarams.head.pos(), |
|
3125 |
"intf.annotation.cant.have.type.params"); |
|
3126 |
} else { |
|
3127 |
// Check that all extended classes and interfaces |
|
3128 |
// are compatible (i.e. no two define methods with same arguments |
|
3129 |
// yet different return types). (JLS 8.4.6.3) |
|
3130 |
chk.checkCompatibleSupertypes(tree.pos(), c.type); |
|
3131 |
} |
|
3132 |
||
3133 |
// Check that class does not import the same parameterized interface |
|
3134 |
// with two different argument lists. |
|
3135 |
chk.checkClassBounds(tree.pos(), c.type); |
|
3136 |
||
3137 |
tree.type = c.type; |
|
3138 |
||
8032 | 3139 |
for (List<JCTypeParameter> l = tree.typarams; |
3140 |
l.nonEmpty(); l = l.tail) { |
|
3141 |
Assert.checkNonNull(env.info.scope.lookup(l.head.name).scope); |
|
10 | 3142 |
} |
3143 |
||
3144 |
// Check that a generic class doesn't extend Throwable |
|
3145 |
if (!c.type.allparams().isEmpty() && types.isSubtype(c.type, syms.throwableType)) |
|
3146 |
log.error(tree.extending.pos(), "generic.throwable"); |
|
3147 |
||
3148 |
// Check that all methods which implement some |
|
3149 |
// method conform to the method they implement. |
|
3150 |
chk.checkImplementations(tree); |
|
3151 |
||
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
3152 |
//check that a resource implementing AutoCloseable cannot throw InterruptedException |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
3153 |
checkAutoCloseable(tree.pos(), env, c.type); |
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
9075
diff
changeset
|
3154 |
|
10 | 3155 |
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
3156 |
// Attribute declaration |
|
3157 |
attribStat(l.head, env); |
|
3158 |
// Check that declarations in inner classes are not static (JLS 8.1.2) |
|
3159 |
// Make an exception for static constants. |
|
3160 |
if (c.owner.kind != PCK && |
|
3161 |
((c.flags() & STATIC) == 0 || c.name == names.empty) && |
|
3162 |
(TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) { |
|
3163 |
Symbol sym = null; |
|
10950 | 3164 |
if (l.head.hasTag(VARDEF)) sym = ((JCVariableDecl) l.head).sym; |
10 | 3165 |
if (sym == null || |
3166 |
sym.kind != VAR || |
|
3167 |
((VarSymbol) sym).getConstValue() == null) |
|
8239
d2c934e951e2
7014715: javac returns different error code for certain failure(s)
mcimadamore
parents:
8237
diff
changeset
|
3168 |
log.error(l.head.pos(), "icls.cant.have.static.decl", c); |
10 | 3169 |
} |
3170 |
} |
|
3171 |
||
3172 |
// Check for cycles among non-initial constructors. |
|
3173 |
chk.checkCyclicConstructors(tree); |
|
3174 |
||
3175 |
// Check for cycles among annotation elements. |
|
3176 |
chk.checkNonCyclicElements(tree); |
|
3177 |
||
3178 |
// Check for proper use of serialVersionUID |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3179 |
if (env.info.lint.isEnabled(LintCategory.SERIAL) && |
10 | 3180 |
isSerializable(c) && |
3181 |
(c.flags() & Flags.ENUM) == 0 && |
|
3182 |
(c.flags() & ABSTRACT) == 0) { |
|
3183 |
checkSerialVersionUID(tree, c); |
|
3184 |
} |
|
3185 |
} |
|
3186 |
// where |
|
3187 |
/** check if a class is a subtype of Serializable, if that is available. */ |
|
3188 |
private boolean isSerializable(ClassSymbol c) { |
|
3189 |
try { |
|
3190 |
syms.serializableType.complete(); |
|
3191 |
} |
|
3192 |
catch (CompletionFailure e) { |
|
3193 |
return false; |
|
3194 |
} |
|
3195 |
return types.isSubtype(c.type, syms.serializableType); |
|
3196 |
} |
|
3197 |
||
3198 |
/** Check that an appropriate serialVersionUID member is defined. */ |
|
3199 |
private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) { |
|
3200 |
||
3201 |
// check for presence of serialVersionUID |
|
3202 |
Scope.Entry e = c.members().lookup(names.serialVersionUID); |
|
3203 |
while (e.scope != null && e.sym.kind != VAR) e = e.next(); |
|
3204 |
if (e.scope == null) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3205 |
log.warning(LintCategory.SERIAL, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
3206 |
tree.pos(), "missing.SVUID", c); |
10 | 3207 |
return; |
3208 |
} |
|
3209 |
||
3210 |
// check that it is static final |
|
3211 |
VarSymbol svuid = (VarSymbol)e.sym; |
|
3212 |
if ((svuid.flags() & (STATIC | FINAL)) != |
|
3213 |
(STATIC | FINAL)) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3214 |
log.warning(LintCategory.SERIAL, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
3215 |
TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c); |
10 | 3216 |
|
3217 |
// check that it is long |
|
3218 |
else if (svuid.type.tag != TypeTags.LONG) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3219 |
log.warning(LintCategory.SERIAL, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
3220 |
TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c); |
10 | 3221 |
|
3222 |
// check constant |
|
3223 |
else if (svuid.getConstValue() == null) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
3224 |
log.warning(LintCategory.SERIAL, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
3225 |
TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c); |
10 | 3226 |
} |
3227 |
||
3228 |
private Type capture(Type type) { |
|
3229 |
return types.capture(type); |
|
3230 |
} |
|
3149 | 3231 |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3232 |
// <editor-fold desc="post-attribution visitor"> |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3233 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3234 |
/** |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3235 |
* Handle missing types/symbols in an AST. This routine is useful when |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3236 |
* the compiler has encountered some errors (which might have ended up |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3237 |
* terminating attribution abruptly); if the compiler is used in fail-over |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3238 |
* mode (e.g. by an IDE) and the AST contains semantic errors, this routine |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3239 |
* prevents NPE to be progagated during subsequent compilation steps. |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3240 |
*/ |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3241 |
public void postAttr(Env<AttrContext> env) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3242 |
new PostAttrAnalyzer().scan(env.tree); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3243 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3244 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3245 |
class PostAttrAnalyzer extends TreeScanner { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3246 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3247 |
private void initTypeIfNeeded(JCTree that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3248 |
if (that.type == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3249 |
that.type = syms.unknownType; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3250 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3251 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3252 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3253 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3254 |
public void scan(JCTree tree) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3255 |
if (tree == null) return; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3256 |
if (tree instanceof JCExpression) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3257 |
initTypeIfNeeded(tree); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3258 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3259 |
super.scan(tree); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3260 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3261 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3262 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3263 |
public void visitIdent(JCIdent that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3264 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3265 |
that.sym = syms.unknownSymbol; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3266 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3267 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3268 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3269 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3270 |
public void visitSelect(JCFieldAccess that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3271 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3272 |
that.sym = syms.unknownSymbol; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3273 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3274 |
super.visitSelect(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3275 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3276 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3277 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3278 |
public void visitClassDef(JCClassDecl that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3279 |
initTypeIfNeeded(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3280 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3281 |
that.sym = new ClassSymbol(0, that.name, that.type, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3282 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3283 |
super.visitClassDef(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3284 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3285 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3286 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3287 |
public void visitMethodDef(JCMethodDecl that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3288 |
initTypeIfNeeded(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3289 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3290 |
that.sym = new MethodSymbol(0, that.name, that.type, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3291 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3292 |
super.visitMethodDef(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3293 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3294 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3295 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3296 |
public void visitVarDef(JCVariableDecl that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3297 |
initTypeIfNeeded(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3298 |
if (that.sym == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3299 |
that.sym = new VarSymbol(0, that.name, that.type, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3300 |
that.sym.adr = 0; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3301 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3302 |
super.visitVarDef(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3303 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3304 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3305 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3306 |
public void visitNewClass(JCNewClass that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3307 |
if (that.constructor == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3308 |
that.constructor = new MethodSymbol(0, names.init, syms.unknownType, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3309 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3310 |
if (that.constructorType == null) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3311 |
that.constructorType = syms.unknownType; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3312 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3313 |
super.visitNewClass(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3314 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3315 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3316 |
@Override |
10187 | 3317 |
public void visitAssignop(JCAssignOp that) { |
3318 |
if (that.operator == null) |
|
3319 |
that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); |
|
3320 |
super.visitAssignop(that); |
|
3321 |
} |
|
3322 |
||
3323 |
@Override |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3324 |
public void visitBinary(JCBinary that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3325 |
if (that.operator == null) |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3326 |
that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3327 |
super.visitBinary(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3328 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3329 |
|
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3330 |
@Override |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3331 |
public void visitUnary(JCUnary that) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3332 |
if (that.operator == null) |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3333 |
that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3334 |
super.visitUnary(that); |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3335 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3336 |
} |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6592
diff
changeset
|
3337 |
// </editor-fold> |
10 | 3338 |
} |