1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
package com.sun.tools.javafx.comp; |
27 | |
|
28 | |
import java.util.HashMap; |
29 | |
import java.util.HashSet; |
30 | |
import java.util.Map; |
31 | |
import java.util.Set; |
32 | |
|
33 | |
import com.sun.tools.javac.code.*; |
34 | |
import static com.sun.tools.javac.code.Flags.*; |
35 | |
import static com.sun.tools.javac.code.Flags.ANNOTATION; |
36 | |
import static com.sun.tools.javac.code.Flags.SYNCHRONIZED; |
37 | |
import static com.sun.tools.javac.code.Kinds.*; |
38 | |
import com.sun.tools.javac.code.Lint.LintCategory; |
39 | |
import com.sun.tools.javac.code.Symbol.*; |
40 | |
import com.sun.tools.javac.code.Type.ClassType; |
41 | |
import com.sun.tools.javac.code.Type.ErrorType; |
42 | |
import com.sun.tools.javac.code.Type.ForAll; |
43 | |
import com.sun.tools.javac.code.Type.TypeVar; |
44 | |
import static com.sun.tools.javac.code.TypeTags.*; |
45 | |
import static com.sun.tools.javac.code.TypeTags.WILDCARD; |
46 | |
import com.sun.tools.javac.comp.Infer; |
47 | |
import com.sun.tools.javac.jvm.ByteCodes; |
48 | |
import com.sun.tools.javac.jvm.ClassReader; |
49 | |
import com.sun.tools.javac.jvm.Target; |
50 | |
import com.sun.tools.javac.tree.JCTree; |
51 | |
import com.sun.tools.javac.tree.JCTree.*; |
52 | |
import com.sun.tools.javac.util.*; |
53 | |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
54 | |
import com.sun.tools.javafx.code.JavafxClassSymbol; |
55 | |
import com.sun.tools.javafx.code.JavafxFlags; |
56 | |
import com.sun.tools.javafx.code.JavafxSymtab; |
57 | |
import com.sun.tools.javafx.code.JavafxTypes; |
58 | |
import static com.sun.tools.javafx.code.JavafxVarSymbol.*; |
59 | |
import com.sun.tools.javafx.comp.JavafxAttr.Sequenceness; |
60 | |
import com.sun.tools.javafx.tree.JFXClassDeclaration; |
61 | |
import com.sun.tools.javafx.tree.JavafxTreeInfo; |
62 | |
import com.sun.tools.javafx.tree.JavafxTreeScanner; |
63 | |
import com.sun.tools.javafx.util.MsgSym; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | 12 | public class JavafxCheck { |
73 | 12 | protected static final Context.Key<JavafxCheck> javafxCheckKey = |
74 | |
new Context.Key<JavafxCheck>(); |
75 | |
|
76 | |
private final JavafxDefs defs; |
77 | |
private final Name.Table names; |
78 | |
private final Log log; |
79 | |
private final JavafxSymtab syms; |
80 | |
private final Infer infer; |
81 | |
private final Target target; |
82 | |
private final Source source; |
83 | |
private final JavafxTypes types; |
84 | |
private final boolean skipAnnotations; |
85 | |
private final JavafxTreeInfo treeinfo; |
86 | |
private final JavafxResolve rs; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
private Lint lint; |
92 | |
|
93 | |
public static JavafxCheck instance(Context context) { |
94 | 2394 | JavafxCheck instance = context.get(javafxCheckKey); |
95 | 2394 | if (instance == null) |
96 | 399 | instance = new JavafxCheck(context); |
97 | 2394 | return instance; |
98 | |
} |
99 | |
|
100 | |
public static void preRegister(final Context context) { |
101 | 0 | context.put(javafxCheckKey, new Context.Factory<JavafxCheck>() { |
102 | |
public JavafxCheck make() { |
103 | 0 | return new JavafxCheck(context); |
104 | |
} |
105 | |
}); |
106 | 0 | } |
107 | |
|
108 | 399 | protected JavafxCheck(Context context) { |
109 | 399 | context.put(javafxCheckKey, this); |
110 | |
|
111 | 399 | defs = JavafxDefs.instance(context); |
112 | 399 | names = Name.Table.instance(context); |
113 | 399 | log = Log.instance(context); |
114 | 399 | syms = (JavafxSymtab) Symtab.instance(context); |
115 | 399 | infer = Infer.instance(context); |
116 | 399 | this.types = JavafxTypes.instance(context); |
117 | 399 | Options options = Options.instance(context); |
118 | 399 | target = Target.instance(context); |
119 | 399 | source = Source.instance(context); |
120 | 399 | lint = Lint.instance(context); |
121 | 399 | treeinfo = (JavafxTreeInfo)JavafxTreeInfo.instance(context); |
122 | |
|
123 | 399 | allowGenerics = source.allowGenerics(); |
124 | 399 | allowAnnotations = source.allowAnnotations(); |
125 | 399 | complexInference = options.get("-complexinference") != null; |
126 | 399 | skipAnnotations = options.get("skipAnnotations") != null; |
127 | |
|
128 | 399 | boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION); |
129 | 399 | boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED); |
130 | |
|
131 | 399 | deprecationHandler = new MandatoryWarningHandler(log,verboseDeprecated, MsgSym.MESSAGEPREFIX_DEPRECATED); |
132 | 399 | uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked, MsgSym.MESSAGEPREFIX_UNCHECKED); |
133 | 399 | rs = JavafxResolve.instance(context); |
134 | 399 | } |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
boolean allowGenerics; |
140 | |
|
141 | |
|
142 | |
|
143 | |
boolean allowAnnotations; |
144 | |
|
145 | |
|
146 | |
|
147 | |
boolean complexInference; |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | 399 | public Map<Name,ClassSymbol> compiled = new HashMap<Name, ClassSymbol>(); |
153 | |
|
154 | |
|
155 | |
|
156 | |
private MandatoryWarningHandler deprecationHandler; |
157 | |
|
158 | |
|
159 | |
|
160 | |
private MandatoryWarningHandler uncheckedHandler; |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
public |
168 | |
|
169 | |
Lint setLint(Lint newLint) { |
170 | 10390 | Lint prev = lint; |
171 | 10390 | lint = newLint; |
172 | 10390 | return prev; |
173 | |
} |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public |
181 | |
|
182 | |
void warnDeprecated(DiagnosticPosition pos, Symbol sym) { |
183 | 0 | if (!lint.isSuppressed(LintCategory.DEPRECATION)) |
184 | 0 | deprecationHandler.report(pos, MsgSym.MESSAGE_HAS_BEEN_DEPRECATED, sym, sym.location()); |
185 | 0 | } |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
public void warnUnchecked(DiagnosticPosition pos, String msg, Object... args) { |
192 | 67 | if (!lint.isSuppressed(LintCategory.UNCHECKED)) |
193 | 0 | uncheckedHandler.report(pos, msg, args); |
194 | 67 | } |
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
public void reportDeferredDiagnostics() { |
200 | 378 | deprecationHandler.reportDeferredDiagnostic(); |
201 | 378 | uncheckedHandler.reportDeferredDiagnostic(); |
202 | 378 | } |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
public Type completionError(DiagnosticPosition pos, CompletionFailure ex) { |
210 | 0 | log.error(pos, MsgSym.MESSAGE_CANNOT_ACCESS, ex.sym, ex.errmsg); |
211 | 0 | if (ex instanceof ClassReader.BadClassFile) throw new Abort(); |
212 | 0 | else return syms.errType; |
213 | |
} |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
public |
223 | |
|
224 | |
Type typeError(DiagnosticPosition pos, Object problem, Type found, Type req) { |
225 | 13 | String foundAsJavaFXType = types.toJavaFXString(found); |
226 | 13 | String requiredAsJavaFXType = types.toJavaFXString(req); |
227 | 13 | log.error(pos, MsgSym.MESSAGE_PROB_FOUND_REQ, problem, foundAsJavaFXType, requiredAsJavaFXType); |
228 | 13 | return syms.errType; |
229 | |
} |
230 | |
|
231 | |
Type typeError(DiagnosticPosition pos, String problem, Type found, Type req, Object explanation) { |
232 | 0 | String foundAsJavaFXType = types.toJavaFXString(found); |
233 | 0 | String requiredAsJavaFXType = types.toJavaFXString(req); |
234 | 0 | log.error(pos, MsgSym.MESSAGE_PROB_FOUND_REQ_1, problem, foundAsJavaFXType, requiredAsJavaFXType, explanation); |
235 | 0 | return syms.errType; |
236 | |
} |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
Type typeTagError(DiagnosticPosition pos, Object required, Object found) { |
245 | 3 | Object requiredAsJavaFXType = required; |
246 | 3 | if (required instanceof Type) { |
247 | 2 | requiredAsJavaFXType = types.toJavaFXString((Type) requiredAsJavaFXType); |
248 | |
} |
249 | 3 | Object foundAsJavaFXType = found; |
250 | 3 | if (foundAsJavaFXType instanceof Type) { |
251 | 3 | foundAsJavaFXType = types.toJavaFXString((Type) foundAsJavaFXType); |
252 | |
} |
253 | 3 | log.error(pos, MsgSym.MESSAGE_TYPE_FOUND_REQ, foundAsJavaFXType, requiredAsJavaFXType); |
254 | 3 | return syms.errType; |
255 | |
} |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
public |
264 | |
|
265 | |
void earlyRefError(DiagnosticPosition pos, Symbol sym) { |
266 | 0 | log.error(pos, MsgSym.MESSAGE_CANNOT_REF_BEFORE_CTOR_CALLED, sym); |
267 | 0 | } |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
protected |
273 | |
|
274 | |
void duplicateError(DiagnosticPosition pos, Symbol sym) { |
275 | 0 | if (sym.type == null || !sym.type.isErroneous()) { |
276 | 0 | log.error(pos, MsgSym.MESSAGE_ALREADY_DEFINED, sym, sym.location()); |
277 | |
} |
278 | 0 | } |
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
protected |
284 | |
|
285 | |
void varargsDuplicateError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) { |
286 | 0 | if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) { |
287 | 0 | log.error(pos, MsgSym.MESSAGE_ARRAY_AND_VARARGS, sym1, sym2, sym2.location()); |
288 | |
} |
289 | 0 | } |
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
public |
303 | |
|
304 | |
void checkTransparentVar(DiagnosticPosition pos, VarSymbol v, Scope s) { |
305 | 3283 | if (s.next != null) { |
306 | 2743 | for (Scope.Entry e = s.next.lookup(v.name); |
307 | 2743 | e.scope != null && e.sym.owner == v.owner; |
308 | 0 | e = e.next()) { |
309 | 0 | if (e.sym.kind == VAR && |
310 | |
(e.sym.owner.kind & (VAR | MTH)) != 0 && |
311 | |
v.name != names.error) { |
312 | 0 | duplicateError(pos, e.sym); |
313 | 0 | return; |
314 | |
} |
315 | |
} |
316 | |
} |
317 | 3283 | } |
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
public |
327 | |
|
328 | |
void checkTransparentClass(DiagnosticPosition pos, ClassSymbol c, Scope s) { |
329 | 26 | if (s.next != null) { |
330 | 26 | for (Scope.Entry e = s.next.lookup(c.name); |
331 | 26 | e.scope != null && e.sym.owner == c.owner; |
332 | 0 | e = e.next()) { |
333 | 0 | if (e.sym.kind == TYP && |
334 | |
(e.sym.owner.kind & (VAR | MTH)) != 0 && |
335 | |
c.name != names.error) { |
336 | 0 | duplicateError(pos, e.sym); |
337 | 0 | return; |
338 | |
} |
339 | |
} |
340 | |
} |
341 | 26 | } |
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
public |
352 | |
|
353 | |
boolean checkUniqueClassName(DiagnosticPosition pos, Name name, Scope s) { |
354 | 317 | for (Scope.Entry e = s.lookup(name); e.scope == s; e = e.next()) { |
355 | 0 | if (e.sym.kind == TYP && e.sym.name != names.error) { |
356 | 0 | duplicateError(pos, e.sym); |
357 | 0 | return false; |
358 | |
} |
359 | |
} |
360 | 1333 | for (Symbol sym = s.owner; sym != null; sym = sym.owner) { |
361 | 1016 | if (sym.kind == TYP && sym.name == name && sym.name != names.error) { |
362 | 0 | duplicateError(pos, sym); |
363 | 0 | return true; |
364 | |
} |
365 | |
} |
366 | 317 | return true; |
367 | |
} |
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
public |
381 | |
|
382 | |
Name localClassName(ClassSymbol c) { |
383 | 26 | for (int i=1; ; i++) { |
384 | 26 | Name flatname = names. |
385 | |
fromString("" + c.owner.enclClass().flatname + |
386 | |
target.syntheticNameChar() + i + |
387 | |
c.name); |
388 | 26 | if (compiled.get(flatname) == null) return flatname; |
389 | |
} |
390 | |
} |
391 | |
|
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
private Type deLocationize(Type external) { |
397 | 77640 | if (external.tag == CLASS) { |
398 | 25094 | Name flatname = ((ClassSymbol) external.tsym).flatname; |
399 | 25094 | Type deloc = defs.delocationize(flatname); |
400 | 25094 | if (deloc != null) { |
401 | 0 | throw new AssertionError("At this point we should not have Location(s). This is most likely JavafxReader problem. It should convert all the Location types to the \"real\" types."); |
402 | |
} |
403 | |
} |
404 | 77640 | return external; |
405 | |
} |
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
|
413 | |
Type checkType(DiagnosticPosition pos, Type foundRaw, Type reqRaw, Sequenceness pSequenceness) { |
414 | 38820 | Type req = deLocationize(reqRaw); |
415 | 38820 | Type found = deLocationize(foundRaw); |
416 | 38820 | Type realFound = found; |
417 | 38820 | if (req.tag == ERROR) |
418 | 0 | return req; |
419 | 38820 | if (found == syms.unreachableType) |
420 | 216 | return found; |
421 | 38604 | if (found.tag == FORALL) |
422 | 0 | return instantiatePoly(pos, (ForAll)found, req, convertWarner(pos, found, req)); |
423 | 38604 | if (req.tag == NONE || req == syms.javafx_UnspecifiedType) |
424 | 30811 | return found; |
425 | 7793 | if (types.isSequence(req)) { |
426 | 561 | req = types.elementType(req); |
427 | 561 | pSequenceness = Sequenceness.REQUIRED; |
428 | |
} |
429 | 7793 | if (types.isSequence(found) || types.isArray(found)) { |
430 | 430 | if (pSequenceness != Sequenceness.DISALLOWED) { |
431 | 429 | found = types.isSequence(found) ? types.elementType(found) : types.elemtype(found); |
432 | |
} else { |
433 | 1 | return typeError(pos, JCDiagnostic.fragment(MsgSym.MESSAGE_INCOMPATIBLE_TYPES), found, req); |
434 | |
} |
435 | |
} |
436 | 7792 | if (types.isAssignable(found, req, convertWarner(pos, found, req))) |
437 | 7780 | return realFound; |
438 | |
|
439 | |
|
440 | 12 | ListBuffer<Type> supertypes = ListBuffer.<Type>lb(); |
441 | 12 | Set<Type> superSet = new HashSet<Type>(); |
442 | 12 | supertypes.append(found); |
443 | 12 | superSet.add(found); |
444 | |
|
445 | 12 | types.getSupertypes(found.tsym, supertypes, superSet); |
446 | |
|
447 | 12 | for (Type baseType : supertypes) { |
448 | 18 | if (types.isAssignable(baseType, req, convertWarner(pos, found, req))) |
449 | 0 | return realFound; |
450 | |
} |
451 | |
|
452 | 12 | if (found.tag <= DOUBLE && req.tag <= DOUBLE) |
453 | 0 | return typeError(pos, JCDiagnostic.fragment(MsgSym.MESSAGE_POSSIBLE_LOSS_OF_PRECISION), found, req); |
454 | 12 | if (found.isSuperBound()) { |
455 | 0 | log.error(pos, MsgSym.MESSAGE_ASSIGNMENT_FROM_SUPER_BOUND, found); |
456 | 0 | return syms.errType; |
457 | |
} |
458 | 12 | if (req.isExtendsBound()) { |
459 | 0 | log.error(pos, MsgSym.MESSAGE_ASSIGNMENT_TO_EXTENDS_BOUND, req); |
460 | 0 | return syms.errType; |
461 | |
} |
462 | 12 | return typeError(pos, JCDiagnostic.fragment(MsgSym.MESSAGE_INCOMPATIBLE_TYPES), found, req); |
463 | |
} |
464 | |
|
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | |
Type instantiatePoly(DiagnosticPosition pos, ForAll t, Type pt, Warner warn) { |
470 | 0 | if (pt == Infer.anyPoly && complexInference) { |
471 | 0 | return t; |
472 | 0 | } else if (pt == Infer.anyPoly || pt.tag == NONE) { |
473 | 0 | Type newpt = t.qtype.tag <= VOID ? t.qtype : syms.objectType; |
474 | 0 | return instantiatePoly(pos, t, newpt, warn); |
475 | 0 | } else if (pt.tag == ERROR) { |
476 | 0 | return pt; |
477 | |
} else { |
478 | |
try { |
479 | 0 | return infer.instantiateExpr(t, pt, warn); |
480 | 0 | } catch (Infer.NoInstanceException ex) { |
481 | 0 | if (ex.isAmbiguous) { |
482 | 0 | JCDiagnostic d = ex.getDiagnostic(); |
483 | 0 | log.error(pos, |
484 | |
d!=null ? MsgSym.MESSAGE_UNDETERMINDED_TYPE_1 : MsgSym.MESSAGE_UNDETERMINDED_TYPE, |
485 | |
t, d); |
486 | 0 | return syms.errType; |
487 | |
} else { |
488 | 0 | JCDiagnostic d = ex.getDiagnostic(); |
489 | 0 | return typeError(pos, |
490 | |
JCDiagnostic.fragment(d!=null ? MsgSym.MESSAGE_INCOMPATIBLE_TYPES_1 : MsgSym.MESSAGE_INCOMPATIBLE_TYPES, d), |
491 | |
t, pt); |
492 | |
} |
493 | |
} |
494 | |
} |
495 | |
} |
496 | |
|
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
public |
505 | |
|
506 | |
Type checkCastable(DiagnosticPosition pos, Type found, Type req) { |
507 | 196 | if (found.tag == FORALL && found instanceof ForAll) { |
508 | 0 | instantiatePoly(pos, (ForAll) found, req, castWarner(pos, found, req)); |
509 | 0 | return req; |
510 | 196 | } else if (types.isCastable(found, req, castWarner(pos, found, req))) { |
511 | 194 | return req; |
512 | |
} |
513 | |
|
514 | 2 | else if (found.tsym != null && found.tsym instanceof JavafxClassSymbol) { |
515 | 2 | ListBuffer<Type> supertypes = ListBuffer.<Type>lb(); |
516 | 2 | Set<Type> superSet = new HashSet<Type>(); |
517 | 2 | supertypes.append(found); |
518 | 2 | superSet.add(found); |
519 | |
|
520 | 2 | types.getSupertypes(found.tsym, supertypes, superSet); |
521 | |
|
522 | 2 | for (Type baseType : supertypes) { |
523 | 4 | if (types.isCastable(baseType, req, castWarner(pos, found, req))) |
524 | 2 | return req; |
525 | |
} |
526 | |
} |
527 | |
|
528 | 0 | if (req.tsym != null && req.tsym instanceof JavafxClassSymbol) { |
529 | 0 | ListBuffer<Type> supertypes = ListBuffer.<Type>lb(); |
530 | 0 | Set<Type> superSet = new HashSet<Type>(); |
531 | 0 | supertypes.append(req); |
532 | 0 | superSet.add(req); |
533 | |
|
534 | 0 | types.getSupertypes(req.tsym, supertypes, superSet); |
535 | 0 | for (Type baseType : supertypes) { |
536 | 0 | if (types.isCastable(baseType, found, castWarner(pos, found, req))) |
537 | 0 | return req; |
538 | |
} |
539 | |
} |
540 | |
|
541 | 0 | return typeError(pos, |
542 | |
JCDiagnostic.fragment(MsgSym.MESSAGE_INCONVERTIBLE_TYPES), |
543 | |
found, req); |
544 | |
} |
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | |
boolean isTypeVar(Type t) { |
550 | 0 | return t.tag == TYPEVAR || t.tag == ARRAY && isTypeVar(types.elemtype(t)); |
551 | |
} |
552 | |
|
553 | |
|
554 | |
|
555 | |
|
556 | |
|
557 | |
|
558 | |
|
559 | |
|
560 | |
|
561 | |
private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) { |
562 | 0 | if (a.isUnbound()) { |
563 | 0 | return; |
564 | 0 | } else if (a.tag != WILDCARD) { |
565 | 0 | a = types.upperBound(a); |
566 | 0 | for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) { |
567 | 0 | if (!types.isSubtype(a, l.head)) { |
568 | 0 | log.error(pos, MsgSym.MESSAGE_NOT_WITHIN_BOUNDS, a); |
569 | 0 | return; |
570 | |
} |
571 | |
} |
572 | 0 | } else if (a.isExtendsBound()) { |
573 | 0 | if (!types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings)) |
574 | 0 | log.error(pos, MsgSym.MESSAGE_NOT_WITHIN_BOUNDS, a); |
575 | 0 | } else if (a.isSuperBound()) { |
576 | 0 | if (types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound())) |
577 | 0 | log.error(pos, MsgSym.MESSAGE_NOT_WITHIN_BOUNDS, a); |
578 | |
} |
579 | 0 | } |
580 | |
|
581 | |
|
582 | |
public |
583 | |
|
584 | |
|
585 | |
|
586 | |
|
587 | |
|
588 | |
Type checkNonVoid(DiagnosticPosition pos, Type t) { |
589 | 9019 | if (t.tag == VOID) { |
590 | 1 | log.error(pos, MsgSym.MESSAGE_VOID_NOT_ALLOWED_HERE); |
591 | 1 | return syms.errType; |
592 | |
} else { |
593 | 9018 | return t; |
594 | |
} |
595 | |
} |
596 | |
|
597 | |
|
598 | |
|
599 | |
|
600 | |
|
601 | |
|
602 | |
public |
603 | |
|
604 | |
Type checkClassType(DiagnosticPosition pos, Type t) { |
605 | 667 | if (t.tag != CLASS && t.tag != ERROR) |
606 | 0 | return typeTagError(pos, |
607 | |
JCDiagnostic.fragment(MsgSym.MESSAGE_TYPE_REQ_CLASS), |
608 | |
(t.tag == TYPEVAR) |
609 | |
? JCDiagnostic.fragment(MsgSym.MESSAGE_TYPE_PARAMETER, t) |
610 | |
: t); |
611 | |
else |
612 | 667 | return t; |
613 | |
} |
614 | |
|
615 | |
|
616 | |
|
617 | |
|
618 | |
public Type checkSequenceElementType (DiagnosticPosition pos, Type t) { |
619 | 479 | if (types.isSequence(t)) |
620 | 477 | return types.elementType(t); |
621 | 2 | if (t.tag != ERROR) { |
622 | 2 | return typeTagError(pos, types.sequenceType(syms.unknownType), t); |
623 | |
} |
624 | 0 | return syms.errType; |
625 | |
} |
626 | |
|
627 | |
|
628 | |
|
629 | |
|
630 | |
|
631 | |
|
632 | |
|
633 | |
public |
634 | |
|
635 | |
Type checkClassType(DiagnosticPosition pos, Type t, boolean noBounds) { |
636 | 667 | t = checkClassType(pos, t); |
637 | 667 | if (noBounds && t.isParameterized()) { |
638 | 0 | List<Type> args = t.getTypeArguments(); |
639 | 0 | while (args.nonEmpty()) { |
640 | 0 | if (args.head.tag == WILDCARD) |
641 | 0 | return typeTagError(pos, |
642 | |
Log.getLocalizedString(MsgSym.MESSAGE_TYPE_REQ_EXACT), |
643 | |
args.head); |
644 | 0 | args = args.tail; |
645 | |
} |
646 | |
} |
647 | 667 | return t; |
648 | |
} |
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | |
|
654 | |
|
655 | |
public |
656 | |
|
657 | |
Type checkReifiableReferenceType(DiagnosticPosition pos, Type t) { |
658 | 37 | if (t.tag != CLASS && t.tag != ARRAY && t.tag != ERROR) { |
659 | 1 | return typeTagError(pos, |
660 | |
JCDiagnostic.fragment(MsgSym.MESSAGE_TYPE_REQ_CLASS_ARRAY), |
661 | |
t); |
662 | 36 | } else if (!types.isReifiable(t)) { |
663 | 1 | log.error(pos, MsgSym.MESSAGE_ILLEGAL_GENERIC_TYPE_FOR_INSTOF); |
664 | 1 | return syms.errType; |
665 | |
} else { |
666 | 35 | return t; |
667 | |
} |
668 | |
} |
669 | |
|
670 | |
|
671 | |
public |
672 | |
|
673 | |
|
674 | |
|
675 | |
|
676 | |
|
677 | |
|
678 | |
Type checkRefType(DiagnosticPosition pos, Type t) { |
679 | 0 | switch (t.tag) { |
680 | |
case CLASS: |
681 | |
case ARRAY: |
682 | |
case TYPEVAR: |
683 | |
case WILDCARD: |
684 | |
case ERROR: |
685 | 0 | return t; |
686 | |
default: |
687 | 0 | return typeTagError(pos, |
688 | |
JCDiagnostic.fragment(MsgSym.MESSAGE_TYPE_REQ_REF), |
689 | |
t); |
690 | |
} |
691 | |
} |
692 | |
|
693 | |
|
694 | |
|
695 | |
|
696 | |
|
697 | |
|
698 | |
public |
699 | |
|
700 | |
Type checkNullOrRefType(DiagnosticPosition pos, Type t) { |
701 | 37 | switch (t.tag) { |
702 | |
case CLASS: |
703 | |
case ARRAY: |
704 | |
case TYPEVAR: |
705 | |
case WILDCARD: |
706 | |
case BOT: |
707 | |
case ERROR: |
708 | 37 | return t; |
709 | |
default: |
710 | 0 | return typeTagError(pos, |
711 | |
JCDiagnostic.fragment(MsgSym.MESSAGE_TYPE_REQ_REF), |
712 | |
t); |
713 | |
} |
714 | |
} |
715 | |
|
716 | |
|
717 | |
|
718 | |
|
719 | |
|
720 | |
|
721 | |
|
722 | |
|
723 | |
boolean checkDisjoint(DiagnosticPosition pos, long flags, long set1, long set2) { |
724 | 29190 | if ((flags & set1) != 0 && (flags & set2) != 0) { |
725 | 0 | log.error(pos, |
726 | |
MsgSym.MESSAGE_ILLEGAL_COMBINATION_OF_MODIFIERS, |
727 | |
JavafxTreeInfo.flagNames(JavafxTreeInfo.firstFlag(flags & set1)), |
728 | |
JavafxTreeInfo.flagNames(JavafxTreeInfo.firstFlag(flags & set2))); |
729 | 0 | return false; |
730 | |
} else |
731 | 29190 | return true; |
732 | |
} |
733 | |
|
734 | |
|
735 | |
|
736 | |
|
737 | |
|
738 | |
|
739 | |
|
740 | |
|
741 | |
|
742 | |
|
743 | |
|
744 | |
public |
745 | |
|
746 | |
long checkFlags(DiagnosticPosition pos, long flags, Symbol sym, JCTree tree) { |
747 | |
long mask; |
748 | 5099 | long implicit = 0; |
749 | 5099 | switch (sym.kind) { |
750 | |
case VAR: |
751 | 3283 | if (sym.owner.kind != TYP) |
752 | 2743 | mask = LocalVarFlags; |
753 | 540 | else if ((sym.owner.flags_field & INTERFACE) != 0) |
754 | 0 | mask = implicit = InterfaceVarFlags; |
755 | |
else |
756 | 540 | mask = VarFlags; |
757 | 540 | break; |
758 | |
case MTH: |
759 | 1114 | if (sym.name == names.init) { |
760 | 0 | if ((sym.owner.flags_field & ENUM) != 0) { |
761 | |
|
762 | |
|
763 | |
|
764 | 0 | implicit = PRIVATE; |
765 | 0 | mask = PRIVATE; |
766 | |
} else |
767 | 0 | mask = ConstructorFlags; |
768 | 1114 | } else if ((sym.owner.flags_field & INTERFACE) != 0) |
769 | 0 | mask = implicit = InterfaceMethodFlags; |
770 | |
else { |
771 | 1114 | mask = MethodFlags; |
772 | |
} |
773 | |
|
774 | 1114 | if (((flags|implicit) & Flags.ABSTRACT) == 0) |
775 | 1104 | implicit |= sym.owner.flags_field & STRICTFP; |
776 | |
break; |
777 | |
case TYP: |
778 | 702 | if (sym.isLocal()) { |
779 | 26 | mask = LocalClassFlags; |
780 | 26 | if (sym.name.len == 0 || true ) { |
781 | |
|
782 | |
|
783 | 26 | mask |= STATIC; |
784 | |
|
785 | 26 | implicit |= FINAL; |
786 | |
} |
787 | 26 | if ((sym.owner.flags_field & STATIC) == 0 && |
788 | |
(flags & ENUM) != 0) |
789 | 0 | log.error(pos, MsgSym.MESSAGE_ENUMS_MUST_BE_STATIC); |
790 | 676 | } else if (sym.owner.kind == TYP) { |
791 | 291 | mask = MemberClassFlags; |
792 | 291 | if (sym.owner.owner.kind == PCK || |
793 | |
(sym.owner.flags_field & STATIC) != 0) |
794 | 291 | mask |= STATIC; |
795 | 0 | else if ((flags & ENUM) != 0) |
796 | 0 | log.error(pos, MsgSym.MESSAGE_ENUMS_MUST_BE_STATIC); |
797 | |
|
798 | 291 | if ((flags & (INTERFACE | ENUM)) != 0 ) implicit = STATIC; |
799 | |
} else { |
800 | 385 | mask = ClassFlags; |
801 | |
} |
802 | |
|
803 | 702 | if ((flags & INTERFACE) != 0) implicit |= ABSTRACT; |
804 | |
|
805 | 702 | if ((flags & ENUM) != 0) { |
806 | |
|
807 | 0 | mask &= ~(ABSTRACT | FINAL); |
808 | 0 | implicit |= implicitEnumFinalFlag(tree); |
809 | |
} |
810 | |
|
811 | 702 | implicit |= sym.owner.flags_field & STRICTFP; |
812 | 702 | break; |
813 | |
default: |
814 | 0 | throw new AssertionError(); |
815 | |
} |
816 | 5099 | long illegal = flags & StandardFlags & ~mask; |
817 | 5099 | if (illegal != 0) { |
818 | 0 | if ((illegal & INTERFACE) != 0) { |
819 | 0 | log.error(pos, MsgSym.MESSAGE_INTF_NOT_ALLOWED_HERE); |
820 | 0 | mask |= INTERFACE; |
821 | |
} |
822 | |
else { |
823 | 0 | log.error(pos, |
824 | |
MsgSym.MESSAGE_MOD_NOT_ALLOWED_HERE, JavafxTreeInfo.flagNames(illegal)); |
825 | |
} |
826 | |
} |
827 | 5099 | else if ((sym.kind == TYP || |
828 | |
|
829 | |
|
830 | |
checkDisjoint(pos, flags, |
831 | |
ABSTRACT, |
832 | |
PRIVATE | STATIC)) |
833 | |
&& |
834 | |
checkDisjoint(pos, flags, |
835 | |
ABSTRACT | INTERFACE, |
836 | |
FINAL | NATIVE | SYNCHRONIZED) |
837 | |
&& |
838 | |
checkDisjoint(pos, flags, |
839 | |
PUBLIC, |
840 | |
PRIVATE | PROTECTED) |
841 | |
&& |
842 | |
checkDisjoint(pos, flags, |
843 | |
PRIVATE, |
844 | |
PUBLIC | PROTECTED) |
845 | |
&& |
846 | |
checkDisjoint(pos, flags, |
847 | |
FINAL, |
848 | |
VOLATILE) |
849 | |
&& |
850 | |
(sym.kind == TYP || |
851 | |
checkDisjoint(pos, flags, |
852 | |
ABSTRACT | NATIVE, |
853 | |
STRICTFP))) { |
854 | |
|
855 | |
} |
856 | 5099 | return flags & (mask | ~StandardFlags) | implicit; |
857 | |
} |
858 | |
|
859 | |
|
860 | |
|
861 | |
|
862 | |
|
863 | |
|
864 | |
|
865 | |
|
866 | |
|
867 | |
private long implicitEnumFinalFlag(JCTree tree) { |
868 | 0 | if (tree.getTag() != JCTree.CLASSDEF) return 0; |
869 | |
class SpecialTreeVisitor extends JCTree.Visitor { |
870 | |
boolean specialized; |
871 | 0 | SpecialTreeVisitor() { |
872 | 0 | this.specialized = false; |
873 | 0 | } |
874 | |
|
875 | |
@Override |
876 | 0 | public void visitTree(JCTree tree) { } |
877 | |
|
878 | |
@Override |
879 | |
public void visitVarDef(JCVariableDecl tree) { |
880 | 0 | if ((tree.mods.flags & ENUM) != 0) { |
881 | 0 | if (tree.init instanceof JCNewClass && |
882 | |
((JCNewClass) tree.init).def != null) { |
883 | 0 | specialized = true; |
884 | |
} |
885 | |
} |
886 | 0 | } |
887 | |
} |
888 | |
|
889 | 0 | SpecialTreeVisitor sts = new SpecialTreeVisitor(); |
890 | 0 | JFXClassDeclaration cdef = (JFXClassDeclaration) tree; |
891 | 0 | for (JCTree localDefs: cdef.getMembers()) { |
892 | 0 | localDefs.accept(sts); |
893 | 0 | if (sts.specialized) return 0; |
894 | |
} |
895 | 0 | return FINAL; |
896 | |
} |
897 | |
|
898 | |
|
899 | |
|
900 | |
|
901 | |
|
902 | |
|
903 | |
|
904 | |
|
905 | |
|
906 | |
|
907 | |
|
908 | |
|
909 | |
|
910 | |
|
911 | |
|
912 | |
|
913 | 399 | private Validator validator = new Validator(); |
914 | |
|
915 | |
|
916 | |
|
917 | |
|
918 | |
|
919 | |
public |
920 | |
|
921 | |
void validate(JCTree tree) { |
922 | |
try { |
923 | 803 | if (tree != null) tree.accept(validator); |
924 | 0 | } catch (CompletionFailure ex) { |
925 | 0 | completionError(tree.pos(), ex); |
926 | 803 | } |
927 | 803 | } |
928 | |
|
929 | |
|
930 | |
|
931 | |
|
932 | |
public |
933 | |
|
934 | |
void validate(List<? extends JCTree> trees) { |
935 | 4121 | for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) |
936 | 124 | validate(l.head); |
937 | 3997 | } |
938 | |
|
939 | |
|
940 | |
|
941 | |
|
942 | |
public |
943 | |
|
944 | |
void validateTypeParams(List<JCTypeParameter> trees) { |
945 | 670 | for (List<JCTypeParameter> l = trees; l.nonEmpty(); l = l.tail) |
946 | 0 | validate(l.head); |
947 | 670 | } |
948 | |
|
949 | |
|
950 | |
|
951 | 399 | class Validator extends JavafxTreeScanner { |
952 | |
|
953 | |
@Override |
954 | |
public void visitTypeArray(JCArrayTypeTree tree) { |
955 | 0 | validate(tree.elemtype); |
956 | 0 | } |
957 | |
|
958 | |
@Override |
959 | |
public void visitTypeApply(JCTypeApply tree) { |
960 | 0 | if (tree.type.tag == CLASS) { |
961 | 0 | List<Type> formals = tree.type.tsym.type.getTypeArguments(); |
962 | 0 | List<Type> actuals = tree.type.getTypeArguments(); |
963 | 0 | List<JCExpression> args = tree.arguments; |
964 | 0 | List<Type> forms = formals; |
965 | 0 | ListBuffer<TypeVar> tvars_buf = new ListBuffer<TypeVar>(); |
966 | |
|
967 | |
|
968 | |
|
969 | 0 | while (args.nonEmpty() && forms.nonEmpty()) { |
970 | 0 | validate(args.head); |
971 | |
|
972 | |
|
973 | |
|
974 | |
|
975 | |
|
976 | 0 | tvars_buf.append(types.substBound(((TypeVar)forms.head), |
977 | |
formals, |
978 | |
Type.removeBounds(actuals))); |
979 | |
|
980 | 0 | args = args.tail; |
981 | 0 | forms = forms.tail; |
982 | |
} |
983 | |
|
984 | 0 | args = tree.arguments; |
985 | 0 | List<TypeVar> tvars = tvars_buf.toList(); |
986 | 0 | while (args.nonEmpty() && tvars.nonEmpty()) { |
987 | |
|
988 | 0 | args.head.type.withTypeVar(tvars.head); |
989 | 0 | args = args.tail; |
990 | 0 | tvars = tvars.tail; |
991 | |
} |
992 | |
|
993 | 0 | args = tree.arguments; |
994 | 0 | tvars = tvars_buf.toList(); |
995 | 0 | while (args.nonEmpty() && tvars.nonEmpty()) { |
996 | 0 | checkExtends(args.head.pos(), |
997 | |
args.head.type, |
998 | |
tvars.head); |
999 | 0 | args = args.tail; |
1000 | 0 | tvars = tvars.tail; |
1001 | |
} |
1002 | |
|
1003 | |
|
1004 | |
|
1005 | 0 | if (tree.type.getEnclosingType().isRaw()) |
1006 | 0 | log.error(tree.pos(), MsgSym.MESSAGE_IMPROPERLY_FORMED_TYPE_INNER_RAW_PARAM); |
1007 | 0 | if (tree.clazz.getTag() == JCTree.SELECT) |
1008 | 0 | visitSelectInternal((JCFieldAccess)tree.clazz); |
1009 | |
} |
1010 | 0 | } |
1011 | |
|
1012 | |
@Override |
1013 | |
public void visitTypeParameter(JCTypeParameter tree) { |
1014 | 0 | validate(tree.bounds); |
1015 | 0 | checkClassBounds(tree.pos(), tree.type); |
1016 | 0 | } |
1017 | |
|
1018 | |
@Override |
1019 | |
public void visitWildcard(JCWildcard tree) { |
1020 | 0 | if (tree.inner != null) |
1021 | 0 | validate(tree.inner); |
1022 | 0 | } |
1023 | |
|
1024 | |
@Override |
1025 | |
public void visitSelect(JCFieldAccess tree) { |
1026 | 74 | if (tree.type.tag == CLASS) { |
1027 | 38 | visitSelectInternal(tree); |
1028 | |
|
1029 | |
|
1030 | |
|
1031 | 38 | if (tree.selected.type.isParameterized() && tree.type.tsym.type.getTypeArguments().nonEmpty()) |
1032 | 0 | log.error(tree.pos(), MsgSym.MESSAGE_IMPROPERLY_FORMED_TYPE_PARAM_MISSING); |
1033 | |
} |
1034 | 74 | } |
1035 | |
public void visitSelectInternal(JCFieldAccess tree) { |
1036 | 38 | if (tree.type.getEnclosingType().tag != CLASS && |
1037 | |
tree.selected.type.isParameterized()) { |
1038 | |
|
1039 | |
|
1040 | |
|
1041 | 0 | log.error(tree.pos(), MsgSym.MESSAGE_CANNOT_SELECT_STATIC_CLASS_FROM_PARAM_TYPE); |
1042 | |
} else { |
1043 | |
|
1044 | 38 | validate(tree.selected); |
1045 | |
} |
1046 | 38 | } |
1047 | |
|
1048 | |
|
1049 | |
|
1050 | |
@Override |
1051 | |
public void visitTree(JCTree tree) { |
1052 | 0 | } |
1053 | |
} |
1054 | |
|
1055 | |
|
1056 | |
|
1057 | |
|
1058 | |
|
1059 | |
|
1060 | |
|
1061 | |
|
1062 | |
|
1063 | |
|
1064 | |
|
1065 | |
boolean subset(Type t, List<Type> ts) { |
1066 | 0 | for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
1067 | 0 | if (types.isSubtype(t, l.head)) return true; |
1068 | 0 | return false; |
1069 | |
} |
1070 | |
|
1071 | |
|
1072 | |
|
1073 | |
|
1074 | |
boolean intersects(Type t, List<Type> ts) { |
1075 | 0 | for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
1076 | 0 | if (types.isSubtype(t, l.head) || types.isSubtype(l.head, t)) return true; |
1077 | 0 | return false; |
1078 | |
} |
1079 | |
|
1080 | |
|
1081 | |
|
1082 | |
|
1083 | |
List<Type> incl(Type t, List<Type> ts) { |
1084 | 0 | return subset(t, ts) ? ts : excl(t, ts).prepend(t); |
1085 | |
} |
1086 | |
|
1087 | |
|
1088 | |
|
1089 | |
List<Type> excl(Type t, List<Type> ts) { |
1090 | 0 | if (ts.isEmpty()) { |
1091 | 0 | return ts; |
1092 | |
} else { |
1093 | 0 | List<Type> ts1 = excl(t, ts.tail); |
1094 | 0 | if (types.isSubtype(ts.head, t)) return ts1; |
1095 | 0 | else if (ts1 == ts.tail) return ts; |
1096 | 0 | else return ts1.prepend(ts.head); |
1097 | |
} |
1098 | |
} |
1099 | |
|
1100 | |
|
1101 | |
|
1102 | |
List<Type> union(List<Type> ts1, List<Type> ts2) { |
1103 | 0 | List<Type> ts = ts1; |
1104 | 0 | for (List<Type> l = ts2; l.nonEmpty(); l = l.tail) |
1105 | 0 | ts = incl(l.head, ts); |
1106 | 0 | return ts; |
1107 | |
} |
1108 | |
|
1109 | |
|
1110 | |
|
1111 | |
List<Type> diff(List<Type> ts1, List<Type> ts2) { |
1112 | 0 | List<Type> ts = ts1; |
1113 | 0 | for (List<Type> l = ts2; l.nonEmpty(); l = l.tail) |
1114 | 0 | ts = excl(l.head, ts); |
1115 | 0 | return ts; |
1116 | |
} |
1117 | |
|
1118 | |
|
1119 | |
|
1120 | |
public List<Type> intersect(List<Type> ts1, List<Type> ts2) { |
1121 | 0 | List<Type> ts = List.nil(); |
1122 | 0 | for (List<Type> l = ts1; l.nonEmpty(); l = l.tail) |
1123 | 0 | if (subset(l.head, ts2)) ts = incl(l.head, ts); |
1124 | 0 | for (List<Type> l = ts2; l.nonEmpty(); l = l.tail) |
1125 | 0 | if (subset(l.head, ts1)) ts = incl(l.head, ts); |
1126 | 0 | return ts; |
1127 | |
} |
1128 | |
|
1129 | |
|
1130 | |
|
1131 | |
boolean isUnchecked(ClassSymbol exc) { |
1132 | 0 | return |
1133 | |
exc.kind == ERR || |
1134 | |
exc.isSubClass(syms.errorType.tsym, types) || |
1135 | |
exc.isSubClass(syms.runtimeExceptionType.tsym, types); |
1136 | |
} |
1137 | |
|
1138 | |
|
1139 | |
|
1140 | |
boolean isUnchecked(Type exc) { |
1141 | 0 | return |
1142 | |
(exc.tag == TYPEVAR) ? isUnchecked(types.supertype(exc)) : |
1143 | |
(exc.tag == CLASS) ? isUnchecked((ClassSymbol)exc.tsym) : |
1144 | |
exc.tag == BOT; |
1145 | |
} |
1146 | |
|
1147 | |
|
1148 | |
|
1149 | |
boolean isUnchecked(DiagnosticPosition pos, Type exc) { |
1150 | |
try { |
1151 | 0 | return isUnchecked(exc); |
1152 | 0 | } catch (CompletionFailure ex) { |
1153 | 0 | completionError(pos, ex); |
1154 | 0 | return true; |
1155 | |
} |
1156 | |
} |
1157 | |
|
1158 | |
|
1159 | |
|
1160 | |
boolean isHandled(Type exc, List<Type> handled) { |
1161 | 0 | return isUnchecked(exc) || subset(exc, handled); |
1162 | |
} |
1163 | |
|
1164 | |
|
1165 | |
|
1166 | |
|
1167 | |
|
1168 | |
List<Type> unHandled(List<Type> thrown, List<Type> handled) { |
1169 | 180 | List<Type> unhandled = List.nil(); |
1170 | 180 | for (List<Type> l = thrown; l.nonEmpty(); l = l.tail) |
1171 | 0 | if (!isHandled(l.head, handled)) unhandled = unhandled.prepend(l.head); |
1172 | 180 | return unhandled; |
1173 | |
} |
1174 | |
|
1175 | |
|
1176 | |
|
1177 | |
|
1178 | |
|
1179 | |
|
1180 | |
|
1181 | |
|
1182 | |
static int protection(long flags) { |
1183 | 0 | switch ((short)(flags & AccessFlags)) { |
1184 | 0 | case PRIVATE: return 3; |
1185 | 0 | case PROTECTED: return 1; |
1186 | |
default: |
1187 | 0 | case PUBLIC: return 0; |
1188 | 0 | case 0: return 2; |
1189 | |
} |
1190 | |
} |
1191 | |
|
1192 | |
|
1193 | |
|
1194 | |
|
1195 | |
private static String protectionString(long flags) { |
1196 | 0 | long flags1 = flags & AccessFlags; |
1197 | 0 | return (flags1 == 0) ? "package" : JavafxTreeInfo.flagNames(flags1); |
1198 | |
} |
1199 | |
|
1200 | |
|
1201 | |
|
1202 | |
|
1203 | |
|
1204 | |
|
1205 | |
static Object cannotOverride(MethodSymbol m, MethodSymbol other) { |
1206 | |
String key; |
1207 | 0 | if ((other.owner.flags() & INTERFACE) == 0) |
1208 | 0 | key = MsgSym.MESSAGE_CANNOT_OVERRIDE; |
1209 | 0 | else if ((m.owner.flags() & INTERFACE) == 0) |
1210 | 0 | key = MsgSym.MESSAGE_CANNOT_IMPLEMENT; |
1211 | |
else |
1212 | 0 | key = MsgSym.MESSAGE_CLASHES_WITH; |
1213 | 0 | return JCDiagnostic.fragment(key, m, m.location(), other, other.location()); |
1214 | |
} |
1215 | |
|
1216 | |
|
1217 | |
|
1218 | |
|
1219 | |
|
1220 | |
|
1221 | |
static Object uncheckedOverrides(MethodSymbol m, MethodSymbol other) { |
1222 | |
String key; |
1223 | 0 | if ((other.owner.flags() & INTERFACE) == 0) |
1224 | 0 | key = MsgSym.MESSAGE_UNCHECKED_OVERRIDE; |
1225 | 0 | else if ((m.owner.flags() & INTERFACE) == 0) |
1226 | 0 | key = MsgSym.MESSAGE_UNCHECKED_IMPLEMENT; |
1227 | |
else |
1228 | 0 | key = MsgSym.MESSAGE_UNCHECKED_CLASH_WITH; |
1229 | 0 | return JCDiagnostic.fragment(key, m, m.location(), other, other.location()); |
1230 | |
} |
1231 | |
|
1232 | |
|
1233 | |
|
1234 | |
|
1235 | |
|
1236 | |
|
1237 | |
static Object varargsOverrides(MethodSymbol m, MethodSymbol other) { |
1238 | |
String key; |
1239 | 0 | if ((other.owner.flags() & INTERFACE) == 0) |
1240 | 0 | key = MsgSym.MESSAGE_VARARGS_OVERRIDE; |
1241 | 0 | else if ((m.owner.flags() & INTERFACE) == 0) |
1242 | 0 | key = MsgSym.MESSAGE_VARARGS_IMPLEMENT; |
1243 | |
else |
1244 | 0 | key = MsgSym.MESSAGE_VARARGS_CLASH_WITH; |
1245 | 0 | return JCDiagnostic.fragment(key, m, m.location(), other, other.location()); |
1246 | |
} |
1247 | |
|
1248 | |
|
1249 | |
|
1250 | |
|
1251 | |
|
1252 | |
|
1253 | |
|
1254 | |
|
1255 | |
|
1256 | |
|
1257 | |
|
1258 | |
|
1259 | |
|
1260 | |
|
1261 | |
|
1262 | |
|
1263 | |
|
1264 | |
|
1265 | |
|
1266 | |
|
1267 | |
|
1268 | |
|
1269 | |
public |
1270 | |
void checkOverride(JCTree tree, |
1271 | |
MethodSymbol m, |
1272 | |
MethodSymbol other, |
1273 | |
ClassSymbol origin) { |
1274 | |
|
1275 | 215 | if ((m.flags() & (SYNTHETIC|BRIDGE)) != 0 || (other.flags() & SYNTHETIC) != 0) { |
1276 | 35 | return; |
1277 | |
} |
1278 | |
|
1279 | |
|
1280 | 180 | if ((m.flags() & STATIC) != 0 && |
1281 | |
(other.flags() & STATIC) == 0) { |
1282 | 0 | log.error(JavafxTreeInfo.diagnosticPositionFor(m, tree), MsgSym.MESSAGE_OVERRIDE_STATIC, |
1283 | |
cannotOverride(m, other)); |
1284 | 0 | return; |
1285 | |
} |
1286 | |
|
1287 | |
|
1288 | |
|
1289 | 180 | if ((other.flags() & FINAL) != 0 || |
1290 | |
(m.flags() & STATIC) == 0 && |
1291 | |
(other.flags() & STATIC) != 0) { |
1292 | 0 | log.error(JavafxTreeInfo.diagnosticPositionFor(m, tree), MsgSym.MESSAGE_OVERRIDE_METH, |
1293 | |
cannotOverride(m, other), |
1294 | |
JavafxTreeInfo.flagNames(other.flags() & (FINAL | STATIC))); |
1295 | 0 | return; |
1296 | |
} |
1297 | |
|
1298 | |
|
1299 | 180 | if ((other.flags() & JavafxFlags.BOUND) == 0 && (m.flags() & JavafxFlags.BOUND) != 0) { |
1300 | 0 | log.error(JavafxTreeInfo.diagnosticPositionFor(m, tree), MsgSym.MESSAGE_JAVAFX_BOUND_OVERRIDE_METH, |
1301 | |
cannotOverride(m, other)); |
1302 | 0 | return; |
1303 | |
} |
1304 | |
|
1305 | |
|
1306 | 180 | if ((other.flags() & JavafxFlags.BOUND) != 0 && (m.flags() & JavafxFlags.BOUND) == 0) { |
1307 | 0 | log.error(JavafxTreeInfo.diagnosticPositionFor(m, tree), MsgSym.MESSAGE_JAVAFX_NON_BOUND_OVERRIDE_METH, |
1308 | |
cannotOverride(m, other)); |
1309 | 0 | return; |
1310 | |
} |
1311 | |
|
1312 | 180 | if ((m.owner.flags() & ANNOTATION) != 0) { |
1313 | |
|
1314 | 0 | return; |
1315 | |
} |
1316 | |
|
1317 | |
|
1318 | |
|
1319 | |
|
1320 | |
|
1321 | |
|
1322 | |
|
1323 | |
|
1324 | |
|
1325 | |
|
1326 | |
|
1327 | |
|
1328 | 180 | Type mt = types.memberType(origin.type, m); |
1329 | 180 | Type ot = types.memberType(origin.type, other); |
1330 | |
|
1331 | |
|
1332 | |
|
1333 | |
|
1334 | 180 | List<Type> mtvars = mt.getTypeArguments(); |
1335 | 180 | List<Type> otvars = ot.getTypeArguments(); |
1336 | 180 | Type mtres = mt.getReturnType(); |
1337 | 180 | Type otres = types.subst(ot.getReturnType(), otvars, mtvars); |
1338 | |
|
1339 | 180 | overrideWarner.warned = false; |
1340 | 180 | boolean resultTypesOK = |
1341 | |
types.returnTypeSubstitutable(mt, ot, otres, overrideWarner); |
1342 | 180 | if (!resultTypesOK) { |
1343 | 0 | if (!source.allowCovariantReturns() && |
1344 | |
m.owner != origin && |
1345 | |
m.owner.isSubClass(other.owner, types)) { |
1346 | |
|
1347 | |
} else { |
1348 | 0 | typeError(JavafxTreeInfo.diagnosticPositionFor(m, tree), |
1349 | |
JCDiagnostic.fragment(MsgSym.MESSAGE_OVERRIDE_INCOMPATIBLE_RET, |
1350 | |
cannotOverride(m, other)), |
1351 | |
mtres, otres); |
1352 | 0 | return; |
1353 | |
} |
1354 | 180 | } else if (overrideWarner.warned) { |
1355 | 0 | warnUnchecked(JavafxTreeInfo.diagnosticPositionFor(m, tree), |
1356 | |
MsgSym.MESSAGE_PROB_FOUND_REQ, |
1357 | |
JCDiagnostic.fragment(MsgSym.MESSAGE_OVERRIDE_UNCHECKED_RET, |
1358 | |
uncheckedOverrides(m, other)), |
1359 | |
mtres, otres); |
1360 | |
} |
1361 | |
|
1362 | |
|
1363 | |
|
1364 | 180 | List<Type> otthrown = types.subst(ot.getThrownTypes(), otvars, mtvars); |
1365 | 180 | List<Type> unhandled = unHandled(mt.getThrownTypes(), otthrown); |
1366 | 180 | if (unhandled.nonEmpty()) { |
1367 | 0 | log.error(JavafxTreeInfo.diagnosticPositionFor(m, tree), |
1368 | |
MsgSym.MESSAGE_OVERRIDE_METH_DOES_NOT_THROW, |
1369 | |
cannotOverride(m, other), |
1370 | |
unhandled.head); |
1371 | 0 | return; |
1372 | |
} |
1373 | |
|
1374 | |
|
1375 | 180 | if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0) |
1376 | |
&& lint.isEnabled(Lint.LintCategory.OVERRIDES)) { |
1377 | 0 | log.warning(JavafxTreeInfo.diagnosticPositionFor(m, tree), |
1378 | |
((m.flags() & Flags.VARARGS) != 0) |
1379 | |
? MsgSym.MESSAGE_OVERRIDE_VARARGS_MISSING |
1380 | |
: MsgSym.MESSAGE_OVERRIDE_VARARGS_EXTRA, |
1381 | |
varargsOverrides(m, other)); |
1382 | |
} |
1383 | |
|
1384 | |
|
1385 | 180 | if ((other.flags() & BRIDGE) != 0) { |
1386 | 0 | log.warning(JavafxTreeInfo.diagnosticPositionFor(m, tree), MsgSym.MESSAGE_OVERRIDE_BRIDGE, |
1387 | |
uncheckedOverrides(m, other)); |
1388 | |
} |
1389 | |
|
1390 | |
|
1391 | 180 | if ((other.flags() & DEPRECATED) != 0 |
1392 | |
&& (m.flags() & DEPRECATED) == 0 |
1393 | |
&& m.outermostClass() != other.outermostClass() |
1394 | |
&& !isDeprecatedOverrideIgnorable(other, origin)) { |
1395 | 0 | warnDeprecated(JavafxTreeInfo.diagnosticPositionFor(m, tree), other); |
1396 | |
} |
1397 | 180 | } |
1398 | |
|
1399 | |
private boolean isDeprecatedOverrideIgnorable(MethodSymbol m, ClassSymbol origin) { |
1400 | |
|
1401 | |
|
1402 | |
|
1403 | |
|
1404 | |
|
1405 | |
|
1406 | |
|
1407 | 0 | ClassSymbol mc = m.enclClass(); |
1408 | 0 | Type st = types.supertype(origin.type); |
1409 | 0 | if (st.tag != CLASS) |
1410 | 0 | return true; |
1411 | 0 | MethodSymbol stimpl = m.implementation((ClassSymbol)st.tsym, types, false); |
1412 | |
|
1413 | 0 | if (mc != null && ((mc.flags() & INTERFACE) != 0)) { |
1414 | 0 | List<Type> intfs = types.interfaces(origin.type); |
1415 | 0 | return (intfs.contains(mc.type) ? false : (stimpl != null)); |
1416 | |
} |
1417 | |
else |
1418 | 0 | return (stimpl != m); |
1419 | |
} |
1420 | |
|
1421 | |
|
1422 | |
|
1423 | 399 | Warner overrideWarner = new Warner(); |
1424 | |
|
1425 | |
|
1426 | |
|
1427 | |
|
1428 | |
|
1429 | |
|
1430 | |
public void checkCompatibleConcretes(DiagnosticPosition pos, Type site) { |
1431 | 667 | Type sup = types.supertype(site); |
1432 | 667 | if (sup.tag != CLASS) return; |
1433 | |
|
1434 | 667 | for (Type t1 = sup; |
1435 | 667 | t1.tsym.type.isParameterized(); |
1436 | 0 | t1 = types.supertype(t1)) { |
1437 | 0 | for (Scope.Entry e1 = t1.tsym.members().elems; |
1438 | 0 | e1 != null; |
1439 | 0 | e1 = e1.sibling) { |
1440 | 0 | Symbol s1 = e1.sym; |
1441 | 0 | if (s1.kind != MTH || |
1442 | |
(s1.flags() & (STATIC|SYNTHETIC|BRIDGE)) != 0 || |
1443 | |
!s1.isInheritedIn(site.tsym, types) || |
1444 | |
((MethodSymbol)s1).implementation(site.tsym, |
1445 | |
types, |
1446 | |
true) != s1) |
1447 | 0 | continue; |
1448 | 0 | Type st1 = types.memberType(t1, s1); |
1449 | 0 | int s1ArgsLength = st1.getParameterTypes().length(); |
1450 | 0 | if (st1 == s1.type) continue; |
1451 | |
|
1452 | 0 | for (Type t2 = sup; |
1453 | 0 | t2.tag == CLASS; |
1454 | 0 | t2 = types.supertype(t2)) { |
1455 | 0 | for (Scope.Entry e2 = t1.tsym.members().lookup(s1.name); |
1456 | 0 | e2.scope != null; |
1457 | 0 | e2 = e2.next()) { |
1458 | 0 | Symbol s2 = e2.sym; |
1459 | 0 | if (s2 == s1 || |
1460 | |
s2.kind != MTH || |
1461 | |
(s2.flags() & (STATIC|SYNTHETIC|BRIDGE)) != 0 || |
1462 | |
s2.type.getParameterTypes().length() != s1ArgsLength || |
1463 | |
!s2.isInheritedIn(site.tsym, types) || |
1464 | |
((MethodSymbol)s2).implementation(site.tsym, |
1465 | |
types, |
1466 | |
true) != s2) |
1467 | 0 | continue; |
1468 | 0 | Type st2 = types.memberType(t2, s2); |
1469 | 0 | if (types.overrideEquivalent(st1, st2)) |
1470 | 0 | log.error(pos, MsgSym.MESSAGE_CONCRETE_INHERITANCE_CONFLICT, |
1471 | |
s1, t1, s2, t2, sup); |
1472 | |
} |
1473 | |
} |
1474 | |
} |
1475 | |
} |
1476 | 667 | } |
1477 | |
|
1478 | |
|
1479 | |
|
1480 | |
|
1481 | |
|
1482 | |
|
1483 | |
|
1484 | |
public boolean checkCompatibleAbstracts(DiagnosticPosition pos, |
1485 | |
Type t1, |
1486 | |
Type t2) { |
1487 | 0 | return checkCompatibleAbstracts(pos, t1, t2, |
1488 | |
types.makeCompoundType(t1, t2)); |
1489 | |
} |
1490 | |
|
1491 | |
public boolean checkCompatibleAbstracts(DiagnosticPosition pos, |
1492 | |
Type t1, |
1493 | |
Type t2, |
1494 | |
Type site) { |
1495 | 11 | Symbol sym = firstIncompatibility(t1, t2, site); |
1496 | 11 | if (sym != null) { |
1497 | 0 | log.error(pos, MsgSym.MESSAGE_TYPES_INCOMPATIBLE_DIFF_RET, |
1498 | |
t1, t2, sym.name + |
1499 | |
"(" + types.memberType(t2, sym).getParameterTypes() + ")"); |
1500 | 0 | return false; |
1501 | |
} |
1502 | 11 | return true; |
1503 | |
} |
1504 | |
|
1505 | |
|
1506 | |
|
1507 | |
|
1508 | |
|
1509 | |
|
1510 | |
|
1511 | |
|
1512 | |
|
1513 | |
private Symbol firstIncompatibility(Type t1, Type t2, Type site) { |
1514 | 11 | Map<TypeSymbol,Type> interfaces1 = new HashMap<TypeSymbol,Type>(); |
1515 | 11 | closure(t1, interfaces1); |
1516 | |
Map<TypeSymbol,Type> interfaces2; |
1517 | 11 | if (t1 == t2) |
1518 | 0 | interfaces2 = interfaces1; |
1519 | |
else |
1520 | 11 | closure(t2, interfaces1, interfaces2 = new HashMap<TypeSymbol,Type>()); |
1521 | |
|
1522 | 11 | for (Type t3 : interfaces1.values()) { |
1523 | 25 | for (Type t4 : interfaces2.values()) { |
1524 | 29 | Symbol s = firstDirectIncompatibility(t3, t4, site); |
1525 | 29 | if (s != null) return s; |
1526 | 29 | } |
1527 | |
} |
1528 | 11 | return null; |
1529 | |
} |
1530 | |
|
1531 | |
|
1532 | |
private void closure(Type t, Map<TypeSymbol,Type> typeMap) { |
1533 | 39 | if (t.tag != CLASS) return; |
1534 | 28 | if (typeMap.put(t.tsym, t) == null) { |
1535 | 25 | closure(types.supertype(t), typeMap); |
1536 | 25 | for (Type i : types.interfaces(t)) |
1537 | 3 | closure(i, typeMap); |
1538 | |
} |
1539 | 28 | } |
1540 | |
|
1541 | |
|
1542 | |
private void closure(Type t, Map<TypeSymbol,Type> typesSkip, Map<TypeSymbol,Type> typeMap) { |
1543 | 28 | if (t.tag != CLASS) return; |
1544 | 28 | if (typesSkip.get(t.tsym) != null) return; |
1545 | 13 | if (typeMap.put(t.tsym, t) == null) { |
1546 | 13 | closure(types.supertype(t), typesSkip, typeMap); |
1547 | 13 | for (Type i : types.interfaces(t)) |
1548 | 4 | closure(i, typesSkip, typeMap); |
1549 | |
} |
1550 | 13 | } |
1551 | |
|
1552 | |
|
1553 | |
private Symbol firstDirectIncompatibility(Type t1, Type t2, Type site) { |
1554 | 265 | for (Scope.Entry e1 = t1.tsym.members().elems; e1 != null; e1 = e1.sibling) { |
1555 | 236 | Symbol s1 = e1.sym; |
1556 | 236 | Type st1 = null; |
1557 | 236 | if (s1.kind != MTH || s1.name == defs.runMethodName || |
1558 | 19 | !s1.isInheritedIn(site.tsym, types)) continue; |
1559 | 204 | Symbol impl = types.implementation((MethodSymbol)s1, site.tsym, false); |
1560 | 204 | if (impl != null && (impl.flags() & ABSTRACT) == 0) continue; |
1561 | 188 | for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); e2.scope != null; e2 = e2.next()) { |
1562 | 24 | Symbol s2 = e2.sym; |
1563 | 24 | if (s1 == s2) continue; |
1564 | 24 | if (s2.kind != MTH || !s2.isInheritedIn(site.tsym, types)) continue; |
1565 | 24 | if (st1 == null) st1 = types.memberType(t1, s1); |
1566 | 24 | Type st2 = types.memberType(t2, s2); |
1567 | 24 | if (types.overrideEquivalent(st1, st2)) { |
1568 | 12 | List<Type> tvars1 = st1.getTypeArguments(); |
1569 | 12 | List<Type> tvars2 = st2.getTypeArguments(); |
1570 | 12 | Type rt1 = st1.getReturnType(); |
1571 | 12 | Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1); |
1572 | 12 | boolean compat = |
1573 | |
types.isSameType(rt1, rt2) || |
1574 | |
rt1.tag >= CLASS && rt2.tag >= CLASS && |
1575 | |
(types.covariantReturnType(rt1, rt2, Warner.noWarnings) || |
1576 | |
types.covariantReturnType(rt2, rt1, Warner.noWarnings)); |
1577 | 12 | if (!compat) return s2; |
1578 | |
} |
1579 | |
} |
1580 | |
} |
1581 | 29 | return null; |
1582 | |
} |
1583 | |
|
1584 | |
|
1585 | |
|
1586 | |
|
1587 | |
|
1588 | |
|
1589 | |
|
1590 | |
public |
1591 | |
|
1592 | |
void checkOverride(JCTree tree, MethodSymbol m) { |
1593 | 1237 | ClassSymbol origin = (ClassSymbol)m.owner; |
1594 | 1237 | if ((origin.flags() & ENUM) != 0 && names.finalize.equals(m.name)) |
1595 | 0 | if (m.overrides(syms.enumFinalFinalize, origin, types, false)) { |
1596 | 0 | log.error(tree.pos(), MsgSym.MESSAGE_ENUM_NO_FINALIZE); |
1597 | 0 | return; |
1598 | |
} |
1599 | 1237 | ListBuffer<Type> supertypes = ListBuffer.<Type>lb(); |
1600 | 1237 | Set<Type> superSet = new HashSet<Type>(); |
1601 | 1237 | types.getSupertypes(origin, supertypes, superSet); |
1602 | |
|
1603 | 1237 | for (Type t : supertypes) { |
1604 | 1673 | if (t.tag == CLASS) { |
1605 | 1673 | TypeSymbol c = t.tsym; |
1606 | 1673 | Scope.Entry e = c.members().lookup(m.name); |
1607 | 1799 | while (e.scope != null) { |
1608 | 126 | e.sym.complete(); |
1609 | 126 | if (m.overrides(e.sym, origin, types, false)) |
1610 | 121 | checkOverride(tree, m, (MethodSymbol)e.sym, origin); |
1611 | 126 | e = e.next(); |
1612 | |
} |
1613 | 1673 | } |
1614 | |
} |
1615 | 1237 | } |
1616 | |
|
1617 | |
|
1618 | |
|
1619 | |
|
1620 | |
|
1621 | |
|
1622 | |
public |
1623 | |
|
1624 | |
void checkAllDefined(DiagnosticPosition pos, ClassSymbol c) { |
1625 | |
try { |
1626 | 650 | MethodSymbol undef = firstUndef(c, c); |
1627 | 650 | if (undef != null) { |
1628 | 0 | if ((c.flags() & ENUM) != 0 && |
1629 | |
types.supertype(c.type).tsym == syms.enumSym && |
1630 | |
(c.flags() & FINAL) == 0) { |
1631 | |
|
1632 | 0 | c.flags_field |= ABSTRACT; |
1633 | |
} else { |
1634 | 0 | MethodSymbol undef1 = |
1635 | |
new MethodSymbol(undef.flags(), undef.name, |
1636 | |
types.memberType(c.type, undef), undef.owner); |
1637 | 0 | log.error(pos, MsgSym.MESSAGE_DOES_NOT_OVERRIDE_ABSTRACT, |
1638 | |
c, undef1, undef1.location()); |
1639 | |
} |
1640 | |
} |
1641 | 0 | } catch (CompletionFailure ex) { |
1642 | 0 | completionError(pos, ex); |
1643 | 650 | } |
1644 | 650 | } |
1645 | |
|
1646 | |
|
1647 | |
|
1648 | |
|
1649 | |
private MethodSymbol firstUndef(ClassSymbol impl, ClassSymbol c) { |
1650 | 1489 | MethodSymbol undef = null; |
1651 | |
|
1652 | |
|
1653 | 1489 | if (c == impl || (c.flags() & (ABSTRACT | INTERFACE)) != 0) { |
1654 | 712 | Scope s = c.members(); |
1655 | 712 | for (Scope.Entry e = s.elems; |
1656 | 3675 | undef == null && e != null; |
1657 | 2963 | e = e.sibling) { |
1658 | 2963 | if (e.sym.kind == MTH && |
1659 | |
(e.sym.flags() & (ABSTRACT|IPROXY)) == ABSTRACT) { |
1660 | 61 | MethodSymbol absmeth = (MethodSymbol)e.sym; |
1661 | 61 | MethodSymbol implmeth = types.implementation(absmeth, impl, true); |
1662 | 61 | if (implmeth == null || implmeth == absmeth) { |
1663 | 0 | undef = absmeth; |
1664 | |
} |
1665 | |
} |
1666 | |
} |
1667 | 712 | if (undef == null) { |
1668 | 712 | Type st = types.supertype(c.type); |
1669 | 712 | if (st.tag == CLASS) |
1670 | 712 | undef = firstUndef(impl, (ClassSymbol)st.tsym); |
1671 | |
} |
1672 | 712 | for (List<Type> l = types.interfaces(c.type); |
1673 | 839 | undef == null && l.nonEmpty(); |
1674 | 127 | l = l.tail) { |
1675 | 127 | undef = firstUndef(impl, (ClassSymbol)l.head.tsym); |
1676 | |
} |
1677 | |
} |
1678 | 1489 | return undef; |
1679 | |
} |
1680 | |
|
1681 | |
|
1682 | |
|
1683 | |
|
1684 | |
|
1685 | |
|
1686 | |
|
1687 | |
|
1688 | |
public |
1689 | |
|
1690 | |
void checkNonCyclic(DiagnosticPosition pos, Type t) { |
1691 | 2701 | checkNonCyclicInternal(pos, t); |
1692 | 2701 | } |
1693 | |
|
1694 | |
|
1695 | |
void checkNonCyclic(DiagnosticPosition pos, TypeVar t) { |
1696 | 0 | checkNonCyclic1(pos, t, new HashSet<TypeVar>()); |
1697 | 0 | } |
1698 | |
|
1699 | |
private void checkNonCyclic1(DiagnosticPosition pos, Type t, Set<TypeVar> seen) { |
1700 | |
final TypeVar tv; |
1701 | 0 | if (seen.contains(t)) { |
1702 | 0 | tv = (TypeVar)t; |
1703 | 0 | tv.bound = new ErrorType(); |
1704 | 0 | log.error(pos, MsgSym.MESSAGE_CYCLIC_INHERITANCE, t); |
1705 | 0 | } else if (t.tag == TYPEVAR) { |
1706 | 0 | tv = (TypeVar)t; |
1707 | 0 | seen.add(tv); |
1708 | 0 | for (Type b : types.getBounds(tv)) |
1709 | 0 | checkNonCyclic1(pos, b, seen); |
1710 | |
} |
1711 | 0 | } |
1712 | |
|
1713 | |
|
1714 | |
|
1715 | |
|
1716 | |
|
1717 | |
|
1718 | |
|
1719 | |
|
1720 | |
private boolean checkNonCyclicInternal(DiagnosticPosition pos, Type t) { |
1721 | 6246 | boolean complete = true; |
1722 | |
|
1723 | 6246 | Symbol c = t.tsym; |
1724 | 6246 | if ((c.flags_field & ACYCLIC) != 0) return true; |
1725 | |
|
1726 | 2722 | if ((c.flags_field & LOCKED) != 0) { |
1727 | 2 | noteCyclic(pos, (ClassSymbol)c); |
1728 | 2720 | } else if (!c.type.isErroneous()) { |
1729 | |
try { |
1730 | 2720 | c.flags_field |= LOCKED; |
1731 | 2720 | if (c.type.tag == CLASS) { |
1732 | 2720 | ClassType clazz = (ClassType)c.type; |
1733 | 2720 | if (clazz.interfaces_field != null) |
1734 | 3145 | for (List<Type> l=clazz.interfaces_field; l.nonEmpty(); l=l.tail) |
1735 | 426 | complete &= checkNonCyclicInternal(pos, l.head); |
1736 | 2720 | if (clazz.supertype_field != null) { |
1737 | 2719 | Type st = clazz.supertype_field; |
1738 | 2719 | if (st != null && st.tag == CLASS) |
1739 | 2343 | complete &= checkNonCyclicInternal(pos, st); |
1740 | |
} |
1741 | 2720 | if (c.owner.kind == TYP) |
1742 | 776 | complete &= checkNonCyclicInternal(pos, c.owner.type); |
1743 | |
} |
1744 | |
} finally { |
1745 | 2720 | c.flags_field &= ~LOCKED; |
1746 | 2720 | } |
1747 | |
} |
1748 | 2722 | if (complete) |
1749 | 2256 | complete = ((c.flags_field & UNATTRIBUTED) == 0) && c.completer == null; |
1750 | 2722 | if (complete) c.flags_field |= ACYCLIC; |
1751 | 2722 | return complete; |
1752 | |
} |
1753 | |
|
1754 | |
|
1755 | |
private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) { |
1756 | 2 | log.error(pos, MsgSym.MESSAGE_CYCLIC_INHERITANCE, c); |
1757 | 3 | for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail) |
1758 | 1 | l.head = new ErrorType((ClassSymbol)l.head.tsym); |
1759 | 2 | Type st = types.supertype(c.type); |
1760 | 2 | if (st.tag == CLASS) |
1761 | 2 | ((ClassType)c.type).supertype_field = new ErrorType((ClassSymbol)st.tsym); |
1762 | 2 | c.type = new ErrorType(c); |
1763 | 2 | c.flags_field |= ACYCLIC; |
1764 | 2 | } |
1765 | |
|
1766 | |
|
1767 | |
|
1768 | |
|
1769 | |
|
1770 | |
|
1771 | |
public |
1772 | |
|
1773 | |
void checkImplementations(JFXClassDeclaration tree) { |
1774 | 667 | checkImplementations(tree, tree.sym); |
1775 | 667 | } |
1776 | |
|
1777 | |
|
1778 | |
|
1779 | |
|
1780 | |
void checkImplementations(JFXClassDeclaration tree, ClassSymbol ic) { |
1781 | 667 | ClassSymbol origin = tree.sym; |
1782 | 2271 | for (List<Type> l = types.closure(ic.type); l.nonEmpty(); l = l.tail) { |
1783 | 1604 | ClassSymbol lc = (ClassSymbol)l.head.tsym; |
1784 | 1604 | if ((allowGenerics || origin != lc) && (lc.flags() & ABSTRACT) != 0) { |
1785 | 5409 | for (Scope.Entry e=lc.members().elems; e != null; e=e.sibling) { |
1786 | 5257 | if (e.sym.kind == MTH && |
1787 | |
(e.sym.flags() & (STATIC|ABSTRACT)) == ABSTRACT) { |
1788 | 119 | MethodSymbol absmeth = (MethodSymbol)e.sym; |
1789 | 119 | MethodSymbol implmeth = absmeth.implementation(origin, types, false); |
1790 | 119 | if (implmeth != null && implmeth != absmeth && |
1791 | |
(implmeth.owner.flags() & INTERFACE) == |
1792 | |
(origin.flags() & INTERFACE)) { |
1793 | |
|
1794 | |
|
1795 | |
|
1796 | |
|
1797 | |
|
1798 | |
|
1799 | 94 | checkOverride(tree, implmeth, absmeth, origin); |
1800 | |
} |
1801 | |
} |
1802 | |
} |
1803 | |
} |
1804 | |
} |
1805 | 667 | } |
1806 | |
|
1807 | |
|
1808 | |
|
1809 | |
|
1810 | |
|
1811 | |
|
1812 | |
|
1813 | |
public |
1814 | |
|
1815 | |
void checkCompatibleSupertypes(DiagnosticPosition pos, Type c) { |
1816 | 667 | List<Type> supertypes = types.interfaces(c); |
1817 | 667 | Type supertype = types.supertype(c); |
1818 | 667 | if (supertype.tag == CLASS && |
1819 | |
(supertype.tsym.flags() & ABSTRACT) != 0) |
1820 | 3 | supertypes = supertypes.prepend(supertype); |
1821 | 775 | for (List<Type> l = supertypes; l.nonEmpty(); l = l.tail) { |
1822 | 108 | if (allowGenerics && !l.head.getTypeArguments().isEmpty() && |
1823 | |
!checkCompatibleAbstracts(pos, l.head, l.head, c)) |
1824 | 0 | return; |
1825 | 119 | for (List<Type> m = supertypes; m != l; m = m.tail) |
1826 | 11 | if (!checkCompatibleAbstracts(pos, l.head, m.head, c)) |
1827 | 0 | return; |
1828 | |
} |
1829 | 667 | checkCompatibleConcretes(pos, c); |
1830 | 667 | } |
1831 | |
|
1832 | |
|
1833 | |
|
1834 | |
|
1835 | |
|
1836 | |
|
1837 | |
|
1838 | |
public |
1839 | |
|
1840 | |
void checkClassBounds(DiagnosticPosition pos, Type type) { |
1841 | 670 | checkClassBounds(pos, new HashMap<TypeSymbol,Type>(), type); |
1842 | 670 | } |
1843 | |
|
1844 | |
|
1845 | |
|
1846 | |
|
1847 | |
|
1848 | |
void checkClassBounds(DiagnosticPosition pos, |
1849 | |
Map<TypeSymbol,Type> seensofar, |
1850 | |
Type type) { |
1851 | 2770 | if (type.isErroneous()) return; |
1852 | 3010 | for (List<Type> l = types.interfaces(type); l.nonEmpty(); l = l.tail) { |
1853 | 240 | Type it = l.head; |
1854 | 240 | Type oldit = seensofar.put(it.tsym, it); |
1855 | 240 | if (oldit != null) { |
1856 | 10 | List<Type> oldparams = oldit.allparams(); |
1857 | 10 | List<Type> newparams = it.allparams(); |
1858 | 10 | if (!types.containsTypeEquivalent(oldparams, newparams)) |
1859 | 0 | log.error(pos, MsgSym.MESSAGE_CANNOT_INHERIT_DIFF_ARG, |
1860 | |
it.tsym, Type.toString(oldparams), |
1861 | |
Type.toString(newparams)); |
1862 | |
} |
1863 | 240 | checkClassBounds(pos, seensofar, it); |
1864 | |
} |
1865 | 2770 | Type st = types.supertype(type); |
1866 | 2770 | if (st != null) checkClassBounds(pos, seensofar, st); |
1867 | 2770 | } |
1868 | |
|
1869 | |
|
1870 | |
|
1871 | |
|
1872 | |
|
1873 | |
public |
1874 | |
|
1875 | |
void checkNotRepeated(DiagnosticPosition pos, Type it, Set<Type> its) { |
1876 | 129 | if (its.contains(it)) |
1877 | 0 | log.error(pos, MsgSym.MESSAGE_REPEATED_INTERFACE); |
1878 | |
else { |
1879 | 129 | its.add(it); |
1880 | |
} |
1881 | 129 | } |
1882 | |
|
1883 | |
|
1884 | |
|
1885 | |
|
1886 | |
|
1887 | |
|
1888 | |
|
1889 | |
|
1890 | |
|
1891 | |
|
1892 | |
public |
1893 | |
|
1894 | |
void validateAnnotationType(JCTree restype) { |
1895 | |
|
1896 | 0 | if (restype != null) { |
1897 | 0 | validateAnnotationType(restype.pos(), restype.type); |
1898 | |
} |
1899 | 0 | } |
1900 | |
|
1901 | |
void validateAnnotationType(DiagnosticPosition pos, Type type) { |
1902 | 0 | if (type.isPrimitive()) return; |
1903 | 0 | if (types.isSameType(type, syms.stringType)) return; |
1904 | 0 | if ((type.tsym.flags() & Flags.ENUM) != 0) return; |
1905 | 0 | if ((type.tsym.flags() & Flags.ANNOTATION) != 0) return; |
1906 | 0 | if (types.lowerBound(type).tsym == syms.classType.tsym) return; |
1907 | 0 | if (types.isArray(type) && !types.isArray(types.elemtype(type))) { |
1908 | 0 | validateAnnotationType(pos, types.elemtype(type)); |
1909 | 0 | return; |
1910 | |
} |
1911 | 0 | log.error(pos, MsgSym.MESSAGE_INVALID_ANNOTATION_MEMBER_TYPE); |
1912 | 0 | } |
1913 | |
|
1914 | |
|
1915 | |
|
1916 | |
|
1917 | |
|
1918 | |
|
1919 | |
|
1920 | |
|
1921 | |
|
1922 | |
|
1923 | |
public |
1924 | |
|
1925 | |
void validateAnnotationMethod(DiagnosticPosition pos, MethodSymbol m) { |
1926 | 0 | for (Type sup = syms.annotationType; sup.tag == CLASS; sup = types.supertype(sup)) { |
1927 | 0 | Scope s = sup.tsym.members(); |
1928 | 0 | for (Scope.Entry e = s.lookup(m.name); e.scope != null; e = e.next()) { |
1929 | 0 | if (e.sym.kind == MTH && |
1930 | |
(e.sym.flags() & (PUBLIC | PROTECTED)) != 0 && |
1931 | |
types.overrideEquivalent(m.type, e.sym.type)) |
1932 | 0 | log.error(pos, MsgSym.MESSAGE_INTF_ANNOTATION_MEMBER_CLASH, e.sym, sup); |
1933 | |
} |
1934 | |
} |
1935 | 0 | } |
1936 | |
|
1937 | |
|
1938 | |
|
1939 | |
public void validateAnnotations(List<JCAnnotation> annotations, Symbol s) { |
1940 | 3943 | if (skipAnnotations) return; |
1941 | 3943 | for (JCAnnotation a : annotations) |
1942 | 0 | validateAnnotation(a, s); |
1943 | 3943 | } |
1944 | |
|
1945 | |
|
1946 | |
|
1947 | |
public void validateAnnotation(JCAnnotation a, Symbol s) { |
1948 | 0 | validateAnnotation(a); |
1949 | |
|
1950 | 0 | if (!annotationApplicable(a, s)) |
1951 | 0 | log.error(a.pos(), MsgSym.MESSAGE_ANNOTATION_TYPE_NOT_APPLICABLE); |
1952 | |
|
1953 | 0 | if (a.annotationType.type.tsym == syms.overrideType.tsym) { |
1954 | 0 | if (!isOverrider(s)) |
1955 | 0 | log.error(a.pos(), MsgSym.MESSAGE_METHOD_DOES_NOT_OVERRIDE_SUPERCLASS); |
1956 | |
} |
1957 | 0 | } |
1958 | |
|
1959 | |
|
1960 | |
boolean isOverrider(Symbol s) { |
1961 | 0 | if (s.kind != MTH || s.isStatic()) |
1962 | 0 | return false; |
1963 | 0 | MethodSymbol m = (MethodSymbol)s; |
1964 | 0 | TypeSymbol owner = (TypeSymbol)m.owner; |
1965 | 0 | for (Type sup : types.closure(owner.type)) { |
1966 | 0 | if (sup == owner.type) |
1967 | 0 | continue; |
1968 | 0 | Scope scope = sup.tsym.members(); |
1969 | 0 | for (Scope.Entry e = scope.lookup(m.name); e.scope != null; e = e.next()) { |
1970 | 0 | if (!e.sym.isStatic() && m.overrides(e.sym, owner, types, true)) |
1971 | 0 | return true; |
1972 | |
} |
1973 | 0 | } |
1974 | 0 | return false; |
1975 | |
} |
1976 | |
|
1977 | |
|
1978 | |
boolean annotationApplicable(JCAnnotation a, Symbol s) { |
1979 | 0 | Attribute.Compound atTarget = |
1980 | |
a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); |
1981 | 0 | if (atTarget == null) return true; |
1982 | 0 | Attribute atValue = atTarget.member(names.value); |
1983 | 0 | if (!(atValue instanceof Attribute.Array)) return true; |
1984 | 0 | Attribute.Array arr = (Attribute.Array) atValue; |
1985 | 0 | for (Attribute app : arr.values) { |
1986 | 0 | if (!(app instanceof Attribute.Enum)) return true; |
1987 | 0 | Attribute.Enum e = (Attribute.Enum) app; |
1988 | 0 | if (e.value.name == names.TYPE) |
1989 | 0 | { if (s.kind == TYP) return true; } |
1990 | 0 | else if (e.value.name == names.FIELD) |
1991 | 0 | { if (s.kind == VAR && s.owner.kind != MTH) return true; } |
1992 | 0 | else if (e.value.name == names.METHOD) |
1993 | 0 | { if (s.kind == MTH && !s.isConstructor()) return true; } |
1994 | 0 | else if (e.value.name == names.PARAMETER) |
1995 | 0 | { if (s.kind == VAR && |
1996 | |
s.owner.kind == MTH && |
1997 | |
(s.flags() & PARAMETER) != 0) |
1998 | 0 | return true; |
1999 | |
} |
2000 | 0 | else if (e.value.name == names.CONSTRUCTOR) |
2001 | 0 | { if (s.kind == MTH && s.isConstructor()) return true; } |
2002 | 0 | else if (e.value.name == names.LOCAL_VARIABLE) |
2003 | 0 | { if (s.kind == VAR && s.owner.kind == MTH && |
2004 | |
(s.flags() & PARAMETER) == 0) |
2005 | 0 | return true; |
2006 | |
} |
2007 | 0 | else if (e.value.name == names.ANNOTATION_TYPE) |
2008 | 0 | { if (s.kind == TYP && (s.flags() & ANNOTATION) != 0) |
2009 | 0 | return true; |
2010 | |
} |
2011 | 0 | else if (e.value.name == names.PACKAGE) |
2012 | 0 | { if (s.kind == PCK) return true; } |
2013 | |
else |
2014 | 0 | return true; |
2015 | |
} |
2016 | 0 | return false; |
2017 | |
} |
2018 | |
|
2019 | |
|
2020 | |
|
2021 | |
public void validateAnnotation(JCAnnotation a) { |
2022 | 0 | if (a.type.isErroneous()) return; |
2023 | |
|
2024 | |
|
2025 | 0 | Set<MethodSymbol> members = new HashSet<MethodSymbol>(); |
2026 | 0 | for (Scope.Entry e = a.annotationType.type.tsym.members().elems; |
2027 | 0 | e != null; |
2028 | 0 | e = e.sibling) |
2029 | 0 | if (e.sym.kind == MTH) |
2030 | 0 | members.add((MethodSymbol) e.sym); |
2031 | |
|
2032 | |
|
2033 | 0 | for (JCTree arg : a.args) { |
2034 | 0 | if (arg.getTag() != JCTree.ASSIGN) continue; |
2035 | 0 | JCAssign assign = (JCAssign) arg; |
2036 | 0 | Symbol m = JavafxTreeInfo.symbol(assign.lhs); |
2037 | 0 | if (m == null || m.type.isErroneous()) continue; |
2038 | 0 | if (!members.remove(m)) |
2039 | 0 | log.error(arg.pos(), MsgSym.MESSAGE_DUPLICATE_ANNOTATION_MEMBER_VALUE, |
2040 | |
m.name, a.type); |
2041 | 0 | if (assign.rhs.getTag() == ANNOTATION) |
2042 | 0 | validateAnnotation((JCAnnotation)assign.rhs); |
2043 | 0 | } |
2044 | |
|
2045 | |
|
2046 | 0 | for (MethodSymbol m : members) |
2047 | 0 | if (m.defaultValue == null && !m.type.isErroneous()) |
2048 | 0 | log.error(a.pos(), MsgSym.MESSAGE_ANNOTATION_MISSING_DEFAULT_VALUE, |
2049 | |
a.type, m.name); |
2050 | |
|
2051 | |
|
2052 | |
|
2053 | 0 | if (a.annotationType.type.tsym != syms.annotationTargetType.tsym || |
2054 | |
a.args.tail == null) |
2055 | 0 | return; |
2056 | |
|
2057 | 0 | if (a.args.head.getTag() != JCTree.ASSIGN) return; |
2058 | 0 | JCAssign assign = (JCAssign) a.args.head; |
2059 | 0 | Symbol m = JavafxTreeInfo.symbol(assign.lhs); |
2060 | 0 | if (m.name != names.value) return; |
2061 | 0 | JCTree rhs = assign.rhs; |
2062 | 0 | if (rhs.getTag() != JCTree.NEWARRAY) return; |
2063 | 0 | JCNewArray na = (JCNewArray) rhs; |
2064 | 0 | Set<Symbol> targets = new HashSet<Symbol>(); |
2065 | 0 | for (JCTree elem : na.elems) { |
2066 | 0 | if (!targets.add(JavafxTreeInfo.symbol(elem))) { |
2067 | 0 | log.error(elem.pos(), MsgSym.MESSAGE_REPEATED_ANNOTATION_TARGET); |
2068 | |
} |
2069 | |
} |
2070 | 0 | } |
2071 | |
|
2072 | |
|
2073 | |
public |
2074 | |
|
2075 | |
void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) { |
2076 | 5183 | if (allowAnnotations && |
2077 | |
lint.isEnabled(Lint.LintCategory.DEP_ANN) && |
2078 | |
(s.flags() & DEPRECATED) != 0 && |
2079 | |
!syms.deprecatedType.isErroneous() && |
2080 | |
s.attribute(syms.deprecatedType.tsym) == null) { |
2081 | 0 | log.warning(pos, MsgSym.MESSAGE_MISSING_DEPRECATED_ANNOTATION); |
2082 | |
} |
2083 | 5183 | } |
2084 | |
|
2085 | |
|
2086 | |
|
2087 | |
|
2088 | |
|
2089 | |
|
2090 | |
|
2091 | |
|
2092 | |
public |
2093 | |
|
2094 | |
void checkNonCyclicElements(JFXClassDeclaration tree) { |
2095 | 667 | if ((tree.sym.flags_field & ANNOTATION) == 0) return; |
2096 | 0 | assert (tree.sym.flags_field & LOCKED) == 0; |
2097 | |
try { |
2098 | 0 | tree.sym.flags_field |= LOCKED; |
2099 | 0 | for (JCTree def : tree.getMembers()) { |
2100 | 0 | if (def.getTag() != JCTree.METHODDEF) continue; |
2101 | 0 | JCMethodDecl meth = (JCMethodDecl)def; |
2102 | 0 | checkAnnotationResType(meth.pos(), meth.restype.type); |
2103 | 0 | } |
2104 | |
} finally { |
2105 | 0 | tree.sym.flags_field &= ~LOCKED; |
2106 | 0 | tree.sym.flags_field |= ACYCLIC_ANN; |
2107 | 0 | } |
2108 | 0 | } |
2109 | |
|
2110 | |
void checkNonCyclicElementsInternal(DiagnosticPosition pos, TypeSymbol tsym) { |
2111 | 0 | if ((tsym.flags_field & ACYCLIC_ANN) != 0) |
2112 | 0 | return; |
2113 | 0 | if ((tsym.flags_field & LOCKED) != 0) { |
2114 | 0 | log.error(pos, MsgSym.MESSAGE_CYCLIC_ANNOTATION_ELEMENT); |
2115 | 0 | return; |
2116 | |
} |
2117 | |
try { |
2118 | 0 | tsym.flags_field |= LOCKED; |
2119 | 0 | for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) { |
2120 | 0 | Symbol s = e.sym; |
2121 | 0 | if (s.kind != Kinds.MTH) |
2122 | 0 | continue; |
2123 | 0 | checkAnnotationResType(pos, ((MethodSymbol)s).type.getReturnType()); |
2124 | |
} |
2125 | |
} finally { |
2126 | 0 | tsym.flags_field &= ~LOCKED; |
2127 | 0 | tsym.flags_field |= ACYCLIC_ANN; |
2128 | 0 | } |
2129 | 0 | } |
2130 | |
|
2131 | |
void checkAnnotationResType(DiagnosticPosition pos, Type type) { |
2132 | 0 | switch (type.tag) { |
2133 | |
case TypeTags.CLASS: |
2134 | 0 | if ((type.tsym.flags() & ANNOTATION) != 0) |
2135 | 0 | checkNonCyclicElementsInternal(pos, type.tsym); |
2136 | |
break; |
2137 | |
case TypeTags.ARRAY: |
2138 | 0 | checkAnnotationResType(pos, types.elemtype(type)); |
2139 | 0 | break; |
2140 | |
default: |
2141 | |
break; |
2142 | |
} |
2143 | 0 | } |
2144 | |
|
2145 | |
|
2146 | |
|
2147 | |
|
2148 | |
|
2149 | |
|
2150 | |
|
2151 | |
|
2152 | |
|
2153 | |
public |
2154 | |
|
2155 | |
void checkCyclicConstructors(JFXClassDeclaration tree) { |
2156 | 667 | Map<Symbol,Symbol> callMap = new HashMap<Symbol, Symbol>(); |
2157 | |
|
2158 | |
|
2159 | 2577 | for (List<JCTree> l = tree.getMembers(); l.nonEmpty(); l = l.tail) { |
2160 | 1910 | JCMethodInvocation app = JavafxTreeInfo.firstConstructorCall(l.head); |
2161 | 1910 | if (app == null) continue; |
2162 | 0 | JCMethodDecl meth = (JCMethodDecl) l.head; |
2163 | 0 | if (JavafxTreeInfo.name(app.meth) == names._this) { |
2164 | 0 | callMap.put(meth.sym, JavafxTreeInfo.symbol(app.meth)); |
2165 | |
} else { |
2166 | 0 | meth.sym.flags_field |= ACYCLIC; |
2167 | |
} |
2168 | |
} |
2169 | |
|
2170 | |
|
2171 | 667 | Symbol[] ctors = new Symbol[0]; |
2172 | 667 | ctors = callMap.keySet().toArray(ctors); |
2173 | 667 | for (Symbol caller : ctors) { |
2174 | 0 | checkCyclicConstructor(tree, caller, callMap); |
2175 | |
} |
2176 | 667 | } |
2177 | |
|
2178 | |
|
2179 | |
|
2180 | |
|
2181 | |
private void checkCyclicConstructor(JFXClassDeclaration tree, Symbol ctor, |
2182 | |
Map<Symbol,Symbol> callMap) { |
2183 | 0 | if (ctor != null && (ctor.flags_field & ACYCLIC) == 0) { |
2184 | 0 | if ((ctor.flags_field & LOCKED) != 0) { |
2185 | 0 | log.error(JavafxTreeInfo.diagnosticPositionFor(ctor, tree), |
2186 | |
MsgSym.MESSAGE_RECURSIVE_CTOR_INVOCATION); |
2187 | |
} else { |
2188 | 0 | ctor.flags_field |= LOCKED; |
2189 | 0 | checkCyclicConstructor(tree, callMap.remove(ctor), callMap); |
2190 | 0 | ctor.flags_field &= ~LOCKED; |
2191 | |
} |
2192 | 0 | ctor.flags_field |= ACYCLIC; |
2193 | |
} |
2194 | 0 | } |
2195 | |
|
2196 | |
|
2197 | |
|
2198 | |
|
2199 | |
|
2200 | |
public |
2201 | |
|
2202 | |
|
2203 | |
|
2204 | |
|
2205 | |
|
2206 | |
|
2207 | |
|
2208 | |
|
2209 | |
|
2210 | |
|
2211 | |
int checkOperator(DiagnosticPosition pos, |
2212 | |
OperatorSymbol operator, |
2213 | |
int tag, |
2214 | |
Type left, |
2215 | |
Type right) { |
2216 | 1131 | if (operator.opcode == ByteCodes.error) { |
2217 | 0 | log.error(pos, |
2218 | |
MsgSym.MESSAGE_OPERATOR_CANNOT_BE_APPLIED, |
2219 | |
treeinfo.operatorName(tag), |
2220 | |
left + "," + right); |
2221 | |
} |
2222 | 1131 | return operator.opcode; |
2223 | |
} |
2224 | |
|
2225 | |
|
2226 | |
|
2227 | |
public |
2228 | |
|
2229 | |
|
2230 | |
|
2231 | |
|
2232 | |
|
2233 | |
|
2234 | |
|
2235 | |
void checkDivZero(DiagnosticPosition pos, Symbol operator, Type operand) { |
2236 | 1131 | if (operand.constValue() != null |
2237 | |
&& lint.isEnabled(Lint.LintCategory.DIVZERO) |
2238 | |
&& operand.tag <= LONG |
2239 | |
&& ((Number) (operand.constValue())).longValue() == 0) { |
2240 | 0 | int opc = ((OperatorSymbol)operator).opcode; |
2241 | 0 | if (opc == ByteCodes.idiv || opc == ByteCodes.imod |
2242 | |
|| opc == ByteCodes.ldiv || opc == ByteCodes.lmod) { |
2243 | 0 | log.warning(pos, MsgSym.MESSAGE_DIV_ZERO); |
2244 | |
} |
2245 | |
} |
2246 | 1131 | } |
2247 | |
|
2248 | |
|
2249 | |
|
2250 | |
|
2251 | |
|
2252 | |
public |
2253 | |
|
2254 | |
void checkEmptyIf(JCIf tree) { |
2255 | 0 | if (tree.thenpart.getTag() == JCTree.SKIP && tree.elsepart == null && lint.isEnabled(Lint.LintCategory.EMPTY)) |
2256 | 0 | log.warning(tree.thenpart.pos(), MsgSym.MESSAGE_EMPTY_IF); |
2257 | 0 | } |
2258 | |
|
2259 | |
|
2260 | |
|
2261 | |
|
2262 | |
|
2263 | |
|
2264 | |
public boolean checkUnique(DiagnosticPosition pos, Symbol sym, Scope s) { |
2265 | |
|
2266 | |
|
2267 | 4346 | if (sym.type != null && sym.type.isErroneous()) |
2268 | |
|
2269 | 1 | return true; |
2270 | 4345 | if (sym.owner.name == names.any) return false; |
2271 | 5495 | for (Scope.Entry e = s.lookup(sym.name); e.scope == s; e = e.next()) { |
2272 | 1150 | sym.complete(); |
2273 | 1150 | if (sym != e.sym && |
2274 | |
sym.kind == e.sym.kind && |
2275 | |
sym.name != names.error && |
2276 | |
(sym.kind != MTH || types.overrideEquivalent(sym.type, e.sym.type))) { |
2277 | 0 | if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS)) |
2278 | 0 | varargsDuplicateError(pos, sym, e.sym); |
2279 | |
else |
2280 | 0 | duplicateError(pos, e.sym); |
2281 | 0 | return false; |
2282 | |
} |
2283 | |
} |
2284 | 4345 | return true; |
2285 | |
} |
2286 | |
|
2287 | |
|
2288 | |
|
2289 | |
|
2290 | |
|
2291 | |
|
2292 | |
|
2293 | |
|
2294 | |
public |
2295 | |
|
2296 | |
boolean checkUniqueImport(DiagnosticPosition pos, Symbol sym, Scope s) { |
2297 | 3323 | return checkUniqueImport(pos, sym, s, false); |
2298 | |
} |
2299 | |
|
2300 | |
|
2301 | |
|
2302 | |
|
2303 | |
|
2304 | |
|
2305 | |
|
2306 | |
|
2307 | |
|
2308 | |
public |
2309 | |
|
2310 | |
boolean checkUniqueStaticImport(DiagnosticPosition pos, Symbol sym, Scope s) { |
2311 | 0 | return checkUniqueImport(pos, sym, s, true); |
2312 | |
} |
2313 | |
|
2314 | |
|
2315 | |
|
2316 | |
|
2317 | |
|
2318 | |
|
2319 | |
|
2320 | |
|
2321 | |
private boolean checkUniqueImport(DiagnosticPosition pos, Symbol sym, Scope s, boolean staticImport) { |
2322 | 3325 | for (Scope.Entry e = s.lookup(sym.name); e.scope != null; e = e.next()) { |
2323 | |
|
2324 | 2 | boolean isClassDecl = e.scope == s; |
2325 | 2 | if ((isClassDecl || sym != e.sym) && |
2326 | |
sym.kind == e.sym.kind && |
2327 | |
sym.name != names.error) { |
2328 | 0 | if (!e.sym.type.isErroneous()) { |
2329 | 0 | String what = e.sym.toString(); |
2330 | 0 | if (!isClassDecl) { |
2331 | 0 | if (staticImport) |
2332 | 0 | log.error(pos, MsgSym.MESSAGE_ALREADY_DEFINED_STATIC_SINGLE_IMPORT, what); |
2333 | |
else |
2334 | 0 | log.error(pos, MsgSym.MESSAGE_ALREADY_DEFINED_SINGLE_IMPORT, what); |
2335 | |
} |
2336 | 0 | else if (sym != e.sym) |
2337 | 0 | log.error(pos, MsgSym.MESSAGE_ALREADY_DEFINED_THIS_UNIT, what); |
2338 | |
} |
2339 | 0 | return false; |
2340 | |
} |
2341 | |
} |
2342 | 3323 | return true; |
2343 | |
} |
2344 | |
|
2345 | |
|
2346 | |
|
2347 | |
public void checkCanonical(JCTree tree) { |
2348 | 668 | if (!isCanonical(tree)) |
2349 | 0 | log.error(tree.pos(), MsgSym.MESSAGE_IMPORT_REQUIRES_CANONICAL, |
2350 | |
JavafxTreeInfo.symbol(tree)); |
2351 | 668 | } |
2352 | |
|
2353 | |
private boolean isCanonical(JCTree tree) { |
2354 | 1961 | while (tree.getTag() == JCTree.SELECT) { |
2355 | 1293 | JCFieldAccess s = (JCFieldAccess) tree; |
2356 | 1293 | if (s.sym.owner != JavafxTreeInfo.symbol(s.selected)) |
2357 | 0 | return false; |
2358 | 1293 | tree = s.selected; |
2359 | 1293 | } |
2360 | 668 | return true; |
2361 | |
} |
2362 | |
|
2363 | |
private class ConversionWarner extends Warner { |
2364 | |
final String key; |
2365 | |
final Type found; |
2366 | |
final Type expected; |
2367 | 11579 | public ConversionWarner(DiagnosticPosition pos, String key, Type found, Type expected) { |
2368 | 11579 | super(pos); |
2369 | 11579 | this.key = key; |
2370 | 11579 | this.found = found; |
2371 | 11579 | this.expected = expected; |
2372 | 11579 | } |
2373 | |
|
2374 | |
@Override |
2375 | |
public void warnUnchecked() { |
2376 | 59 | boolean localWarned = this.warned; |
2377 | 59 | super.warnUnchecked(); |
2378 | 59 | if (localWarned) return; |
2379 | 59 | Object problem = JCDiagnostic.fragment(key); |
2380 | 59 | JavafxCheck.this.warnUnchecked(pos(), MsgSym.MESSAGE_PROB_FOUND_REQ, problem, found, expected); |
2381 | 59 | } |
2382 | |
} |
2383 | |
|
2384 | |
public Warner castWarner(DiagnosticPosition pos, Type found, Type expected) { |
2385 | 200 | return new ConversionWarner(pos, MsgSym.MESSAGE_UNCHECKED_CAST_TO_TYPE, found, expected); |
2386 | |
} |
2387 | |
|
2388 | |
public Warner convertWarner(DiagnosticPosition pos, Type found, Type expected) { |
2389 | 11379 | return new ConversionWarner(pos, MsgSym.MESSAGE_UNCHECKED_ASSIGN, found, expected); |
2390 | |
} |
2391 | |
|
2392 | |
public void warnEmptyRangeLiteral(DiagnosticPosition pos, JCLiteral lower, JCLiteral upper, JCLiteral step, boolean isExclusive) { |
2393 | 133 | double lowerValue = ((Number)lower.getValue()).doubleValue(); |
2394 | 132 | double upperValue = ((Number)upper.getValue()).doubleValue(); |
2395 | 131 | double stepValue = step != null? ((Number)step.getValue()).doubleValue() : 1; |
2396 | 130 | if ((stepValue > 0 && lowerValue > upperValue) |
2397 | |
|| (stepValue < 0 && lowerValue < upperValue) |
2398 | |
|| (isExclusive && lowerValue == upperValue)) { |
2399 | 17 | log.warning(pos, MsgSym.MESSAGE_JAVAFX_RANGE_LITERAL_EMPTY); |
2400 | |
} |
2401 | 130 | } |
2402 | |
} |