206 clauses = clauses.prepend(d); |
206 clauses = clauses.prepend(d); |
207 } |
207 } |
208 } |
208 } |
209 return clauses.reverse(); |
209 return clauses.reverse(); |
210 } |
210 } |
|
211 |
|
212 private int indexOf(Type type, WhereClauseKind kind) { |
|
213 int index = 1; |
|
214 for (Type t : whereClauses.get(kind).keySet()) { |
|
215 if (t.tsym == type.tsym) { |
|
216 return index; |
|
217 } |
|
218 if (kind != WhereClauseKind.TYPEVAR || |
|
219 t.toString().equals(type.toString())) { |
|
220 index++; |
|
221 } |
|
222 } |
|
223 return -1; |
|
224 } |
|
225 |
|
226 private boolean unique(TypeVar typevar) { |
|
227 int found = 0; |
|
228 for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) { |
|
229 if (t.toString().equals(typevar.toString())) { |
|
230 found++; |
|
231 } |
|
232 } |
|
233 if (found < 1) |
|
234 throw new AssertionError("Missing type variable in where clause " + typevar); |
|
235 return found == 1; |
|
236 } |
211 //where |
237 //where |
212 /** |
238 /** |
213 * This enum defines all posssible kinds of where clauses that can be |
239 * This enum defines all posssible kinds of where clauses that can be |
214 * attached by a rich diagnostic formatter to a given diagnostic |
240 * attached by a rich diagnostic formatter to a given diagnostic |
215 */ |
241 */ |
364 "compiler.misc.type.var", |
390 "compiler.misc.type.var", |
365 t.toString(), indexOf(t, WhereClauseKind.TYPEVAR)); |
391 t.toString(), indexOf(t, WhereClauseKind.TYPEVAR)); |
366 } |
392 } |
367 } |
393 } |
368 |
394 |
369 private int indexOf(Type type, WhereClauseKind kind) { |
|
370 int index = 0; |
|
371 boolean found = false; |
|
372 for (Type t : whereClauses.get(kind).keySet()) { |
|
373 if (t == type) { |
|
374 found = true; |
|
375 break; |
|
376 } |
|
377 index++; |
|
378 } |
|
379 if (!found) |
|
380 throw new AssertionError("Missing symbol in where clause " + type); |
|
381 return index + 1; |
|
382 } |
|
383 |
|
384 private boolean unique(TypeVar typevar) { |
|
385 int found = 0; |
|
386 for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) { |
|
387 if (t.toString().equals(typevar.toString())) { |
|
388 found++; |
|
389 } |
|
390 } |
|
391 if (found < 1) |
|
392 throw new AssertionError("Missing type variable in where clause " + typevar); |
|
393 return found == 1; |
|
394 } |
|
395 |
|
396 @Override |
395 @Override |
397 protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) { |
396 protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) { |
398 return super.printMethodArgs(args, varArgs, locale); |
397 return super.printMethodArgs(args, varArgs, locale); |
399 } |
398 } |
400 |
399 |
490 return null; |
489 return null; |
491 } |
490 } |
492 |
491 |
493 @Override |
492 @Override |
494 public Void visitCapturedType(CapturedType t, Void ignored) { |
493 public Void visitCapturedType(CapturedType t, Void ignored) { |
495 if (!whereClauses.get(WhereClauseKind.CAPTURED).containsKey(t)) { |
494 if (indexOf(t, WhereClauseKind.CAPTURED) == -1) { |
496 String suffix = t.lower == syms.botType ? ".1" : ""; |
495 String suffix = t.lower == syms.botType ? ".1" : ""; |
497 JCDiagnostic d = diags.fragment("where.captured"+ suffix, t, t.bound, t.lower, t.wildcard); |
496 JCDiagnostic d = diags.fragment("where.captured"+ suffix, t, t.bound, t.lower, t.wildcard); |
498 whereClauses.get(WhereClauseKind.CAPTURED).put(t, d); |
497 whereClauses.get(WhereClauseKind.CAPTURED).put(t, d); |
499 visit(t.wildcard); |
498 visit(t.wildcard); |
500 visit(t.lower); |
499 visit(t.lower); |
504 } |
503 } |
505 |
504 |
506 @Override |
505 @Override |
507 public Void visitClassType(ClassType t, Void ignored) { |
506 public Void visitClassType(ClassType t, Void ignored) { |
508 if (t.isCompound()) { |
507 if (t.isCompound()) { |
509 if (!whereClauses.get(WhereClauseKind.INTERSECTION).containsKey(t)) { |
508 if (indexOf(t, WhereClauseKind.INTERSECTION) == -1) { |
510 Type supertype = types.supertype(t); |
509 Type supertype = types.supertype(t); |
511 List<Type> interfaces = types.interfaces(t); |
510 List<Type> interfaces = types.interfaces(t); |
512 JCDiagnostic d = diags.fragment("where.intersection", t, interfaces.prepend(supertype)); |
511 JCDiagnostic d = diags.fragment("where.intersection", t, interfaces.prepend(supertype)); |
513 whereClauses.get(WhereClauseKind.INTERSECTION).put(t, d); |
512 whereClauses.get(WhereClauseKind.INTERSECTION).put(t, d); |
514 visit(supertype); |
513 visit(supertype); |
522 return null; |
521 return null; |
523 } |
522 } |
524 |
523 |
525 @Override |
524 @Override |
526 public Void visitTypeVar(TypeVar t, Void ignored) { |
525 public Void visitTypeVar(TypeVar t, Void ignored) { |
527 if (!whereClauses.get(WhereClauseKind.TYPEVAR).containsKey(t)) { |
526 if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) { |
528 Type bound = t.bound; |
527 Type bound = t.bound; |
529 while ((bound instanceof ErrorType)) |
528 while ((bound instanceof ErrorType)) |
530 bound = ((ErrorType)bound).getOriginalType(); |
529 bound = ((ErrorType)bound).getOriginalType(); |
531 List<Type> bounds = types.getBounds(t); |
530 List<Type> bounds = types.getBounds(t); |
532 nameSimplifier.addUsage(t.tsym); |
531 nameSimplifier.addUsage(t.tsym); |