langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
changeset 45504 ea7475564d07
parent 45413 75202c6b2c35
child 45756 67f4f8f4d34a
equal deleted inserted replaced
45503:d23ae2d67a5d 45504:ea7475564d07
    40 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
    40 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
    41 import com.sun.tools.javac.tree.*;
    41 import com.sun.tools.javac.tree.*;
    42 import com.sun.tools.javac.util.*;
    42 import com.sun.tools.javac.util.*;
    43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
    43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
    44 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    44 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
       
    45 import com.sun.tools.javac.util.JCDiagnostic.Fragment;
    45 import com.sun.tools.javac.util.List;
    46 import com.sun.tools.javac.util.List;
    46 
    47 
    47 import com.sun.tools.javac.code.Lint;
    48 import com.sun.tools.javac.code.Lint;
    48 import com.sun.tools.javac.code.Lint.LintCategory;
    49 import com.sun.tools.javac.code.Lint.LintCategory;
    49 import com.sun.tools.javac.code.Scope.WriteableScope;
    50 import com.sun.tools.javac.code.Scope.WriteableScope;
   267     /** Warn about division by integer constant zero.
   268     /** Warn about division by integer constant zero.
   268      *  @param pos        Position to be used for error reporting.
   269      *  @param pos        Position to be used for error reporting.
   269      */
   270      */
   270     void warnDivZero(DiagnosticPosition pos) {
   271     void warnDivZero(DiagnosticPosition pos) {
   271         if (lint.isEnabled(LintCategory.DIVZERO))
   272         if (lint.isEnabled(LintCategory.DIVZERO))
   272             log.warning(LintCategory.DIVZERO, pos, "div.zero");
   273             log.warning(LintCategory.DIVZERO, pos, Warnings.DivZero);
   273     }
   274     }
   274 
   275 
   275     /**
   276     /**
   276      * Report any deferred diagnostics.
   277      * Report any deferred diagnostics.
   277      */
   278      */
   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
   528     /**
   535     /**
   529      * Check context to be used when evaluating assignment/return statements
   536      * Check context to be used when evaluating assignment/return statements
   530      */
   537      */
   531     CheckContext basicHandler = new CheckContext() {
   538     CheckContext basicHandler = new CheckContext() {
   532         public void report(DiagnosticPosition pos, JCDiagnostic details) {
   539         public void report(DiagnosticPosition pos, JCDiagnostic details) {
   533             log.error(pos, "prob.found.req", details);
   540             log.error(pos, Errors.ProbFoundReq(details));
   534         }
   541         }
   535         public boolean compatible(Type found, Type req, Warner warn) {
   542         public boolean compatible(Type found, Type req, Warner warn) {
   536             return types.isAssignable(found, req, warn);
   543             return types.isAssignable(found, req, warn);
   537         }
   544         }
   538 
   545 
   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.
   597     }
   604     }
   598     Type checkCastable(DiagnosticPosition pos, Type found, Type req, CheckContext checkContext) {
   605     Type checkCastable(DiagnosticPosition pos, Type found, Type req, CheckContext checkContext) {
   599         if (types.isCastable(found, req, castWarner(pos, found, req))) {
   606         if (types.isCastable(found, req, castWarner(pos, found, req))) {
   600             return req;
   607             return req;
   601         } else {
   608         } else {
   602             checkContext.report(pos, diags.fragment("inconvertible.types", found, req));
   609             checkContext.report(pos, diags.fragment(Fragments.InconvertibleTypes(found, req)));
   603             return types.createErrorType(found);
   610             return types.createErrorType(found);
   604         }
   611         }
   605     }
   612     }
   606 
   613 
   607     /** Check for redundant casts (i.e. where source type is a subtype of target type)
   614     /** Check for redundant casts (i.e. where source type is a subtype of target type)
   613                 && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
   620                 && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
   614                 && !is292targetTypeCast(tree)) {
   621                 && !is292targetTypeCast(tree)) {
   615             deferredLintHandler.report(() -> {
   622             deferredLintHandler.report(() -> {
   616                 if (lint.isEnabled(LintCategory.CAST))
   623                 if (lint.isEnabled(LintCategory.CAST))
   617                     log.warning(LintCategory.CAST,
   624                     log.warning(LintCategory.CAST,
   618                             tree.pos(), "redundant.cast", tree.clazz.type);
   625                             tree.pos(), Warnings.RedundantCast(tree.clazz.type));
   619             });
   626             });
   620         }
   627         }
   621     }
   628     }
   622     //where
   629     //where
   623         private boolean is292targetTypeCast(JCTypeCast tree) {
   630         private boolean is292targetTypeCast(JCTypeCast tree) {
   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     }
   732         if (noBounds && t.isParameterized()) {
   739         if (noBounds && t.isParameterized()) {
   733             List<Type> args = t.getTypeArguments();
   740             List<Type> args = t.getTypeArguments();
   734             while (args.nonEmpty()) {
   741             while (args.nonEmpty()) {
   735                 if (args.head.hasTag(WILDCARD))
   742                 if (args.head.hasTag(WILDCARD))
   736                     return typeTagError(pos,
   743                     return typeTagError(pos,
   737                                         diags.fragment("type.req.exact"),
   744                                         diags.fragment(Fragments.TypeReqExact),
   738                                         args.head);
   745                                         args.head);
   739                 args = args.tail;
   746                 args = args.tail;
   740             }
   747             }
   741         }
   748         }
   742         return t;
   749         return t;
   750     Type checkRefType(DiagnosticPosition pos, Type t) {
   757     Type checkRefType(DiagnosticPosition pos, Type t) {
   751         if (t.isReference())
   758         if (t.isReference())
   752             return t;
   759             return t;
   753         else
   760         else
   754             return typeTagError(pos,
   761             return typeTagError(pos,
   755                                 diags.fragment("type.req.ref"),
   762                                 diags.fragment(Fragments.TypeReqRef),
   756                                 t);
   763                                 t);
   757     }
   764     }
   758 
   765 
   759     /** Check that each type is a reference type, i.e. a class, interface or array type
   766     /** Check that each type is a reference type, i.e. a class, interface or array type
   760      *  or a type variable.
   767      *  or a type variable.
   777     Type checkNullOrRefType(DiagnosticPosition pos, Type t) {
   784     Type checkNullOrRefType(DiagnosticPosition pos, Type t) {
   778         if (t.isReference() || t.hasTag(BOT))
   785         if (t.isReference() || t.hasTag(BOT))
   779             return t;
   786             return t;
   780         else
   787         else
   781             return typeTagError(pos,
   788             return typeTagError(pos,
   782                                 diags.fragment("type.req.ref"),
   789                                 diags.fragment(Fragments.TypeReqRef),
   783                                 t);
   790                                 t);
   784     }
   791     }
   785 
   792 
   786     /** Check that flag set does not contain elements of two conflicting sets. s
   793     /** Check that flag set does not contain elements of two conflicting sets. s
   787      *  Return true if it doesn't.
   794      *  Return true if it doesn't.
   791      *  @param set2          Conflicting flags set #2.
   798      *  @param set2          Conflicting flags set #2.
   792      */
   799      */
   793     boolean checkDisjoint(DiagnosticPosition pos, long flags, long set1, long set2) {
   800     boolean checkDisjoint(DiagnosticPosition pos, long flags, long set1, long set2) {
   794         if ((flags & set1) != 0 && (flags & set2) != 0) {
   801         if ((flags & set1) != 0 && (flags & set2) != 0) {
   795             log.error(pos,
   802             log.error(pos,
   796                       "illegal.combination.of.modifiers",
   803                       Errors.IllegalCombinationOfModifiers(asFlagSet(TreeInfo.firstFlag(flags & set1)),
   797                       asFlagSet(TreeInfo.firstFlag(flags & set1)),
   804                                                            asFlagSet(TreeInfo.firstFlag(flags & set2))));
   798                       asFlagSet(TreeInfo.firstFlag(flags & set2)));
       
   799             return false;
   805             return false;
   800         } else
   806         } else
   801             return true;
   807             return true;
   802     }
   808     }
   803 
   809 
   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             }
  1200             throw new AssertionError();
  1205             throw new AssertionError();
  1201         }
  1206         }
  1202         long illegal = flags & ExtendedStandardFlags & ~mask;
  1207         long illegal = flags & ExtendedStandardFlags & ~mask;
  1203         if (illegal != 0) {
  1208         if (illegal != 0) {
  1204             if ((illegal & INTERFACE) != 0) {
  1209             if ((illegal & INTERFACE) != 0) {
  1205                 log.error(pos, "intf.not.allowed.here");
  1210                 log.error(pos, Errors.IntfNotAllowedHere);
  1206                 mask |= INTERFACE;
  1211                 mask |= INTERFACE;
  1207             }
  1212             }
  1208             else {
  1213             else {
  1209                 log.error(pos,
  1214                 log.error(pos,
  1210                           "mod.not.allowed.here", asFlagSet(illegal));
  1215                           Errors.ModNotAllowedHere(asFlagSet(illegal)));
  1211             }
  1216             }
  1212         }
  1217         }
  1213         else if ((sym.kind == TYP ||
  1218         else if ((sym.kind == TYP ||
  1214                   // ISSUE: Disallowing abstract&private is no longer appropriate
  1219                   // ISSUE: Disallowing abstract&private is no longer appropriate
  1215                   // in the presence of inner classes. Should it be deleted here?
  1220                   // in the presence of inner classes. Should it be deleted here?
  1344 
  1349 
  1345                 Type incompatibleArg = firstIncompatibleTypeArg(tree.type);
  1350                 Type incompatibleArg = firstIncompatibleTypeArg(tree.type);
  1346                 if (incompatibleArg != null) {
  1351                 if (incompatibleArg != null) {
  1347                     for (JCTree arg : tree.arguments) {
  1352                     for (JCTree arg : tree.arguments) {
  1348                         if (arg.type == incompatibleArg) {
  1353                         if (arg.type == incompatibleArg) {
  1349                             log.error(arg, "not.within.bounds", incompatibleArg, forms.head);
  1354                             log.error(arg, Errors.NotWithinBounds(incompatibleArg, forms.head));
  1350                         }
  1355                         }
  1351                         forms = forms.tail;
  1356                         forms = forms.tail;
  1352                      }
  1357                      }
  1353                  }
  1358                  }
  1354 
  1359 
  1367                 }
  1372                 }
  1368 
  1373 
  1369                 // Check that this type is either fully parameterized, or
  1374                 // Check that this type is either fully parameterized, or
  1370                 // not parameterized at all.
  1375                 // not parameterized at all.
  1371                 if (tree.type.getEnclosingType().isRaw())
  1376                 if (tree.type.getEnclosingType().isRaw())
  1372                     log.error(tree.pos(), "improperly.formed.type.inner.raw.param");
  1377                     log.error(tree.pos(), Errors.ImproperlyFormedTypeInnerRawParam);
  1373                 if (tree.clazz.hasTag(SELECT))
  1378                 if (tree.clazz.hasTag(SELECT))
  1374                     visitSelectInternal((JCFieldAccess)tree.clazz);
  1379                     visitSelectInternal((JCFieldAccess)tree.clazz);
  1375             }
  1380             }
  1376         }
  1381         }
  1377 
  1382 
  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         }
  1418         }
  1423         }
  1419 
  1424 
  1420         @Override
  1425         @Override
  1421         public void visitTypeIdent(JCPrimitiveTypeTree that) {
  1426         public void visitTypeIdent(JCPrimitiveTypeTree that) {
  1422             if (that.type.hasTag(TypeTag.VOID)) {
  1427             if (that.type.hasTag(TypeTag.VOID)) {
  1423                 log.error(that.pos(), "void.not.allowed.here");
  1428                 log.error(that.pos(), Errors.VoidNotAllowedHere);
  1424             }
  1429             }
  1425             super.visitTypeIdent(that);
  1430             super.visitTypeIdent(that);
  1426         }
  1431         }
  1427 
  1432 
  1428         /** Default visitor method: do nothing.
  1433         /** Default visitor method: do nothing.
  1460             tree.type.hasTag(CLASS) &&
  1465             tree.type.hasTag(CLASS) &&
  1461             !TreeInfo.isDiamond(tree) &&
  1466             !TreeInfo.isDiamond(tree) &&
  1462             !withinAnonConstr(env) &&
  1467             !withinAnonConstr(env) &&
  1463             tree.type.isRaw()) {
  1468             tree.type.isRaw()) {
  1464             log.warning(LintCategory.RAW,
  1469             log.warning(LintCategory.RAW,
  1465                     tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type);
  1470                     tree.pos(), Warnings.RawClassUse(tree.type, tree.type.tsym.type));
  1466         }
  1471         }
  1467     }
  1472     }
  1468     //where
  1473     //where
  1469         private boolean withinAnonConstr(Env<AttrContext> env) {
  1474         private boolean withinAnonConstr(Env<AttrContext> env) {
  1470             return env.enclClass.name.isEmpty() &&
  1475             return env.enclClass.name.isEmpty() &&
  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));
  1869                                                               types,
  1873                                                               types,
  1870                                                               true) != s2)
  1874                                                               true) != s2)
  1871                             continue;
  1875                             continue;
  1872                         Type st2 = types.memberType(t2, s2);
  1876                         Type st2 = types.memberType(t2, s2);
  1873                         if (types.overrideEquivalent(st1, st2))
  1877                         if (types.overrideEquivalent(st1, st2))
  1874                             log.error(pos, "concrete.inheritance.conflict",
  1878                             log.error(pos,
  1875                                       s1, t1, s2, t2, sup);
  1879                                       Errors.ConcreteInheritanceConflict(s1, t1, s2, t2, sup));
  1876                     }
  1880                     }
  1877                 }
  1881                 }
  1878             }
  1882             }
  1879         }
  1883         }
  1880     }
  1884     }
  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(
  2015      */
  2018      */
  2016     void checkOverride(Env<AttrContext> env, JCMethodDecl tree, MethodSymbol m) {
  2019     void checkOverride(Env<AttrContext> env, JCMethodDecl tree, MethodSymbol m) {
  2017         ClassSymbol origin = (ClassSymbol)m.owner;
  2020         ClassSymbol origin = (ClassSymbol)m.owner;
  2018         if ((origin.flags() & ENUM) != 0 && names.finalize.equals(m.name))
  2021         if ((origin.flags() & ENUM) != 0 && names.finalize.equals(m.name))
  2019             if (m.overrides(syms.enumFinalFinalize, origin, types, false)) {
  2022             if (m.overrides(syms.enumFinalFinalize, origin, types, false)) {
  2020                 log.error(tree.pos(), "enum.no.finalize");
  2023                 log.error(tree.pos(), Errors.EnumNoFinalize);
  2021                 return;
  2024                 return;
  2022             }
  2025             }
  2023         for (Type t = origin.type; t.hasTag(CLASS);
  2026         for (Type t = origin.type; t.hasTag(CLASS);
  2024              t = types.supertype(t)) {
  2027              t = types.supertype(t)) {
  2025             if (t != origin.type) {
  2028             if (t != origin.type) {
  2095             boolean overridesHashCode = types.implementation(hashCodeAtObject,
  2098             boolean overridesHashCode = types.implementation(hashCodeAtObject,
  2096                 someClass, false, equalsHasCodeFilter) != hashCodeAtObject;
  2099                 someClass, false, equalsHasCodeFilter) != hashCodeAtObject;
  2097 
  2100 
  2098             if (overridesEquals && !overridesHashCode) {
  2101             if (overridesEquals && !overridesHashCode) {
  2099                 log.warning(LintCategory.OVERRIDES, pos,
  2102                 log.warning(LintCategory.OVERRIDES, pos,
  2100                         "override.equals.but.not.hashcode", someClass);
  2103                             Warnings.OverrideEqualsButNotHashcode(someClass));
  2101             }
  2104             }
  2102         }
  2105         }
  2103     }
  2106     }
  2104 
  2107 
  2105     public void checkModuleName (JCModuleDecl tree) {
  2108     public void checkModuleName (JCModuleDecl tree) {
  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();
  2286         if  (t.hasTag(TYPEVAR) && (t.tsym.flags() & UNATTRIBUTED) != 0)
  2289         if  (t.hasTag(TYPEVAR) && (t.tsym.flags() & UNATTRIBUTED) != 0)
  2287             return;
  2290             return;
  2288         if (seen.contains(t)) {
  2291         if (seen.contains(t)) {
  2289             tv = (TypeVar)t;
  2292             tv = (TypeVar)t;
  2290             tv.bound = types.createErrorType(t);
  2293             tv.bound = types.createErrorType(t);
  2291             log.error(pos, "cyclic.inheritance", t);
  2294             log.error(pos, Errors.CyclicInheritance(t));
  2292         } else if (t.hasTag(TYPEVAR)) {
  2295         } else if (t.hasTag(TYPEVAR)) {
  2293             tv = (TypeVar)t;
  2296             tv = (TypeVar)t;
  2294             seen = seen.prepend(tv);
  2297             seen = seen.prepend(tv);
  2295             for (Type b : types.getBounds(tv))
  2298             for (Type b : types.getBounds(tv))
  2296                 checkNonCyclic1(pos, b, seen);
  2299                 checkNonCyclic1(pos, b, seen);
  2338         return complete;
  2341         return complete;
  2339     }
  2342     }
  2340 
  2343 
  2341     /** Note that we found an inheritance cycle. */
  2344     /** Note that we found an inheritance cycle. */
  2342     private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) {
  2345     private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) {
  2343         log.error(pos, "cyclic.inheritance", c);
  2346         log.error(pos, Errors.CyclicInheritance(c));
  2344         for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail)
  2347         for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail)
  2345             l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType);
  2348             l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType);
  2346         Type st = types.supertype(c.type);
  2349         Type st = types.supertype(c.type);
  2347         if (st.hasTag(CLASS))
  2350         if (st.hasTag(CLASS))
  2348             ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType);
  2351             ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType);
  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             }
  2645             if (potentiallyAmbiguous) {
  2646             if (potentiallyAmbiguous) {
  2646                 //we found two incompatible functional interfaces with same arity
  2647                 //we found two incompatible functional interfaces with same arity
  2647                 //this means a call site passing an implicit lambda would be ambigiuous
  2648                 //this means a call site passing an implicit lambda would be ambigiuous
  2648                 msym1.flags_field |= POTENTIALLY_AMBIGUOUS;
  2649                 msym1.flags_field |= POTENTIALLY_AMBIGUOUS;
  2649                 msym2.flags_field |= POTENTIALLY_AMBIGUOUS;
  2650                 msym2.flags_field |= POTENTIALLY_AMBIGUOUS;
  2650                 log.warning(LintCategory.OVERLOADS, pos, "potentially.ambiguous.overload",
  2651                 log.warning(LintCategory.OVERLOADS, pos,
  2651                             msym1, msym1.location(),
  2652                             Warnings.PotentiallyAmbiguousOverload(msym1, msym1.location(),
  2652                             msym2, msym2.location());
  2653                                                                   msym2, msym2.location()));
  2653                 return;
  2654                 return;
  2654             }
  2655             }
  2655         }
  2656         }
  2656     }
  2657     }
  2657 
  2658 
  2677             if (!types.isSubtype(sym.owner.type, syms.serializableType) &&
  2678             if (!types.isSubtype(sym.owner.type, syms.serializableType) &&
  2678                 isEffectivelyNonPublic(sym)) {
  2679                 isEffectivelyNonPublic(sym)) {
  2679                 if (isLambda) {
  2680                 if (isLambda) {
  2680                     if (belongsToRestrictedPackage(sym)) {
  2681                     if (belongsToRestrictedPackage(sym)) {
  2681                         log.warning(LintCategory.SERIAL, tree.pos(),
  2682                         log.warning(LintCategory.SERIAL, tree.pos(),
  2682                             "access.to.member.from.serializable.lambda", sym);
  2683                                     Warnings.AccessToMemberFromSerializableLambda(sym));
  2683                     }
  2684                     }
  2684                 } else {
  2685                 } else {
  2685                     log.warning(tree.pos(),
  2686                     log.warning(tree.pos(),
  2686                         "access.to.member.from.serializable.element", sym);
  2687                                 Warnings.AccessToMemberFromSerializableElement(sym));
  2687                 }
  2688                 }
  2688             }
  2689             }
  2689         }
  2690         }
  2690     }
  2691     }
  2691 
  2692 
  2713 
  2714 
  2714     /** Report a conflict between a user symbol and a synthetic symbol.
  2715     /** Report a conflict between a user symbol and a synthetic symbol.
  2715      */
  2716      */
  2716     private void syntheticError(DiagnosticPosition pos, Symbol sym) {
  2717     private void syntheticError(DiagnosticPosition pos, Symbol sym) {
  2717         if (!sym.type.isErroneous()) {
  2718         if (!sym.type.isErroneous()) {
  2718             log.error(pos, "synthetic.name.conflict", sym, sym.location());
  2719             log.error(pos, Errors.SyntheticNameConflict(sym, sym.location()));
  2719         }
  2720         }
  2720     }
  2721     }
  2721 
  2722 
  2722     /** Check that class c does not implement directly or indirectly
  2723     /** Check that class c does not implement directly or indirectly
  2723      *  the same parameterized interface with two different argument lists.
  2724      *  the same parameterized interface with two different argument lists.
  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);
  2756     /** Enter interface into into set.
  2758     /** Enter interface into into set.
  2757      *  If it existed already, issue a "repeated interface" error.
  2759      *  If it existed already, issue a "repeated interface" error.
  2758      */
  2760      */
  2759     void checkNotRepeated(DiagnosticPosition pos, Type it, Set<Type> its) {
  2761     void checkNotRepeated(DiagnosticPosition pos, Type it, Set<Type> its) {
  2760         if (its.contains(it))
  2762         if (its.contains(it))
  2761             log.error(pos, "repeated.interface");
  2763             log.error(pos, Errors.RepeatedInterface);
  2762         else {
  2764         else {
  2763             its.add(it);
  2765             its.add(it);
  2764         }
  2766         }
  2765     }
  2767     }
  2766 
  2768 
  2806         if (types.cvarLowerBound(type).tsym == syms.classType.tsym) return;
  2808         if (types.cvarLowerBound(type).tsym == syms.classType.tsym) return;
  2807         if (types.isArray(type) && !types.isArray(types.elemtype(type))) {
  2809         if (types.isArray(type) && !types.isArray(types.elemtype(type))) {
  2808             validateAnnotationType(pos, types.elemtype(type));
  2810             validateAnnotationType(pos, types.elemtype(type));
  2809             return;
  2811             return;
  2810         }
  2812         }
  2811         log.error(pos, "invalid.annotation.member.type");
  2813         log.error(pos, Errors.InvalidAnnotationMemberType);
  2812     }
  2814     }
  2813 
  2815 
  2814     /**
  2816     /**
  2815      * "It is also a compile-time error if any method declared in an
  2817      * "It is also a compile-time error if any method declared in an
  2816      * annotation type has a signature that is override-equivalent to
  2818      * annotation type has a signature that is override-equivalent to
  2824             Scope s = sup.tsym.members();
  2826             Scope s = sup.tsym.members();
  2825             for (Symbol sym : s.getSymbolsByName(m.name)) {
  2827             for (Symbol sym : s.getSymbolsByName(m.name)) {
  2826                 if (sym.kind == MTH &&
  2828                 if (sym.kind == MTH &&
  2827                     (sym.flags() & (PUBLIC | PROTECTED)) != 0 &&
  2829                     (sym.flags() & (PUBLIC | PROTECTED)) != 0 &&
  2828                     types.overrideEquivalent(m.type, sym.type))
  2830                     types.overrideEquivalent(m.type, sym.type))
  2829                     log.error(pos, "intf.annotation.member.clash", sym, sup);
  2831                     log.error(pos, Errors.IntfAnnotationMemberClash(sym, sup));
  2830             }
  2832             }
  2831         }
  2833         }
  2832     }
  2834     }
  2833 
  2835 
  2834     /** Check the annotations of a symbol.
  2836     /** Check the annotations of a symbol.
  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) {
  2993                 containedTargets.add(e.value.name);
  2999                 containedTargets.add(e.value.name);
  2994             }
  3000             }
  2995         }
  3001         }
  2996 
  3002 
  2997         if (!isTargetSubsetOf(containerTargets, containedTargets)) {
  3003         if (!isTargetSubsetOf(containerTargets, containedTargets)) {
  2998             log.error(pos, "invalid.repeatable.annotation.incompatible.target", container, contained);
  3004             log.error(pos, Errors.InvalidRepeatableAnnotationIncompatibleTarget(container, contained));
  2999         }
  3005         }
  3000     }
  3006     }
  3001 
  3007 
  3002     /* get a set of names for the default target */
  3008     /* get a set of names for the default target */
  3003     private Set<Name> getDefaultTargetSet() {
  3009     private Set<Name> getDefaultTargetSet() {
  3056         for(Symbol elm : scope.getSymbols()) {
  3062         for(Symbol elm : scope.getSymbols()) {
  3057             if (elm.name != names.value &&
  3063             if (elm.name != names.value &&
  3058                 elm.kind == MTH &&
  3064                 elm.kind == MTH &&
  3059                 ((MethodSymbol)elm).defaultValue == null) {
  3065                 ((MethodSymbol)elm).defaultValue == null) {
  3060                 log.error(pos,
  3066                 log.error(pos,
  3061                           "invalid.repeatable.annotation.elem.nondefault",
  3067                           Errors.InvalidRepeatableAnnotationElemNondefault(container, elm));
  3062                           container,
       
  3063                           elm);
       
  3064             }
  3068             }
  3065         }
  3069         }
  3066     }
  3070     }
  3067 
  3071 
  3068     /** Is s a method symbol that overrides a method in a superclass? */
  3072     /** Is s a method symbol that overrides a method in a superclass? */
  3207             JCAssign assign = (JCAssign)arg;
  3211             JCAssign assign = (JCAssign)arg;
  3208             Symbol m = TreeInfo.symbol(assign.lhs);
  3212             Symbol m = TreeInfo.symbol(assign.lhs);
  3209             if (m == null || m.type.isErroneous()) continue;
  3213             if (m == null || m.type.isErroneous()) continue;
  3210             if (!elements.remove(m)) {
  3214             if (!elements.remove(m)) {
  3211                 isValid = false;
  3215                 isValid = false;
  3212                 log.error(assign.lhs.pos(), "duplicate.annotation.member.value",
  3216                 log.error(assign.lhs.pos(),
  3213                         m.name, a.type);
  3217                           Errors.DuplicateAnnotationMemberValue(m.name, a.type));
  3214             }
  3218             }
  3215         }
  3219         }
  3216 
  3220 
  3217         // all the remaining ones better have default values
  3221         // all the remaining ones better have default values
  3218         List<Name> missingDefaults = List.nil();
  3222         List<Name> missingDefaults = List.nil();
  3254         JCNewArray na = (JCNewArray) rhs;
  3258         JCNewArray na = (JCNewArray) rhs;
  3255         Set<Symbol> targets = new HashSet<>();
  3259         Set<Symbol> targets = new HashSet<>();
  3256         for (JCTree elem : na.elems) {
  3260         for (JCTree elem : na.elems) {
  3257             if (!targets.add(TreeInfo.symbol(elem))) {
  3261             if (!targets.add(TreeInfo.symbol(elem))) {
  3258                 isValid = false;
  3262                 isValid = false;
  3259                 log.error(elem.pos(), "repeated.annotation.target");
  3263                 log.error(elem.pos(), Errors.RepeatedAnnotationTarget);
  3260             }
  3264             }
  3261         }
  3265         }
  3262         return isValid;
  3266         return isValid;
  3263     }
  3267     }
  3264 
  3268 
  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.
  3325 
  3329 
  3326     void checkNonCyclicElementsInternal(DiagnosticPosition pos, TypeSymbol tsym) {
  3330     void checkNonCyclicElementsInternal(DiagnosticPosition pos, TypeSymbol tsym) {
  3327         if ((tsym.flags_field & ACYCLIC_ANN) != 0)
  3331         if ((tsym.flags_field & ACYCLIC_ANN) != 0)
  3328             return;
  3332             return;
  3329         if ((tsym.flags_field & LOCKED) != 0) {
  3333         if ((tsym.flags_field & LOCKED) != 0) {
  3330             log.error(pos, "cyclic.annotation.element");
  3334             log.error(pos, Errors.CyclicAnnotationElement(tsym));
  3331             return;
  3335             return;
  3332         }
  3336         }
  3333         try {
  3337         try {
  3334             tsym.flags_field |= LOCKED;
  3338             tsym.flags_field |= LOCKED;
  3335             for (Symbol s : tsym.members().getSymbols(NON_RECURSIVE)) {
  3339             for (Symbol s : tsym.members().getSymbols(NON_RECURSIVE)) {
  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             }
  3431      * Check for empty statements after if
  3435      * Check for empty statements after if
  3432      */
  3436      */
  3433     void checkEmptyIf(JCIf tree) {
  3437     void checkEmptyIf(JCIf tree) {
  3434         if (tree.thenpart.hasTag(SKIP) && tree.elsepart == null &&
  3438         if (tree.thenpart.hasTag(SKIP) && tree.elsepart == null &&
  3435                 lint.isEnabled(LintCategory.EMPTY))
  3439                 lint.isEnabled(LintCategory.EMPTY))
  3436             log.warning(LintCategory.EMPTY, tree.thenpart.pos(), "empty.if");
  3440             log.warning(LintCategory.EMPTY, tree.thenpart.pos(), Warnings.EmptyIf);
  3437     }
  3441     }
  3438 
  3442 
  3439     /** Check that symbol is unique in given scope.
  3443     /** Check that symbol is unique in given scope.
  3440      *  @param pos           Position for error reporting.
  3444      *  @param pos           Position for error reporting.
  3441      *  @param sym           The symbol.
  3445      *  @param sym           The symbol.
  3471 
  3475 
  3472     /** Report duplicate declaration error.
  3476     /** Report duplicate declaration error.
  3473      */
  3477      */
  3474     void duplicateErasureError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) {
  3478     void duplicateErasureError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) {
  3475         if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) {
  3479         if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) {
  3476             log.error(pos, "name.clash.same.erasure", sym1, sym2);
  3480             log.error(pos, Errors.NameClashSameErasure(sym1, sym2));
  3477         }
  3481         }
  3478     }
  3482     }
  3479 
  3483 
  3480     /**Check that types imported through the ordinary imports don't clash with types imported
  3484     /**Check that types imported through the ordinary imports don't clash with types imported
  3481      * by other (static or ordinary) imports. Note that two static imports may import two clashing
  3485      * by other (static or ordinary) imports. Note that two static imports may import two clashing
  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;
  3568         if (lint.isEnabled(Lint.LintCategory.AUXILIARYCLASS) &&
  3572         if (lint.isEnabled(Lint.LintCategory.AUXILIARYCLASS) &&
  3569             (c.flags() & AUXILIARY) != 0 &&
  3573             (c.flags() & AUXILIARY) != 0 &&
  3570             rs.isAccessible(env, c) &&
  3574             rs.isAccessible(env, c) &&
  3571             !fileManager.isSameFile(c.sourcefile, env.toplevel.sourcefile))
  3575             !fileManager.isSameFile(c.sourcefile, env.toplevel.sourcefile))
  3572         {
  3576         {
  3573             log.warning(pos, "auxiliary.class.accessed.from.outside.of.its.source.file",
  3577             log.warning(pos,
  3574                         c, c.sourcefile);
  3578                         Warnings.AuxiliaryClassAccessedFromOutsideOfItsSourceFile(c, c.sourcefile));
  3575         }
  3579         }
  3576     }
  3580     }
  3577 
  3581 
  3578     private class ConversionWarner extends Warner {
  3582     private class ConversionWarner extends Warner {
  3579         final String uncheckedKey;
  3583         final String uncheckedKey;
  3629                     if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) {
  3633                     if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) {
  3630                         pos = a.pos();
  3634                         pos = a.pos();
  3631                         break;
  3635                         break;
  3632                     }
  3636                     }
  3633                 }
  3637                 }
  3634                 log.error(pos, "bad.functional.intf.anno.1", ex.getDiagnostic());
  3638                 log.error(pos, Errors.BadFunctionalIntfAnno1(ex.getDiagnostic()));
  3635             }
  3639             }
  3636         }
  3640         }
  3637     }
  3641     }
  3638 
  3642 
  3639     public void checkImportsResolvable(final JCCompilationUnit toplevel) {
  3643     public void checkImportsResolvable(final JCCompilationUnit toplevel) {
  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)
  3670                         if (Convert.packagePart(known.fullname) == tsym.flatName())
  3677                         if (Convert.packagePart(known.fullname) == tsym.flatName())
  3671                             continue OUTER;
  3678                             continue OUTER;
  3672                     }
  3679                     }
  3673                 }
  3680                 }
  3674                 if (tsym.kind == PCK && tsym.members().isEmpty() && !tsym.exists()) {
  3681                 if (tsym.kind == PCK && tsym.members().isEmpty() && !tsym.exists()) {
  3675                     log.error(DiagnosticFlag.RESOLVE_ERROR, imp.pos, "doesnt.exist", tsym);
  3682                     log.error(DiagnosticFlag.RESOLVE_ERROR, imp.pos, Errors.DoesntExist(tsym));
  3676                 }
  3683                 }
  3677             }
  3684             }
  3678         }
  3685         }
  3679     }
  3686     }
  3680 
  3687