286 /** Report a failure to complete a class. |
287 /** Report a failure to complete a class. |
287 * @param pos Position to be used for error reporting. |
288 * @param pos Position to be used for error reporting. |
288 * @param ex The failure to report. |
289 * @param ex The failure to report. |
289 */ |
290 */ |
290 public Type completionError(DiagnosticPosition pos, CompletionFailure ex) { |
291 public Type completionError(DiagnosticPosition pos, CompletionFailure ex) { |
291 log.error(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE, pos, "cant.access", ex.sym, ex.getDetailValue()); |
292 log.error(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE, pos, Errors.CantAccess(ex.sym, ex.getDetailValue())); |
292 if (ex instanceof ClassFinder.BadClassFile) throw new Abort(); |
293 if (ex instanceof ClassFinder.BadClassFile) throw new Abort(); |
293 else return syms.errType; |
294 else return syms.errType; |
294 } |
295 } |
295 |
296 |
296 /** Report an error that wrong type tag was found. |
297 /** Report an error that wrong type tag was found. |
297 * @param pos Position to be used for error reporting. |
298 * @param pos Position to be used for error reporting. |
298 * @param required An internationalized string describing the type tag |
299 * @param required An internationalized string describing the type tag |
299 * required. |
300 * required. |
300 * @param found The type that was found. |
301 * @param found The type that was found. |
301 */ |
302 */ |
302 Type typeTagError(DiagnosticPosition pos, Object required, Object found) { |
303 Type typeTagError(DiagnosticPosition pos, JCDiagnostic required, Object found) { |
303 // this error used to be raised by the parser, |
304 // this error used to be raised by the parser, |
304 // but has been delayed to this point: |
305 // but has been delayed to this point: |
305 if (found instanceof Type && ((Type)found).hasTag(VOID)) { |
306 if (found instanceof Type && ((Type)found).hasTag(VOID)) { |
306 log.error(pos, "illegal.start.of.type"); |
307 log.error(pos, Errors.IllegalStartOfType); |
307 return syms.errType; |
308 return syms.errType; |
308 } |
309 } |
309 log.error(pos, "type.found.req", found, required); |
310 log.error(pos, Errors.TypeFoundReq(found, required)); |
310 return types.createErrorType(found instanceof Type ? (Type)found : syms.errType); |
311 return types.createErrorType(found instanceof Type ? (Type)found : syms.errType); |
311 } |
312 } |
312 |
313 |
313 /** Report an error that symbol cannot be referenced before super |
314 /** Report an error that symbol cannot be referenced before super |
314 * has been called. |
315 * has been called. |
315 * @param pos Position to be used for error reporting. |
316 * @param pos Position to be used for error reporting. |
316 * @param sym The referenced symbol. |
317 * @param sym The referenced symbol. |
317 */ |
318 */ |
318 void earlyRefError(DiagnosticPosition pos, Symbol sym) { |
319 void earlyRefError(DiagnosticPosition pos, Symbol sym) { |
319 log.error(pos, "cant.ref.before.ctor.called", sym); |
320 log.error(pos, Errors.CantRefBeforeCtorCalled(sym)); |
320 } |
321 } |
321 |
322 |
322 /** Report duplicate declaration error. |
323 /** Report duplicate declaration error. |
323 */ |
324 */ |
324 void duplicateError(DiagnosticPosition pos, Symbol sym) { |
325 void duplicateError(DiagnosticPosition pos, Symbol sym) { |
325 if (!sym.type.isErroneous()) { |
326 if (!sym.type.isErroneous()) { |
326 Symbol location = sym.location(); |
327 Symbol location = sym.location(); |
327 if (location.kind == MTH && |
328 if (location.kind == MTH && |
328 ((MethodSymbol)location).isStaticOrInstanceInit()) { |
329 ((MethodSymbol)location).isStaticOrInstanceInit()) { |
329 log.error(pos, "already.defined.in.clinit", kindName(sym), sym, |
330 log.error(pos, |
330 kindName(sym.location()), kindName(sym.location().enclClass()), |
331 Errors.AlreadyDefinedInClinit(kindName(sym), |
331 sym.location().enclClass()); |
332 sym, |
|
333 kindName(sym.location()), |
|
334 kindName(sym.location().enclClass()), |
|
335 sym.location().enclClass())); |
332 } else { |
336 } else { |
333 log.error(pos, "already.defined", kindName(sym), sym, |
337 log.error(pos, |
334 kindName(sym.location()), sym.location()); |
338 Errors.AlreadyDefined(kindName(sym), |
|
339 sym, |
|
340 kindName(sym.location()), |
|
341 sym.location())); |
335 } |
342 } |
336 } |
343 } |
337 } |
344 } |
338 |
345 |
339 /** Report array/varargs duplicate declaration |
346 /** Report array/varargs duplicate declaration |
340 */ |
347 */ |
341 void varargsDuplicateError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) { |
348 void varargsDuplicateError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) { |
342 if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) { |
349 if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) { |
343 log.error(pos, "array.and.varargs", sym1, sym2, sym2.location()); |
350 log.error(pos, Errors.ArrayAndVarargs(sym1, sym2, sym2.location())); |
344 } |
351 } |
345 } |
352 } |
346 |
353 |
347 /* ************************************************************************ |
354 /* ************************************************************************ |
348 * duplicate declaration checking |
355 * duplicate declaration checking |
576 return found; |
583 return found; |
577 if (checkContext.compatible(found, req, checkContext.checkWarner(pos, found, req))) { |
584 if (checkContext.compatible(found, req, checkContext.checkWarner(pos, found, req))) { |
578 return found; |
585 return found; |
579 } else { |
586 } else { |
580 if (found.isNumeric() && req.isNumeric()) { |
587 if (found.isNumeric() && req.isNumeric()) { |
581 checkContext.report(pos, diags.fragment("possible.loss.of.precision", found, req)); |
588 checkContext.report(pos, diags.fragment(Fragments.PossibleLossOfPrecision(found, req))); |
582 return types.createErrorType(found); |
589 return types.createErrorType(found); |
583 } |
590 } |
584 checkContext.report(pos, diags.fragment("inconvertible.types", found, req)); |
591 checkContext.report(pos, diags.fragment(Fragments.InconvertibleTypes(found, req))); |
585 return types.createErrorType(found); |
592 return types.createErrorType(found); |
586 } |
593 } |
587 } |
594 } |
588 |
595 |
589 /** Check that a given type can be cast to a given target type. |
596 /** Check that a given type can be cast to a given target type. |
660 * @param pos Position to be used for error reporting. |
667 * @param pos Position to be used for error reporting. |
661 * @param t The type to be checked. |
668 * @param t The type to be checked. |
662 */ |
669 */ |
663 Type checkNonVoid(DiagnosticPosition pos, Type t) { |
670 Type checkNonVoid(DiagnosticPosition pos, Type t) { |
664 if (t.hasTag(VOID)) { |
671 if (t.hasTag(VOID)) { |
665 log.error(pos, "void.not.allowed.here"); |
672 log.error(pos, Errors.VoidNotAllowedHere); |
666 return types.createErrorType(t); |
673 return types.createErrorType(t); |
667 } else { |
674 } else { |
668 return t; |
675 return t; |
669 } |
676 } |
670 } |
677 } |
671 |
678 |
672 Type checkClassOrArrayType(DiagnosticPosition pos, Type t) { |
679 Type checkClassOrArrayType(DiagnosticPosition pos, Type t) { |
673 if (!t.hasTag(CLASS) && !t.hasTag(ARRAY) && !t.hasTag(ERROR)) { |
680 if (!t.hasTag(CLASS) && !t.hasTag(ARRAY) && !t.hasTag(ERROR)) { |
674 return typeTagError(pos, |
681 return typeTagError(pos, |
675 diags.fragment("type.req.class.array"), |
682 diags.fragment(Fragments.TypeReqClassArray), |
676 asTypeParam(t)); |
683 asTypeParam(t)); |
677 } else { |
684 } else { |
678 return t; |
685 return t; |
679 } |
686 } |
680 } |
687 } |
684 * @param t The type to be checked. |
691 * @param t The type to be checked. |
685 */ |
692 */ |
686 Type checkClassType(DiagnosticPosition pos, Type t) { |
693 Type checkClassType(DiagnosticPosition pos, Type t) { |
687 if (!t.hasTag(CLASS) && !t.hasTag(ERROR)) { |
694 if (!t.hasTag(CLASS) && !t.hasTag(ERROR)) { |
688 return typeTagError(pos, |
695 return typeTagError(pos, |
689 diags.fragment("type.req.class"), |
696 diags.fragment(Fragments.TypeReqClass), |
690 asTypeParam(t)); |
697 asTypeParam(t)); |
691 } else { |
698 } else { |
692 return t; |
699 return t; |
693 } |
700 } |
694 } |
701 } |
695 //where |
702 //where |
696 private Object asTypeParam(Type t) { |
703 private Object asTypeParam(Type t) { |
697 return (t.hasTag(TYPEVAR)) |
704 return (t.hasTag(TYPEVAR)) |
698 ? diags.fragment("type.parameter", t) |
705 ? diags.fragment(Fragments.TypeParameter(t)) |
699 : t; |
706 : t; |
700 } |
707 } |
701 |
708 |
702 /** Check that type is a valid qualifier for a constructor reference expression |
709 /** Check that type is a valid qualifier for a constructor reference expression |
703 */ |
710 */ |
704 Type checkConstructorRefType(DiagnosticPosition pos, Type t) { |
711 Type checkConstructorRefType(DiagnosticPosition pos, Type t) { |
705 t = checkClassOrArrayType(pos, t); |
712 t = checkClassOrArrayType(pos, t); |
706 if (t.hasTag(CLASS)) { |
713 if (t.hasTag(CLASS)) { |
707 if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { |
714 if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { |
708 log.error(pos, "abstract.cant.be.instantiated", t.tsym); |
715 log.error(pos, Errors.AbstractCantBeInstantiated(t.tsym)); |
709 t = types.createErrorType(t); |
716 t = types.createErrorType(t); |
710 } else if ((t.tsym.flags() & ENUM) != 0) { |
717 } else if ((t.tsym.flags() & ENUM) != 0) { |
711 log.error(pos, "enum.cant.be.instantiated"); |
718 log.error(pos, Errors.EnumCantBeInstantiated); |
712 t = types.createErrorType(t); |
719 t = types.createErrorType(t); |
713 } else { |
720 } else { |
714 t = checkClassType(pos, t, true); |
721 t = checkClassType(pos, t, true); |
715 } |
722 } |
716 } else if (t.hasTag(ARRAY)) { |
723 } else if (t.hasTag(ARRAY)) { |
717 if (!types.isReifiable(((ArrayType)t).elemtype)) { |
724 if (!types.isReifiable(((ArrayType)t).elemtype)) { |
718 log.error(pos, "generic.array.creation"); |
725 log.error(pos, Errors.GenericArrayCreation); |
719 t = types.createErrorType(t); |
726 t = types.createErrorType(t); |
720 } |
727 } |
721 } |
728 } |
722 return t; |
729 return t; |
723 } |
730 } |
813 log.error(DiagnosticFlag.SOURCE_LEVEL, tree.clazz.pos(), |
819 log.error(DiagnosticFlag.SOURCE_LEVEL, tree.clazz.pos(), |
814 Errors.CantApplyDiamond1(t, Fragments.DiamondAndAnonClassNotSupportedInSource(source.name))); |
820 Errors.CantApplyDiamond1(t, Fragments.DiamondAndAnonClassNotSupportedInSource(source.name))); |
815 } |
821 } |
816 if (t.tsym.type.getTypeArguments().isEmpty()) { |
822 if (t.tsym.type.getTypeArguments().isEmpty()) { |
817 log.error(tree.clazz.pos(), |
823 log.error(tree.clazz.pos(), |
818 "cant.apply.diamond.1", |
824 Errors.CantApplyDiamond1(t, |
819 t, diags.fragment("diamond.non.generic", t)); |
825 Fragments.DiamondNonGeneric(t))); |
820 return types.createErrorType(t); |
826 return types.createErrorType(t); |
821 } else if (tree.typeargs != null && |
827 } else if (tree.typeargs != null && |
822 tree.typeargs.nonEmpty()) { |
828 tree.typeargs.nonEmpty()) { |
823 log.error(tree.clazz.pos(), |
829 log.error(tree.clazz.pos(), |
824 "cant.apply.diamond.1", |
830 Errors.CantApplyDiamond1(t, |
825 t, diags.fragment("diamond.and.explicit.params", t)); |
831 Fragments.DiamondAndExplicitParams(t))); |
826 return types.createErrorType(t); |
832 return types.createErrorType(t); |
827 } else { |
833 } else { |
828 return t; |
834 return t; |
829 } |
835 } |
830 } |
836 } |
903 if (m.isVarArgs()) { |
909 if (m.isVarArgs()) { |
904 varargElemType = types.elemtype(tree.params.last().type); |
910 varargElemType = types.elemtype(tree.params.last().type); |
905 } |
911 } |
906 if (hasTrustMeAnno && !isTrustMeAllowedOnMethod(m)) { |
912 if (hasTrustMeAnno && !isTrustMeAllowedOnMethod(m)) { |
907 if (varargElemType != null) { |
913 if (varargElemType != null) { |
|
914 JCDiagnostic msg = allowPrivateSafeVarargs ? |
|
915 diags.fragment(Fragments.VarargsTrustmeOnVirtualVarargs(m)) : |
|
916 diags.fragment(Fragments.VarargsTrustmeOnVirtualVarargsFinalOnly(m)); |
908 log.error(tree, |
917 log.error(tree, |
909 "varargs.invalid.trustme.anno", |
918 Errors.VarargsInvalidTrustmeAnno(syms.trustMeType.tsym, |
910 syms.trustMeType.tsym, |
919 msg)); |
911 allowPrivateSafeVarargs ? |
|
912 diags.fragment("varargs.trustme.on.virtual.varargs", m) : |
|
913 diags.fragment("varargs.trustme.on.virtual.varargs.final.only", m)); |
|
914 } else { |
920 } else { |
915 log.error(tree, |
921 log.error(tree, |
916 "varargs.invalid.trustme.anno", |
922 Errors.VarargsInvalidTrustmeAnno(syms.trustMeType.tsym, |
917 syms.trustMeType.tsym, |
923 Fragments.VarargsTrustmeOnNonVarargsMeth(m))); |
918 diags.fragment("varargs.trustme.on.non.varargs.meth", m)); |
|
919 } |
924 } |
920 } else if (hasTrustMeAnno && varargElemType != null && |
925 } else if (hasTrustMeAnno && varargElemType != null && |
921 types.isReifiable(varargElemType)) { |
926 types.isReifiable(varargElemType)) { |
922 warnUnsafeVararg(tree, |
927 warnUnsafeVararg(tree, |
923 "varargs.redundant.trustme.anno", |
928 "varargs.redundant.trustme.anno", |
924 syms.trustMeType.tsym, |
929 syms.trustMeType.tsym, |
925 diags.fragment("varargs.trustme.on.reifiable.varargs", varargElemType)); |
930 diags.fragment(Fragments.VarargsTrustmeOnReifiableVarargs(varargElemType))); |
926 } |
931 } |
927 else if (!hasTrustMeAnno && varargElemType != null && |
932 else if (!hasTrustMeAnno && varargElemType != null && |
928 !types.isReifiable(varargElemType)) { |
933 !types.isReifiable(varargElemType)) { |
929 warnUnchecked(tree.params.head.pos(), "unchecked.varargs.non.reifiable.type", varargElemType); |
934 warnUnchecked(tree.params.head.pos(), "unchecked.varargs.non.reifiable.type", varargElemType); |
930 } |
935 } |
984 // non-varargs call to varargs method |
989 // non-varargs call to varargs method |
985 Type varParam = owntype.getParameterTypes().last(); |
990 Type varParam = owntype.getParameterTypes().last(); |
986 Type lastArg = argtypes.last(); |
991 Type lastArg = argtypes.last(); |
987 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) && |
992 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) && |
988 !types.isSameType(types.erasure(varParam), types.erasure(lastArg))) |
993 !types.isSameType(types.erasure(varParam), types.erasure(lastArg))) |
989 log.warning(argtrees.last().pos(), "inexact.non-varargs.call", |
994 log.warning(argtrees.last().pos(), |
990 types.elemtype(varParam), varParam); |
995 Warnings.InexactNonVarargsCall(types.elemtype(varParam),varParam)); |
991 } |
996 } |
992 } |
997 } |
993 if (useVarargs) { |
998 if (useVarargs) { |
994 Type argtype = owntype.getParameterTypes().last(); |
999 Type argtype = owntype.getParameterTypes().last(); |
995 if (!types.isReifiable(argtype) && |
1000 if (!types.isReifiable(argtype) && |
1170 case TYP: |
1175 case TYP: |
1171 if (sym.isLocal()) { |
1176 if (sym.isLocal()) { |
1172 mask = LocalClassFlags; |
1177 mask = LocalClassFlags; |
1173 if ((sym.owner.flags_field & STATIC) == 0 && |
1178 if ((sym.owner.flags_field & STATIC) == 0 && |
1174 (flags & ENUM) != 0) |
1179 (flags & ENUM) != 0) |
1175 log.error(pos, "enums.must.be.static"); |
1180 log.error(pos, Errors.EnumsMustBeStatic); |
1176 } else if (sym.owner.kind == TYP) { |
1181 } else if (sym.owner.kind == TYP) { |
1177 mask = MemberClassFlags; |
1182 mask = MemberClassFlags; |
1178 if (sym.owner.owner.kind == PCK || |
1183 if (sym.owner.owner.kind == PCK || |
1179 (sym.owner.flags_field & STATIC) != 0) |
1184 (sym.owner.flags_field & STATIC) != 0) |
1180 mask |= STATIC; |
1185 mask |= STATIC; |
1181 else if ((flags & ENUM) != 0) |
1186 else if ((flags & ENUM) != 0) |
1182 log.error(pos, "enums.must.be.static"); |
1187 log.error(pos, Errors.EnumsMustBeStatic); |
1183 // Nested interfaces and enums are always STATIC (Spec ???) |
1188 // Nested interfaces and enums are always STATIC (Spec ???) |
1184 if ((flags & (INTERFACE | ENUM)) != 0 ) implicit = STATIC; |
1189 if ((flags & (INTERFACE | ENUM)) != 0 ) implicit = STATIC; |
1185 } else { |
1190 } else { |
1186 mask = ClassFlags; |
1191 mask = ClassFlags; |
1187 } |
1192 } |
1393 visitSelectInternal(tree); |
1398 visitSelectInternal(tree); |
1394 |
1399 |
1395 // Check that this type is either fully parameterized, or |
1400 // Check that this type is either fully parameterized, or |
1396 // not parameterized at all. |
1401 // not parameterized at all. |
1397 if (tree.selected.type.isParameterized() && tree.type.tsym.type.getTypeArguments().nonEmpty()) |
1402 if (tree.selected.type.isParameterized() && tree.type.tsym.type.getTypeArguments().nonEmpty()) |
1398 log.error(tree.pos(), "improperly.formed.type.param.missing"); |
1403 log.error(tree.pos(), Errors.ImproperlyFormedTypeParamMissing); |
1399 } |
1404 } |
1400 } |
1405 } |
1401 |
1406 |
1402 public void visitSelectInternal(JCFieldAccess tree) { |
1407 public void visitSelectInternal(JCFieldAccess tree) { |
1403 if (tree.type.tsym.isStatic() && |
1408 if (tree.type.tsym.isStatic() && |
1404 tree.selected.type.isParameterized()) { |
1409 tree.selected.type.isParameterized()) { |
1405 // The enclosing type is not a class, so we are |
1410 // The enclosing type is not a class, so we are |
1406 // looking at a static member type. However, the |
1411 // looking at a static member type. However, the |
1407 // qualifying expression is parameterized. |
1412 // qualifying expression is parameterized. |
1408 log.error(tree.pos(), "cant.select.static.class.from.param.type"); |
1413 log.error(tree.pos(), Errors.CantSelectStaticClassFromParamType); |
1409 } else { |
1414 } else { |
1410 // otherwise validate the rest of the expression |
1415 // otherwise validate the rest of the expression |
1411 tree.selected.accept(this); |
1416 tree.selected.accept(this); |
1412 } |
1417 } |
1413 } |
1418 } |
1611 /** A customized "cannot override" error message. |
1616 /** A customized "cannot override" error message. |
1612 * @param m The overriding method. |
1617 * @param m The overriding method. |
1613 * @param other The overridden method. |
1618 * @param other The overridden method. |
1614 * @return An internationalized string. |
1619 * @return An internationalized string. |
1615 */ |
1620 */ |
1616 Object cannotOverride(MethodSymbol m, MethodSymbol other) { |
1621 Fragment cannotOverride(MethodSymbol m, MethodSymbol other) { |
1617 String key; |
1622 Symbol mloc = m.location(); |
|
1623 Symbol oloc = other.location(); |
|
1624 |
1618 if ((other.owner.flags() & INTERFACE) == 0) |
1625 if ((other.owner.flags() & INTERFACE) == 0) |
1619 key = "cant.override"; |
1626 return Fragments.CantOverride(m, mloc, other, oloc); |
1620 else if ((m.owner.flags() & INTERFACE) == 0) |
1627 else if ((m.owner.flags() & INTERFACE) == 0) |
1621 key = "cant.implement"; |
1628 return Fragments.CantImplement(m, mloc, other, oloc); |
1622 else |
1629 else |
1623 key = "clashes.with"; |
1630 return Fragments.ClashesWith(m, mloc, other, oloc); |
1624 return diags.fragment(key, m, m.location(), other, other.location()); |
|
1625 } |
1631 } |
1626 |
1632 |
1627 /** A customized "override" warning message. |
1633 /** A customized "override" warning message. |
1628 * @param m The overriding method. |
1634 * @param m The overriding method. |
1629 * @param other The overridden method. |
1635 * @param other The overridden method. |
1630 * @return An internationalized string. |
1636 * @return An internationalized string. |
1631 */ |
1637 */ |
1632 Object uncheckedOverrides(MethodSymbol m, MethodSymbol other) { |
1638 Fragment uncheckedOverrides(MethodSymbol m, MethodSymbol other) { |
1633 String key; |
1639 Symbol mloc = m.location(); |
|
1640 Symbol oloc = other.location(); |
|
1641 |
1634 if ((other.owner.flags() & INTERFACE) == 0) |
1642 if ((other.owner.flags() & INTERFACE) == 0) |
1635 key = "unchecked.override"; |
1643 return Fragments.UncheckedOverride(m, mloc, other, oloc); |
1636 else if ((m.owner.flags() & INTERFACE) == 0) |
1644 else if ((m.owner.flags() & INTERFACE) == 0) |
1637 key = "unchecked.implement"; |
1645 return Fragments.UncheckedImplement(m, mloc, other, oloc); |
1638 else |
1646 else |
1639 key = "unchecked.clash.with"; |
1647 return Fragments.UncheckedClashWith(m, mloc, other, oloc); |
1640 return diags.fragment(key, m, m.location(), other, other.location()); |
|
1641 } |
1648 } |
1642 |
1649 |
1643 /** A customized "override" warning message. |
1650 /** A customized "override" warning message. |
1644 * @param m The overriding method. |
1651 * @param m The overriding method. |
1645 * @param other The overridden method. |
1652 * @param other The overridden method. |
1646 * @return An internationalized string. |
1653 * @return An internationalized string. |
1647 */ |
1654 */ |
1648 Object varargsOverrides(MethodSymbol m, MethodSymbol other) { |
1655 Fragment varargsOverrides(MethodSymbol m, MethodSymbol other) { |
1649 String key; |
1656 Symbol mloc = m.location(); |
|
1657 Symbol oloc = other.location(); |
|
1658 |
1650 if ((other.owner.flags() & INTERFACE) == 0) |
1659 if ((other.owner.flags() & INTERFACE) == 0) |
1651 key = "varargs.override"; |
1660 return Fragments.VarargsOverride(m, mloc, other, oloc); |
1652 else if ((m.owner.flags() & INTERFACE) == 0) |
1661 else if ((m.owner.flags() & INTERFACE) == 0) |
1653 key = "varargs.implement"; |
1662 return Fragments.VarargsImplement(m, mloc, other, oloc); |
1654 else |
1663 else |
1655 key = "varargs.clash.with"; |
1664 return Fragments.VarargsClashWith(m, mloc, other, oloc); |
1656 return diags.fragment(key, m, m.location(), other, other.location()); |
|
1657 } |
1665 } |
1658 |
1666 |
1659 /** Check that this method conforms with overridden method 'other'. |
1667 /** Check that this method conforms with overridden method 'other'. |
1660 * where `origin' is the class where checking started. |
1668 * where `origin' is the class where checking started. |
1661 * Complications: |
1669 * Complications: |
1687 } |
1695 } |
1688 |
1696 |
1689 // Error if static method overrides instance method (JLS 8.4.6.2). |
1697 // Error if static method overrides instance method (JLS 8.4.6.2). |
1690 if ((m.flags() & STATIC) != 0 && |
1698 if ((m.flags() & STATIC) != 0 && |
1691 (other.flags() & STATIC) == 0) { |
1699 (other.flags() & STATIC) == 0) { |
1692 log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.static", |
1700 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1693 cannotOverride(m, other)); |
1701 Errors.OverrideStatic(cannotOverride(m, other))); |
1694 m.flags_field |= BAD_OVERRIDE; |
1702 m.flags_field |= BAD_OVERRIDE; |
1695 return; |
1703 return; |
1696 } |
1704 } |
1697 |
1705 |
1698 // Error if instance method overrides static or final |
1706 // Error if instance method overrides static or final |
1699 // method (JLS 8.4.6.1). |
1707 // method (JLS 8.4.6.1). |
1700 if ((other.flags() & FINAL) != 0 || |
1708 if ((other.flags() & FINAL) != 0 || |
1701 (m.flags() & STATIC) == 0 && |
1709 (m.flags() & STATIC) == 0 && |
1702 (other.flags() & STATIC) != 0) { |
1710 (other.flags() & STATIC) != 0) { |
1703 log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.meth", |
1711 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1704 cannotOverride(m, other), |
1712 Errors.OverrideMeth(cannotOverride(m, other), |
1705 asFlagSet(other.flags() & (FINAL | STATIC))); |
1713 asFlagSet(other.flags() & (FINAL | STATIC)))); |
1706 m.flags_field |= BAD_OVERRIDE; |
1714 m.flags_field |= BAD_OVERRIDE; |
1707 return; |
1715 return; |
1708 } |
1716 } |
1709 |
1717 |
1710 if ((m.owner.flags() & ANNOTATION) != 0) { |
1718 if ((m.owner.flags() & ANNOTATION) != 0) { |
1712 return; |
1720 return; |
1713 } |
1721 } |
1714 |
1722 |
1715 // Error if overriding method has weaker access (JLS 8.4.6.3). |
1723 // Error if overriding method has weaker access (JLS 8.4.6.3). |
1716 if (protection(m.flags()) > protection(other.flags())) { |
1724 if (protection(m.flags()) > protection(other.flags())) { |
1717 log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.weaker.access", |
1725 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1718 cannotOverride(m, other), |
|
1719 (other.flags() & AccessFlags) == 0 ? |
1726 (other.flags() & AccessFlags) == 0 ? |
1720 "package" : |
1727 Errors.OverrideWeakerAccess(cannotOverride(m, other), |
1721 asFlagSet(other.flags() & AccessFlags)); |
1728 "package") : |
|
1729 Errors.OverrideWeakerAccess(cannotOverride(m, other), |
|
1730 asFlagSet(other.flags() & AccessFlags))); |
1722 m.flags_field |= BAD_OVERRIDE; |
1731 m.flags_field |= BAD_OVERRIDE; |
1723 return; |
1732 return; |
1724 } |
1733 } |
1725 |
1734 |
1726 Type mt = types.memberType(origin.type, m); |
1735 Type mt = types.memberType(origin.type, m); |
1738 boolean resultTypesOK = |
1747 boolean resultTypesOK = |
1739 types.returnTypeSubstitutable(mt, ot, otres, overrideWarner); |
1748 types.returnTypeSubstitutable(mt, ot, otres, overrideWarner); |
1740 if (!resultTypesOK) { |
1749 if (!resultTypesOK) { |
1741 if ((m.flags() & STATIC) != 0 && (other.flags() & STATIC) != 0) { |
1750 if ((m.flags() & STATIC) != 0 && (other.flags() & STATIC) != 0) { |
1742 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1751 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1743 Errors.OverrideIncompatibleRet(Fragments.CantHide(m, m.location(), other, |
1752 Errors.OverrideIncompatibleRet(Fragments.CantHide(m, m.location(), other, |
1744 other.location()), mtres, otres)); |
1753 other.location()), mtres, otres)); |
1745 m.flags_field |= BAD_OVERRIDE; |
1754 m.flags_field |= BAD_OVERRIDE; |
1746 } else { |
1755 } else { |
1747 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1756 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1748 "override.incompatible.ret", |
1757 Errors.OverrideIncompatibleRet(cannotOverride(m, other), mtres, otres)); |
1749 cannotOverride(m, other), |
|
1750 mtres, otres); |
|
1751 m.flags_field |= BAD_OVERRIDE; |
1758 m.flags_field |= BAD_OVERRIDE; |
1752 } |
1759 } |
1753 return; |
1760 return; |
1754 } else if (overrideWarner.hasNonSilentLint(LintCategory.UNCHECKED)) { |
1761 } else if (overrideWarner.hasNonSilentLint(LintCategory.UNCHECKED)) { |
1755 warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), |
1762 warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), |
1763 List<Type> otthrown = types.subst(ot.getThrownTypes(), otvars, mtvars); |
1770 List<Type> otthrown = types.subst(ot.getThrownTypes(), otvars, mtvars); |
1764 List<Type> unhandledErased = unhandled(mt.getThrownTypes(), types.erasure(otthrown)); |
1771 List<Type> unhandledErased = unhandled(mt.getThrownTypes(), types.erasure(otthrown)); |
1765 List<Type> unhandledUnerased = unhandled(mt.getThrownTypes(), otthrown); |
1772 List<Type> unhandledUnerased = unhandled(mt.getThrownTypes(), otthrown); |
1766 if (unhandledErased.nonEmpty()) { |
1773 if (unhandledErased.nonEmpty()) { |
1767 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1774 log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1768 "override.meth.doesnt.throw", |
1775 Errors.OverrideMethDoesntThrow(cannotOverride(m, other), unhandledUnerased.head)); |
1769 cannotOverride(m, other), |
|
1770 unhandledUnerased.head); |
|
1771 m.flags_field |= BAD_OVERRIDE; |
1776 m.flags_field |= BAD_OVERRIDE; |
1772 return; |
1777 return; |
1773 } |
1778 } |
1774 else if (unhandledUnerased.nonEmpty()) { |
1779 else if (unhandledUnerased.nonEmpty()) { |
1775 warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), |
1780 warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), |
1782 // Optional warning if varargs don't agree |
1787 // Optional warning if varargs don't agree |
1783 if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0) |
1788 if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0) |
1784 && lint.isEnabled(LintCategory.OVERRIDES)) { |
1789 && lint.isEnabled(LintCategory.OVERRIDES)) { |
1785 log.warning(TreeInfo.diagnosticPositionFor(m, tree), |
1790 log.warning(TreeInfo.diagnosticPositionFor(m, tree), |
1786 ((m.flags() & Flags.VARARGS) != 0) |
1791 ((m.flags() & Flags.VARARGS) != 0) |
1787 ? "override.varargs.missing" |
1792 ? Warnings.OverrideVarargsMissing(varargsOverrides(m, other)) |
1788 : "override.varargs.extra", |
1793 : Warnings.OverrideVarargsExtra(varargsOverrides(m, other))); |
1789 varargsOverrides(m, other)); |
|
1790 } |
1794 } |
1791 |
1795 |
1792 // Warn if instance method overrides bridge method (compiler spec ??) |
1796 // Warn if instance method overrides bridge method (compiler spec ??) |
1793 if ((other.flags() & BRIDGE) != 0) { |
1797 if ((other.flags() & BRIDGE) != 0) { |
1794 log.warning(TreeInfo.diagnosticPositionFor(m, tree), "override.bridge", |
1798 log.warning(TreeInfo.diagnosticPositionFor(m, tree), |
1795 uncheckedOverrides(m, other)); |
1799 Warnings.OverrideBridge(uncheckedOverrides(m, other))); |
1796 } |
1800 } |
1797 |
1801 |
1798 // Warn if a deprecated method overridden by a non-deprecated one. |
1802 // Warn if a deprecated method overridden by a non-deprecated one. |
1799 if (!isDeprecatedOverrideIgnorable(other, origin)) { |
1803 if (!isDeprecatedOverrideIgnorable(other, origin)) { |
1800 Lint prevLint = setLint(lint.augment(m)); |
1804 Lint prevLint = setLint(lint.augment(m)); |
1969 !rt2.isPrimitiveOrVoid() && |
1973 !rt2.isPrimitiveOrVoid() && |
1970 (types.covariantReturnType(rt1, rt2, types.noWarnings) || |
1974 (types.covariantReturnType(rt1, rt2, types.noWarnings) || |
1971 types.covariantReturnType(rt2, rt1, types.noWarnings)) || |
1975 types.covariantReturnType(rt2, rt1, types.noWarnings)) || |
1972 checkCommonOverriderIn(s1,s2,site); |
1976 checkCommonOverriderIn(s1,s2,site); |
1973 if (!compat) { |
1977 if (!compat) { |
1974 log.error(pos, "types.incompatible.diff.ret", |
1978 log.error(pos, Errors.TypesIncompatibleDiffRet(t1, t2, s2.name + |
1975 t1, t2, s2.name + |
1979 "(" + types.memberType(t2, s2).getParameterTypes() + ")")); |
1976 "(" + types.memberType(t2, s2).getParameterTypes() + ")"); |
|
1977 return s2; |
1980 return s2; |
1978 } |
1981 } |
1979 } else if (checkNameClash((ClassSymbol)site.tsym, s1, s2) && |
1982 } else if (checkNameClash((ClassSymbol)site.tsym, s1, s2) && |
1980 !checkCommonOverriderIn(s1, s2, site)) { |
1983 !checkCommonOverriderIn(s1, s2, site)) { |
1981 log.error(pos, Errors.NameClashSameErasureNoOverride( |
1984 log.error(pos, Errors.NameClashSameErasureNoOverride( |
2152 MethodSymbol undef = types.firstUnimplementedAbstract(c); |
2155 MethodSymbol undef = types.firstUnimplementedAbstract(c); |
2153 if (undef != null) { |
2156 if (undef != null) { |
2154 MethodSymbol undef1 = |
2157 MethodSymbol undef1 = |
2155 new MethodSymbol(undef.flags(), undef.name, |
2158 new MethodSymbol(undef.flags(), undef.name, |
2156 types.memberType(c.type, undef), undef.owner); |
2159 types.memberType(c.type, undef), undef.owner); |
2157 log.error(pos, "does.not.override.abstract", |
2160 log.error(pos, |
2158 c, undef1, undef1.location()); |
2161 Errors.DoesNotOverrideAbstract(c, undef1, undef1.location())); |
2159 } |
2162 } |
2160 } |
2163 } |
2161 |
2164 |
2162 void checkNonCyclicDecl(JCClassDecl tree) { |
2165 void checkNonCyclicDecl(JCClassDecl tree) { |
2163 CycleChecker cc = new CycleChecker(); |
2166 CycleChecker cc = new CycleChecker(); |
2507 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as |
2510 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as |
2508 //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error |
2511 //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error |
2509 if (!types.isSubSignature(sym.type, types.memberType(site, s), allowStrictMethodClashCheck)) { |
2512 if (!types.isSubSignature(sym.type, types.memberType(site, s), allowStrictMethodClashCheck)) { |
2510 if (types.hasSameArgs(s.erasure(types), sym.erasure(types))) { |
2513 if (types.hasSameArgs(s.erasure(types), sym.erasure(types))) { |
2511 log.error(pos, |
2514 log.error(pos, |
2512 "name.clash.same.erasure.no.hide", |
2515 Errors.NameClashSameErasureNoHide(sym, sym.location(), s, s.location())); |
2513 sym, sym.location(), |
|
2514 s, s.location()); |
|
2515 return; |
2516 return; |
2516 } else { |
2517 } else { |
2517 checkPotentiallyAmbiguousOverloads(pos, site, sym, (MethodSymbol)s); |
2518 checkPotentiallyAmbiguousOverloads(pos, site, sym, (MethodSymbol)s); |
2518 } |
2519 } |
2519 } |
2520 } |
2741 Type oldit = seensofar.put(it.tsym, it); |
2742 Type oldit = seensofar.put(it.tsym, it); |
2742 if (oldit != null) { |
2743 if (oldit != null) { |
2743 List<Type> oldparams = oldit.allparams(); |
2744 List<Type> oldparams = oldit.allparams(); |
2744 List<Type> newparams = it.allparams(); |
2745 List<Type> newparams = it.allparams(); |
2745 if (!types.containsTypeEquivalent(oldparams, newparams)) |
2746 if (!types.containsTypeEquivalent(oldparams, newparams)) |
2746 log.error(pos, "cant.inherit.diff.arg", |
2747 log.error(pos, |
2747 it.tsym, Type.toString(oldparams), |
2748 Errors.CantInheritDiffArg(it.tsym, |
2748 Type.toString(newparams)); |
2749 Type.toString(oldparams), |
|
2750 Type.toString(newparams))); |
2749 } |
2751 } |
2750 checkClassBounds(pos, seensofar, it); |
2752 checkClassBounds(pos, seensofar, it); |
2751 } |
2753 } |
2752 Type st = types.supertype(type); |
2754 Type st = types.supertype(type); |
2753 if (st != Type.noType) checkClassBounds(pos, seensofar, st); |
2755 if (st != Type.noType) checkClassBounds(pos, seensofar, st); |
2849 */ |
2851 */ |
2850 private void validateAnnotation(JCAnnotation a, Symbol s) { |
2852 private void validateAnnotation(JCAnnotation a, Symbol s) { |
2851 validateAnnotationTree(a); |
2853 validateAnnotationTree(a); |
2852 |
2854 |
2853 if (a.type.tsym.isAnnotationType() && !annotationApplicable(a, s)) |
2855 if (a.type.tsym.isAnnotationType() && !annotationApplicable(a, s)) |
2854 log.error(a.pos(), "annotation.type.not.applicable"); |
2856 log.error(a.pos(), Errors.AnnotationTypeNotApplicable); |
2855 |
2857 |
2856 if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { |
2858 if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { |
2857 if (s.kind != TYP) { |
2859 if (s.kind != TYP) { |
2858 log.error(a.pos(), "bad.functional.intf.anno"); |
2860 log.error(a.pos(), Errors.BadFunctionalIntfAnno); |
2859 } else if (!s.isInterface() || (s.flags() & ANNOTATION) != 0) { |
2861 } else if (!s.isInterface() || (s.flags() & ANNOTATION) != 0) { |
2860 log.error(a.pos(), "bad.functional.intf.anno.1", diags.fragment("not.a.functional.intf", s)); |
2862 log.error(a.pos(), Errors.BadFunctionalIntfAnno1(Fragments.NotAFunctionalIntf(s))); |
2861 } |
2863 } |
2862 } |
2864 } |
2863 } |
2865 } |
2864 |
2866 |
2865 public void validateTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { |
2867 public void validateTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { |
2909 Symbol sym = container.members().findFirst(names.value); |
2911 Symbol sym = container.members().findFirst(names.value); |
2910 if (sym != null && sym.kind == MTH) { |
2912 if (sym != null && sym.kind == MTH) { |
2911 MethodSymbol m = (MethodSymbol) sym; |
2913 MethodSymbol m = (MethodSymbol) sym; |
2912 Type ret = m.getReturnType(); |
2914 Type ret = m.getReturnType(); |
2913 if (!(ret.hasTag(ARRAY) && types.isSameType(((ArrayType)ret).elemtype, contained.type))) { |
2915 if (!(ret.hasTag(ARRAY) && types.isSameType(((ArrayType)ret).elemtype, contained.type))) { |
2914 log.error(pos, "invalid.repeatable.annotation.value.return", |
2916 log.error(pos, |
2915 container, ret, types.makeArrayType(contained.type)); |
2917 Errors.InvalidRepeatableAnnotationValueReturn(container, |
|
2918 ret, |
|
2919 types.makeArrayType(contained.type))); |
2916 } |
2920 } |
2917 } else { |
2921 } else { |
2918 log.error(pos, "invalid.repeatable.annotation.no.value", container); |
2922 log.error(pos, Errors.InvalidRepeatableAnnotationNoValue(container)); |
2919 } |
2923 } |
2920 } |
2924 } |
2921 |
2925 |
2922 private void validateRetention(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) { |
2926 private void validateRetention(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) { |
2923 Attribute.RetentionPolicy containerRetention = types.getRetention(container); |
2927 Attribute.RetentionPolicy containerRetention = types.getRetention(container); |
2934 if (containerRetention == Attribute.RetentionPolicy.SOURCE) { |
2938 if (containerRetention == Attribute.RetentionPolicy.SOURCE) { |
2935 error = true; |
2939 error = true; |
2936 } |
2940 } |
2937 } |
2941 } |
2938 if (error ) { |
2942 if (error ) { |
2939 log.error(pos, "invalid.repeatable.annotation.retention", |
2943 log.error(pos, |
2940 container, containerRetention, |
2944 Errors.InvalidRepeatableAnnotationRetention(container, |
2941 contained, containedRetention); |
2945 containerRetention.name(), |
|
2946 contained, |
|
2947 containedRetention.name())); |
2942 } |
2948 } |
2943 } |
2949 } |
2944 |
2950 |
2945 private void validateDocumented(Symbol container, Symbol contained, DiagnosticPosition pos) { |
2951 private void validateDocumented(Symbol container, Symbol contained, DiagnosticPosition pos) { |
2946 if (contained.attribute(syms.documentedType.tsym) != null) { |
2952 if (contained.attribute(syms.documentedType.tsym) != null) { |
2947 if (container.attribute(syms.documentedType.tsym) == null) { |
2953 if (container.attribute(syms.documentedType.tsym) == null) { |
2948 log.error(pos, "invalid.repeatable.annotation.not.documented", container, contained); |
2954 log.error(pos, Errors.InvalidRepeatableAnnotationNotDocumented(container, contained)); |
2949 } |
2955 } |
2950 } |
2956 } |
2951 } |
2957 } |
2952 |
2958 |
2953 private void validateInherited(Symbol container, Symbol contained, DiagnosticPosition pos) { |
2959 private void validateInherited(Symbol container, Symbol contained, DiagnosticPosition pos) { |
2954 if (contained.attribute(syms.inheritedType.tsym) != null) { |
2960 if (contained.attribute(syms.inheritedType.tsym) != null) { |
2955 if (container.attribute(syms.inheritedType.tsym) == null) { |
2961 if (container.attribute(syms.inheritedType.tsym) == null) { |
2956 log.error(pos, "invalid.repeatable.annotation.not.inherited", container, contained); |
2962 log.error(pos, Errors.InvalidRepeatableAnnotationNotInherited(container, contained)); |
2957 } |
2963 } |
2958 } |
2964 } |
2959 } |
2965 } |
2960 |
2966 |
2961 private void validateTarget(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) { |
2967 private void validateTarget(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) { |
3266 if (lint.isEnabled(LintCategory.DEP_ANN) && s.isDeprecatableViaAnnotation() && |
3270 if (lint.isEnabled(LintCategory.DEP_ANN) && s.isDeprecatableViaAnnotation() && |
3267 (s.flags() & DEPRECATED) != 0 && |
3271 (s.flags() & DEPRECATED) != 0 && |
3268 !syms.deprecatedType.isErroneous() && |
3272 !syms.deprecatedType.isErroneous() && |
3269 s.attribute(syms.deprecatedType.tsym) == null) { |
3273 s.attribute(syms.deprecatedType.tsym) == null) { |
3270 log.warning(LintCategory.DEP_ANN, |
3274 log.warning(LintCategory.DEP_ANN, |
3271 pos, "missing.deprecated.annotation"); |
3275 pos, Warnings.MissingDeprecatedAnnotation); |
3272 } |
3276 } |
3273 // Note: @Deprecated has no effect on local variables, parameters and package decls. |
3277 // Note: @Deprecated has no effect on local variables, parameters and package decls. |
3274 if (lint.isEnabled(LintCategory.DEPRECATION) && !s.isDeprecatableViaAnnotation()) { |
3278 if (lint.isEnabled(LintCategory.DEPRECATION) && !s.isDeprecatableViaAnnotation()) { |
3275 if (!syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) != null) { |
3279 if (!syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) != null) { |
3276 log.warning(LintCategory.DEPRECATION, pos, |
3280 log.warning(LintCategory.DEPRECATION, pos, |
3277 "deprecated.annotation.has.no.effect", Kinds.kindName(s)); |
3281 Warnings.DeprecatedAnnotationHasNoEffect(Kinds.kindName(s))); |
3278 } |
3282 } |
3279 } |
3283 } |
3280 } |
3284 } |
3281 |
3285 |
3282 void checkDeprecated(final DiagnosticPosition pos, final Symbol other, final Symbol s) { |
3286 void checkDeprecated(final DiagnosticPosition pos, final Symbol other, final Symbol s) { |
3288 } |
3292 } |
3289 |
3293 |
3290 void checkSunAPI(final DiagnosticPosition pos, final Symbol s) { |
3294 void checkSunAPI(final DiagnosticPosition pos, final Symbol s) { |
3291 if ((s.flags() & PROPRIETARY) != 0) { |
3295 if ((s.flags() & PROPRIETARY) != 0) { |
3292 deferredLintHandler.report(() -> { |
3296 deferredLintHandler.report(() -> { |
3293 log.mandatoryWarning(pos, "sun.proprietary", s); |
3297 log.mandatoryWarning(pos, Warnings.SunProprietary(s)); |
3294 }); |
3298 }); |
3295 } |
3299 } |
3296 } |
3300 } |
3297 |
3301 |
3298 void checkProfile(final DiagnosticPosition pos, final Symbol s) { |
3302 void checkProfile(final DiagnosticPosition pos, final Symbol s) { |
3299 if (profile != Profile.DEFAULT && (s.flags() & NOT_IN_PROFILE) != 0) { |
3303 if (profile != Profile.DEFAULT && (s.flags() & NOT_IN_PROFILE) != 0) { |
3300 log.error(pos, "not.in.profile", s, profile); |
3304 log.error(pos, Errors.NotInProfile(s, profile)); |
3301 } |
3305 } |
3302 } |
3306 } |
3303 |
3307 |
3304 /* ************************************************************************* |
3308 /* ************************************************************************* |
3305 * Check for recursive annotation elements. |
3309 * Check for recursive annotation elements. |
3393 private void checkCyclicConstructor(JCClassDecl tree, Symbol ctor, |
3397 private void checkCyclicConstructor(JCClassDecl tree, Symbol ctor, |
3394 Map<Symbol,Symbol> callMap) { |
3398 Map<Symbol,Symbol> callMap) { |
3395 if (ctor != null && (ctor.flags_field & ACYCLIC) == 0) { |
3399 if (ctor != null && (ctor.flags_field & ACYCLIC) == 0) { |
3396 if ((ctor.flags_field & LOCKED) != 0) { |
3400 if ((ctor.flags_field & LOCKED) != 0) { |
3397 log.error(TreeInfo.diagnosticPositionFor(ctor, tree), |
3401 log.error(TreeInfo.diagnosticPositionFor(ctor, tree), |
3398 "recursive.ctor.invocation"); |
3402 Errors.RecursiveCtorInvocation); |
3399 } else { |
3403 } else { |
3400 ctor.flags_field |= LOCKED; |
3404 ctor.flags_field |= LOCKED; |
3401 checkCyclicConstructor(tree, callMap.remove(ctor), callMap); |
3405 checkCyclicConstructor(tree, callMap.remove(ctor), callMap); |
3402 ctor.flags_field &= ~LOCKED; |
3406 ctor.flags_field &= ~LOCKED; |
3403 } |
3407 } |
3529 if (clashing == null && !staticImport) { |
3533 if (clashing == null && !staticImport) { |
3530 clashing = staticallyImportedSoFar.findFirst(sym.name, duplicates); |
3534 clashing = staticallyImportedSoFar.findFirst(sym.name, duplicates); |
3531 } |
3535 } |
3532 if (clashing != null) { |
3536 if (clashing != null) { |
3533 if (staticImport) |
3537 if (staticImport) |
3534 log.error(pos, "already.defined.static.single.import", clashing); |
3538 log.error(pos, Errors.AlreadyDefinedStaticSingleImport(clashing)); |
3535 else |
3539 else |
3536 log.error(pos, "already.defined.single.import", clashing); |
3540 log.error(pos, Errors.AlreadyDefinedSingleImport(clashing)); |
3537 return false; |
3541 return false; |
3538 } |
3542 } |
3539 clashing = topLevelScope.findFirst(sym.name, duplicates); |
3543 clashing = topLevelScope.findFirst(sym.name, duplicates); |
3540 if (clashing != null) { |
3544 if (clashing != null) { |
3541 log.error(pos, "already.defined.this.unit", clashing); |
3545 log.error(pos, Errors.AlreadyDefinedThisUnit(clashing)); |
3542 return false; |
3546 return false; |
3543 } |
3547 } |
3544 return true; |
3548 return true; |
3545 } |
3549 } |
3546 |
3550 |
3547 /** Check that a qualified name is in canonical form (for import decls). |
3551 /** Check that a qualified name is in canonical form (for import decls). |
3548 */ |
3552 */ |
3549 public void checkCanonical(JCTree tree) { |
3553 public void checkCanonical(JCTree tree) { |
3550 if (!isCanonical(tree)) |
3554 if (!isCanonical(tree)) |
3551 log.error(tree.pos(), "import.requires.canonical", |
3555 log.error(tree.pos(), |
3552 TreeInfo.symbol(tree)); |
3556 Errors.ImportRequiresCanonical(TreeInfo.symbol(tree))); |
3553 } |
3557 } |
3554 // where |
3558 // where |
3555 private boolean isCanonical(JCTree tree) { |
3559 private boolean isCanonical(JCTree tree) { |
3556 while (tree.hasTag(SELECT)) { |
3560 while (tree.hasTag(SELECT)) { |
3557 JCFieldAccess s = (JCFieldAccess) tree; |
3561 JCFieldAccess s = (JCFieldAccess) tree; |
3645 if (select.name == names.asterisk || (origin = TreeInfo.symbol(select.selected)) == null || origin.kind != TYP) |
3649 if (select.name == names.asterisk || (origin = TreeInfo.symbol(select.selected)) == null || origin.kind != TYP) |
3646 continue; |
3650 continue; |
3647 |
3651 |
3648 TypeSymbol site = (TypeSymbol) TreeInfo.symbol(select.selected); |
3652 TypeSymbol site = (TypeSymbol) TreeInfo.symbol(select.selected); |
3649 if (!checkTypeContainsImportableElement(site, site, toplevel.packge, select.name, new HashSet<Symbol>())) { |
3653 if (!checkTypeContainsImportableElement(site, site, toplevel.packge, select.name, new HashSet<Symbol>())) { |
3650 log.error(imp.pos(), "cant.resolve.location", |
3654 log.error(imp.pos(), |
3651 KindName.STATIC, |
3655 Errors.CantResolveLocation(KindName.STATIC, |
3652 select.name, List.<Type>nil(), List.<Type>nil(), |
3656 select.name, |
3653 Kinds.typeKindName(TreeInfo.symbol(select.selected).type), |
3657 null, |
3654 TreeInfo.symbol(select.selected).type); |
3658 null, |
|
3659 Fragments.Location(kindName(site), |
|
3660 site, |
|
3661 null))); |
3655 } |
3662 } |
3656 } |
3663 } |
3657 } |
3664 } |
3658 |
3665 |
3659 // Check that packages imported are in scope (JLS 7.4.3, 6.3, 6.5.3.1, 6.5.3.2) |
3666 // Check that packages imported are in scope (JLS 7.4.3, 6.3, 6.5.3.1, 6.5.3.2) |