src/share/classes/com/sun/tools/javac/comp/Check.java

changeset 580
46cf751559ae
parent 576
559c9a37d9f6
child 581
f2fdd52e4e87
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Jun 04 17:33:25 2010 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Jun 10 09:29:23 2010 +0100
     1.3 @@ -106,6 +106,7 @@
     1.4  
     1.5          boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION);
     1.6          boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED);
     1.7 +        boolean verboseVarargs = lint.isEnabled(LintCategory.VARARGS);
     1.8          boolean verboseSunApi = lint.isEnabled(LintCategory.SUNAPI);
     1.9          boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings();
    1.10  
    1.11 @@ -113,6 +114,8 @@
    1.12                  enforceMandatoryWarnings, "deprecated");
    1.13          uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
    1.14                  enforceMandatoryWarnings, "unchecked");
    1.15 +        unsafeVarargsHandler = new MandatoryWarningHandler(log, verboseVarargs,
    1.16 +                enforceMandatoryWarnings, "varargs");
    1.17          sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi,
    1.18                  enforceMandatoryWarnings, "sunapi");
    1.19      }
    1.20 @@ -150,6 +153,10 @@
    1.21       */
    1.22      private MandatoryWarningHandler uncheckedHandler;
    1.23  
    1.24 +    /** A handler for messages about unchecked or unsafe vararg method decl.
    1.25 +     */
    1.26 +    private MandatoryWarningHandler unsafeVarargsHandler;
    1.27 +
    1.28      /** A handler for messages about using Sun proprietary API.
    1.29       */
    1.30      private MandatoryWarningHandler sunApiHandler;
    1.31 @@ -182,6 +189,15 @@
    1.32              uncheckedHandler.report(pos, msg, args);
    1.33      }
    1.34  
    1.35 +    /** Warn about unsafe vararg method decl.
    1.36 +     *  @param pos        Position to be used for error reporting.
    1.37 +     *  @param sym        The deprecated symbol.
    1.38 +     */
    1.39 +    void warnUnsafeVararg(DiagnosticPosition pos, Type elemType) {
    1.40 +        if (!lint.isSuppressed(LintCategory.VARARGS))
    1.41 +            unsafeVarargsHandler.report(pos, "varargs.non.reifiable.type", elemType);
    1.42 +    }
    1.43 +
    1.44      /** Warn about using Sun proprietary API.
    1.45       *  @param pos        Position to be used for error reporting.
    1.46       *  @param msg        A string describing the problem.
    1.47 @@ -202,6 +218,7 @@
    1.48      public void reportDeferredDiagnostics() {
    1.49          deprecationHandler.reportDeferredDiagnostic();
    1.50          uncheckedHandler.reportDeferredDiagnostic();
    1.51 +        unsafeVarargsHandler.reportDeferredDiagnostic();
    1.52          sunApiHandler.reportDeferredDiagnostic();
    1.53      }
    1.54  
    1.55 @@ -680,17 +697,33 @@
    1.56          }
    1.57      }
    1.58  
    1.59 +    void checkVarargMethodDecl(JCMethodDecl tree) {
    1.60 +        MethodSymbol m = tree.sym;
    1.61 +        //check the element type of the vararg
    1.62 +        if (m.isVarArgs()) {
    1.63 +            Type varargElemType = types.elemtype(tree.params.last().type);
    1.64 +            if (!types.isReifiable(varargElemType)) {
    1.65 +                warnUnsafeVararg(tree.params.head.pos(), varargElemType);
    1.66 +            }
    1.67 +        }
    1.68 +    }
    1.69 +
    1.70      /**
    1.71       * Check that vararg method call is sound
    1.72       * @param pos Position to be used for error reporting.
    1.73       * @param argtypes Actual arguments supplied to vararg method.
    1.74       */
    1.75 -    void checkVararg(DiagnosticPosition pos, List<Type> argtypes) {
    1.76 +    void checkVararg(DiagnosticPosition pos, List<Type> argtypes, Symbol msym, Env<AttrContext> env) {
    1.77 +        Env<AttrContext> calleeLintEnv = env;
    1.78 +        while (calleeLintEnv.info.lint == null)
    1.79 +            calleeLintEnv = calleeLintEnv.next;
    1.80 +        Lint calleeLint = calleeLintEnv.info.lint.augment(msym.attributes_field, msym.flags());
    1.81          Type argtype = argtypes.last();
    1.82 -        if (!types.isReifiable(argtype))
    1.83 +        if (!types.isReifiable(argtype) && !calleeLint.isSuppressed(Lint.LintCategory.VARARGS)) {
    1.84              warnUnchecked(pos,
    1.85                                "unchecked.generic.array.creation",
    1.86                                argtype);
    1.87 +        }
    1.88      }
    1.89  
    1.90      /** Check that given modifiers are legal for given symbol and

mercurial