662 return false; |
662 return false; |
663 } else |
663 } else |
664 return true; |
664 return true; |
665 } |
665 } |
666 |
666 |
667 /** Check that the type inferred using the diamond operator does not contain |
667 /** Check that usage of diamond operator is correct (i.e. diamond should not |
668 * non-denotable types such as captured types or intersection types. |
668 * be used with non-generic classes or in anonymous class creation expressions) |
669 * @param t the type inferred using the diamond operator |
669 */ |
670 */ |
670 Type checkDiamond(JCNewClass tree, Type t) { |
671 List<Type> checkDiamond(ClassType t) { |
671 if (!TreeInfo.isDiamond(tree) || |
672 DiamondTypeChecker dtc = new DiamondTypeChecker(); |
672 t.isErroneous()) { |
673 ListBuffer<Type> buf = ListBuffer.lb(); |
673 return checkClassType(tree.clazz.pos(), t, true); |
674 for (Type arg : t.getTypeArguments()) { |
674 } else if (tree.def != null) { |
675 if (!dtc.visit(arg, null)) { |
675 log.error(tree.clazz.pos(), |
676 buf.append(arg); |
676 "cant.apply.diamond.1", |
677 } |
677 t, diags.fragment("diamond.and.anon.class", t)); |
678 } |
678 return types.createErrorType(t); |
679 return buf.toList(); |
679 } else if (!t.tsym.type.isParameterized()) { |
680 } |
680 log.error(tree.clazz.pos(), |
681 |
681 "cant.apply.diamond.1", |
682 static class DiamondTypeChecker extends Types.SimpleVisitor<Boolean, Void> { |
682 t, diags.fragment("diamond.non.generic", t)); |
683 public Boolean visitType(Type t, Void s) { |
683 return types.createErrorType(t); |
684 return true; |
684 } else { |
685 } |
685 return t; |
686 @Override |
|
687 public Boolean visitClassType(ClassType t, Void s) { |
|
688 if (t.isCompound()) { |
|
689 return false; |
|
690 } |
|
691 for (Type targ : t.getTypeArguments()) { |
|
692 if (!visit(targ, s)) { |
|
693 return false; |
|
694 } |
|
695 } |
|
696 return true; |
|
697 } |
|
698 @Override |
|
699 public Boolean visitCapturedType(CapturedType t, Void s) { |
|
700 return false; |
|
701 } |
686 } |
702 } |
687 } |
703 |
688 |
704 void checkVarargsMethodDecl(Env<AttrContext> env, JCMethodDecl tree) { |
689 void checkVarargsMethodDecl(Env<AttrContext> env, JCMethodDecl tree) { |
705 MethodSymbol m = tree.sym; |
690 MethodSymbol m = tree.sym; |