632 } else { |
632 } else { |
633 return t; |
633 return t; |
634 } |
634 } |
635 } |
635 } |
636 |
636 |
|
637 Type checkClassOrArrayType(DiagnosticPosition pos, Type t) { |
|
638 if (!t.hasTag(CLASS) && !t.hasTag(ARRAY) && !t.hasTag(ERROR)) { |
|
639 return typeTagError(pos, |
|
640 diags.fragment("type.req.class.array"), |
|
641 asTypeParam(t)); |
|
642 } else { |
|
643 return t; |
|
644 } |
|
645 } |
|
646 |
637 /** Check that type is a class or interface type. |
647 /** Check that type is a class or interface type. |
638 * @param pos Position to be used for error reporting. |
648 * @param pos Position to be used for error reporting. |
639 * @param t The type to be checked. |
649 * @param t The type to be checked. |
640 */ |
650 */ |
641 Type checkClassType(DiagnosticPosition pos, Type t) { |
651 Type checkClassType(DiagnosticPosition pos, Type t) { |
642 if (!t.hasTag(CLASS) && !t.hasTag(ERROR)) |
652 if (!t.hasTag(CLASS) && !t.hasTag(ERROR)) { |
643 return typeTagError(pos, |
653 return typeTagError(pos, |
644 diags.fragment("type.req.class"), |
654 diags.fragment("type.req.class"), |
645 (t.hasTag(TYPEVAR)) |
655 asTypeParam(t)); |
646 ? diags.fragment("type.parameter", t) |
656 } else { |
647 : t); |
|
648 else |
|
649 return t; |
657 return t; |
650 } |
658 } |
|
659 } |
|
660 //where |
|
661 private Object asTypeParam(Type t) { |
|
662 return (t.hasTag(TYPEVAR)) |
|
663 ? diags.fragment("type.parameter", t) |
|
664 : t; |
|
665 } |
651 |
666 |
652 /** Check that type is a valid qualifier for a constructor reference expression |
667 /** Check that type is a valid qualifier for a constructor reference expression |
653 */ |
668 */ |
654 Type checkConstructorRefType(DiagnosticPosition pos, Type t) { |
669 Type checkConstructorRefType(DiagnosticPosition pos, Type t) { |
655 t = checkClassType(pos, t); |
670 t = checkClassOrArrayType(pos, t); |
656 if (t.hasTag(CLASS)) { |
671 if (t.hasTag(CLASS)) { |
657 if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { |
672 if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { |
658 log.error(pos, "abstract.cant.be.instantiated"); |
673 log.error(pos, "abstract.cant.be.instantiated"); |
659 t = types.createErrorType(t); |
674 t = types.createErrorType(t); |
660 } else if ((t.tsym.flags() & ENUM) != 0) { |
675 } else if ((t.tsym.flags() & ENUM) != 0) { |
688 /** Check that type is a reifiable class, interface or array type. |
703 /** Check that type is a reifiable class, interface or array type. |
689 * @param pos Position to be used for error reporting. |
704 * @param pos Position to be used for error reporting. |
690 * @param t The type to be checked. |
705 * @param t The type to be checked. |
691 */ |
706 */ |
692 Type checkReifiableReferenceType(DiagnosticPosition pos, Type t) { |
707 Type checkReifiableReferenceType(DiagnosticPosition pos, Type t) { |
693 if (!t.hasTag(CLASS) && !t.hasTag(ARRAY) && !t.hasTag(ERROR)) { |
708 t = checkClassOrArrayType(pos, t); |
694 return typeTagError(pos, |
709 if (!t.isErroneous() && !types.isReifiable(t)) { |
695 diags.fragment("type.req.class.array"), |
|
696 t); |
|
697 } else if (!types.isReifiable(t)) { |
|
698 log.error(pos, "illegal.generic.type.for.instof"); |
710 log.error(pos, "illegal.generic.type.for.instof"); |
699 return types.createErrorType(t); |
711 return types.createErrorType(t); |
700 } else { |
712 } else { |
701 return t; |
713 return t; |
702 } |
714 } |