219 deprecationHandler.report(pos, Warnings.HasBeenDeprecatedModule(sym));
220 } else {
221 deprecationHandler.report(pos, Warnings.HasBeenDeprecated(sym, sym.location()));
222 }
223 }
224 }
225
226 /** Warn about unchecked operation.
227 * @param pos Position to be used for error reporting.
228 * @param msg A string describing the problem.
229 */
230 public void warnUnchecked(DiagnosticPosition pos, Warning warnKey) {
231 if (!lint.isSuppressed(LintCategory.UNCHECKED))
232 uncheckedHandler.report(pos, warnKey);
233 }
234
235 /** Warn about unsafe vararg method decl.
236 * @param pos Position to be used for error reporting.
237 */
238 void warnUnsafeVararg(DiagnosticPosition pos, Warning warnKey) {
239 if (lint.isEnabled(LintCategory.VARARGS) && Feature.SIMPLIFIED_VARARGS.allowedInSource(source))
240 log.warning(LintCategory.VARARGS, pos, warnKey);
241 }
242
243 public void warnStatic(DiagnosticPosition pos, Warning warnKey) {
244 if (lint.isEnabled(LintCategory.STATIC))
245 log.warning(LintCategory.STATIC, pos, warnKey);
246 }
247
248 /** Warn about division by integer constant zero.
249 * @param pos Position to be used for error reporting.
250 */
251 void warnDivZero(DiagnosticPosition pos) {
252 if (lint.isEnabled(LintCategory.DIVZERO))
253 log.warning(LintCategory.DIVZERO, pos, Warnings.DivZero);
254 }
255
256 /**
257 * Report any deferred diagnostics.
258 */
259 public void reportDeferredDiagnostics() {
869 public Boolean visitCapturedType(CapturedType t, Void s) {
870 /* Any type variable mentioned in the inferred type must have been declared as a type parameter
871 (i.e cannot have been produced by capture conversion (5.1.10))
872 */
873 return false;
874 }
875
876 @Override
877 public Boolean visitArrayType(ArrayType t, Void s) {
878 return visit(t.elemtype, s);
879 }
880
881 @Override
882 public Boolean visitWildcardType(WildcardType t, Void s) {
883 return visit(t.type, s);
884 }
885 };
886
887 void checkVarargsMethodDecl(Env<AttrContext> env, JCMethodDecl tree) {
888 MethodSymbol m = tree.sym;
889 if (!Feature.SIMPLIFIED_VARARGS.allowedInSource(source)) return;
890 boolean hasTrustMeAnno = m.attribute(syms.trustMeType.tsym) != null;
891 Type varargElemType = null;
892 if (m.isVarArgs()) {
893 varargElemType = types.elemtype(tree.params.last().type);
894 }
895 if (hasTrustMeAnno && !isTrustMeAllowedOnMethod(m)) {
896 if (varargElemType != null) {
897 JCDiagnostic msg = Feature.PRIVATE_SAFE_VARARGS.allowedInSource(source) ?
898 diags.fragment(Fragments.VarargsTrustmeOnVirtualVarargs(m)) :
899 diags.fragment(Fragments.VarargsTrustmeOnVirtualVarargsFinalOnly(m));
900 log.error(tree,
901 Errors.VarargsInvalidTrustmeAnno(syms.trustMeType.tsym,
902 msg));
903 } else {
904 log.error(tree,
905 Errors.VarargsInvalidTrustmeAnno(syms.trustMeType.tsym,
906 Fragments.VarargsTrustmeOnNonVarargsMeth(m)));
907 }
908 } else if (hasTrustMeAnno && varargElemType != null &&
909 types.isReifiable(varargElemType)) {
981 Type varArg = types.elemtype(last);
982 while (args.tail != null) {
983 JCTree arg = args.head;
984 Warner warn = convertWarner(arg.pos(), arg.type, varArg);
985 assertConvertible(arg, arg.type, varArg, warn);
986 args = args.tail;
987 }
988 } else if ((sym.flags() & (VARARGS | SIGNATURE_POLYMORPHIC)) == VARARGS) {
989 // non-varargs call to varargs method
990 Type varParam = owntype.getParameterTypes().last();
991 Type lastArg = argtypes.last();
992 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) &&
993 !types.isSameType(types.erasure(varParam), types.erasure(lastArg)))
994 log.warning(argtrees.last().pos(),
995 Warnings.InexactNonVarargsCall(types.elemtype(varParam),varParam));
996 }
997 }
998 if (useVarargs) {
999 Type argtype = owntype.getParameterTypes().last();
1000 if (!types.isReifiable(argtype) &&
1001 (!Feature.SIMPLIFIED_VARARGS.allowedInSource(source) ||
1002 sym.baseSymbol().attribute(syms.trustMeType.tsym) == null ||
1003 !isTrustMeAllowedOnMethod(sym))) {
1004 warnUnchecked(env.tree.pos(), Warnings.UncheckedGenericArrayCreation(argtype));
1005 }
1006 TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype));
1007 }
1008 if ((sym.flags() & SIGNATURE_POLYMORPHIC) != 0 && !target.hasMethodHandles()) {
1009 log.error(env.tree, Errors.BadTargetSigpolyCall(target, Target.JDK1_7));
1010 }
1011 return owntype;
1012 }
1013 //where
1014 private void assertConvertible(JCTree tree, Type actual, Type formal, Warner warn) {
1015 if (types.isConvertible(actual, formal, warn))
1016 return;
1017
1018 if (formal.isCompound()
1019 && types.isSubtype(actual, types.supertype(formal))
1020 && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn))
1021 return;
1022 }
1023
1024 /**
1025 * Check that type 't' is a valid instantiation of a generic class
1026 * (see JLS 4.5)
1027 *
1028 * @param t class type to be checked
1029 * @return true if 't' is well-formed
|
219 deprecationHandler.report(pos, Warnings.HasBeenDeprecatedModule(sym));
220 } else {
221 deprecationHandler.report(pos, Warnings.HasBeenDeprecated(sym, sym.location()));
222 }
223 }
224 }
225
226 /** Warn about unchecked operation.
227 * @param pos Position to be used for error reporting.
228 * @param msg A string describing the problem.
229 */
230 public void warnUnchecked(DiagnosticPosition pos, Warning warnKey) {
231 if (!lint.isSuppressed(LintCategory.UNCHECKED))
232 uncheckedHandler.report(pos, warnKey);
233 }
234
235 /** Warn about unsafe vararg method decl.
236 * @param pos Position to be used for error reporting.
237 */
238 void warnUnsafeVararg(DiagnosticPosition pos, Warning warnKey) {
239 if (lint.isEnabled(LintCategory.VARARGS))
240 log.warning(LintCategory.VARARGS, pos, warnKey);
241 }
242
243 public void warnStatic(DiagnosticPosition pos, Warning warnKey) {
244 if (lint.isEnabled(LintCategory.STATIC))
245 log.warning(LintCategory.STATIC, pos, warnKey);
246 }
247
248 /** Warn about division by integer constant zero.
249 * @param pos Position to be used for error reporting.
250 */
251 void warnDivZero(DiagnosticPosition pos) {
252 if (lint.isEnabled(LintCategory.DIVZERO))
253 log.warning(LintCategory.DIVZERO, pos, Warnings.DivZero);
254 }
255
256 /**
257 * Report any deferred diagnostics.
258 */
259 public void reportDeferredDiagnostics() {
869 public Boolean visitCapturedType(CapturedType t, Void s) {
870 /* Any type variable mentioned in the inferred type must have been declared as a type parameter
871 (i.e cannot have been produced by capture conversion (5.1.10))
872 */
873 return false;
874 }
875
876 @Override
877 public Boolean visitArrayType(ArrayType t, Void s) {
878 return visit(t.elemtype, s);
879 }
880
881 @Override
882 public Boolean visitWildcardType(WildcardType t, Void s) {
883 return visit(t.type, s);
884 }
885 };
886
887 void checkVarargsMethodDecl(Env<AttrContext> env, JCMethodDecl tree) {
888 MethodSymbol m = tree.sym;
889 boolean hasTrustMeAnno = m.attribute(syms.trustMeType.tsym) != null;
890 Type varargElemType = null;
891 if (m.isVarArgs()) {
892 varargElemType = types.elemtype(tree.params.last().type);
893 }
894 if (hasTrustMeAnno && !isTrustMeAllowedOnMethod(m)) {
895 if (varargElemType != null) {
896 JCDiagnostic msg = Feature.PRIVATE_SAFE_VARARGS.allowedInSource(source) ?
897 diags.fragment(Fragments.VarargsTrustmeOnVirtualVarargs(m)) :
898 diags.fragment(Fragments.VarargsTrustmeOnVirtualVarargsFinalOnly(m));
899 log.error(tree,
900 Errors.VarargsInvalidTrustmeAnno(syms.trustMeType.tsym,
901 msg));
902 } else {
903 log.error(tree,
904 Errors.VarargsInvalidTrustmeAnno(syms.trustMeType.tsym,
905 Fragments.VarargsTrustmeOnNonVarargsMeth(m)));
906 }
907 } else if (hasTrustMeAnno && varargElemType != null &&
908 types.isReifiable(varargElemType)) {
980 Type varArg = types.elemtype(last);
981 while (args.tail != null) {
982 JCTree arg = args.head;
983 Warner warn = convertWarner(arg.pos(), arg.type, varArg);
984 assertConvertible(arg, arg.type, varArg, warn);
985 args = args.tail;
986 }
987 } else if ((sym.flags() & (VARARGS | SIGNATURE_POLYMORPHIC)) == VARARGS) {
988 // non-varargs call to varargs method
989 Type varParam = owntype.getParameterTypes().last();
990 Type lastArg = argtypes.last();
991 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) &&
992 !types.isSameType(types.erasure(varParam), types.erasure(lastArg)))
993 log.warning(argtrees.last().pos(),
994 Warnings.InexactNonVarargsCall(types.elemtype(varParam),varParam));
995 }
996 }
997 if (useVarargs) {
998 Type argtype = owntype.getParameterTypes().last();
999 if (!types.isReifiable(argtype) &&
1000 (sym.baseSymbol().attribute(syms.trustMeType.tsym) == null ||
1001 !isTrustMeAllowedOnMethod(sym))) {
1002 warnUnchecked(env.tree.pos(), Warnings.UncheckedGenericArrayCreation(argtype));
1003 }
1004 TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype));
1005 }
1006 return owntype;
1007 }
1008 //where
1009 private void assertConvertible(JCTree tree, Type actual, Type formal, Warner warn) {
1010 if (types.isConvertible(actual, formal, warn))
1011 return;
1012
1013 if (formal.isCompound()
1014 && types.isSubtype(actual, types.supertype(formal))
1015 && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn))
1016 return;
1017 }
1018
1019 /**
1020 * Check that type 't' is a valid instantiation of a generic class
1021 * (see JLS 4.5)
1022 *
1023 * @param t class type to be checked
1024 * @return true if 't' is well-formed
|