langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
changeset 42827 36468b5fa7f4
parent 42822 a84956e7ee4d
child 42828 cce89649f958
equal deleted inserted replaced
42826:563b42fc70ba 42827:36468b5fa7f4
   563     }
   563     }
   564 
   564 
   565     Type checkType(final DiagnosticPosition pos, final Type found, final Type req, final CheckContext checkContext) {
   565     Type checkType(final DiagnosticPosition pos, final Type found, final Type req, final CheckContext checkContext) {
   566         final InferenceContext inferenceContext = checkContext.inferenceContext();
   566         final InferenceContext inferenceContext = checkContext.inferenceContext();
   567         if (inferenceContext.free(req) || inferenceContext.free(found)) {
   567         if (inferenceContext.free(req) || inferenceContext.free(found)) {
   568             inferenceContext.addFreeTypeListener(List.of(req, found), new FreeTypeListener() {
   568             inferenceContext.addFreeTypeListener(List.of(req, found),
   569                 @Override
   569                     solvedContext -> checkType(pos, solvedContext.asInstType(found), solvedContext.asInstType(req), checkContext));
   570                 public void typesInferred(InferenceContext inferenceContext) {
       
   571                     checkType(pos, inferenceContext.asInstType(found), inferenceContext.asInstType(req), checkContext);
       
   572                 }
       
   573             });
       
   574         }
   570         }
   575         if (req.hasTag(ERROR))
   571         if (req.hasTag(ERROR))
   576             return req;
   572             return req;
   577         if (req.hasTag(NONE))
   573         if (req.hasTag(NONE))
   578             return found;
   574             return found;
   612     public void checkRedundantCast(Env<AttrContext> env, final JCTypeCast tree) {
   608     public void checkRedundantCast(Env<AttrContext> env, final JCTypeCast tree) {
   613         if (!tree.type.isErroneous()
   609         if (!tree.type.isErroneous()
   614                 && types.isSameType(tree.expr.type, tree.clazz.type)
   610                 && types.isSameType(tree.expr.type, tree.clazz.type)
   615                 && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
   611                 && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
   616                 && !is292targetTypeCast(tree)) {
   612                 && !is292targetTypeCast(tree)) {
   617             deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
   613             deferredLintHandler.report(() -> {
   618                 @Override
   614                 if (lint.isEnabled(LintCategory.CAST))
   619                 public void report() {
   615                     log.warning(LintCategory.CAST,
   620                     if (lint.isEnabled(Lint.LintCategory.CAST))
   616                             tree.pos(), "redundant.cast", tree.clazz.type);
   621                         log.warning(Lint.LintCategory.CAST,
       
   622                                 tree.pos(), "redundant.cast", tree.clazz.type);
       
   623                 }
       
   624             });
   617             });
   625         }
   618         }
   626     }
   619     }
   627     //where
   620     //where
   628         private boolean is292targetTypeCast(JCTypeCast tree) {
   621         private boolean is292targetTypeCast(JCTypeCast tree) {
   951             InferenceContext inferenceContext) {
   944             InferenceContext inferenceContext) {
   952         // System.out.println("call   : " + env.tree);
   945         // System.out.println("call   : " + env.tree);
   953         // System.out.println("method : " + owntype);
   946         // System.out.println("method : " + owntype);
   954         // System.out.println("actuals: " + argtypes);
   947         // System.out.println("actuals: " + argtypes);
   955         if (inferenceContext.free(mtype)) {
   948         if (inferenceContext.free(mtype)) {
   956             inferenceContext.addFreeTypeListener(List.of(mtype), new FreeTypeListener() {
   949             inferenceContext.addFreeTypeListener(List.of(mtype),
   957                 public void typesInferred(InferenceContext inferenceContext) {
   950                     solvedContext -> checkMethod(solvedContext.asInstType(mtype), sym, env, argtrees, argtypes, useVarargs, solvedContext));
   958                     checkMethod(inferenceContext.asInstType(mtype), sym, env, argtrees, argtypes, useVarargs, inferenceContext);
       
   959                 }
       
   960             });
       
   961             return mtype;
   951             return mtype;
   962         }
   952         }
   963         Type owntype = mtype;
   953         Type owntype = mtype;
   964         List<Type> formals = owntype.getParameterTypes();
   954         List<Type> formals = owntype.getParameterTypes();
   965         List<Type> nonInferred = sym.type.getParameterTypes();
   955         List<Type> nonInferred = sym.type.getParameterTypes();
  2068                 }
  2058                 }
  2069             }
  2059             }
  2070         }
  2060         }
  2071     }
  2061     }
  2072 
  2062 
  2073     private Filter<Symbol> equalsHasCodeFilter = new Filter<Symbol>() {
  2063     private Filter<Symbol> equalsHasCodeFilter = s -> MethodSymbol.implementation_filter.accepts(s) &&
  2074         public boolean accepts(Symbol s) {
  2064             (s.flags() & BAD_OVERRIDE) == 0;
  2075             return MethodSymbol.implementation_filter.accepts(s) &&
       
  2076                     (s.flags() & BAD_OVERRIDE) == 0;
       
  2077 
       
  2078         }
       
  2079     };
       
  2080 
  2065 
  2081     public void checkClassOverrideEqualsAndHashIfNeeded(DiagnosticPosition pos,
  2066     public void checkClassOverrideEqualsAndHashIfNeeded(DiagnosticPosition pos,
  2082             ClassSymbol someClass) {
  2067             ClassSymbol someClass) {
  2083         /* At present, annotations cannot possibly have a method that is override
  2068         /* At present, annotations cannot possibly have a method that is override
  2084          * equivalent with Object.equals(Object) but in any case the condition is
  2069          * equivalent with Object.equals(Object) but in any case the condition is
  3264 
  3249 
  3265     void checkDeprecated(final DiagnosticPosition pos, final Symbol other, final Symbol s) {
  3250     void checkDeprecated(final DiagnosticPosition pos, final Symbol other, final Symbol s) {
  3266         if ( (s.isDeprecatedForRemoval()
  3251         if ( (s.isDeprecatedForRemoval()
  3267                 || s.isDeprecated() && !other.isDeprecated())
  3252                 || s.isDeprecated() && !other.isDeprecated())
  3268                 && (s.outermostClass() != other.outermostClass() || s.outermostClass() == null)) {
  3253                 && (s.outermostClass() != other.outermostClass() || s.outermostClass() == null)) {
  3269             deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
  3254             deferredLintHandler.report(() -> warnDeprecated(pos, s));
  3270                 @Override
       
  3271                 public void report() {
       
  3272                     warnDeprecated(pos, s);
       
  3273                 }
       
  3274             });
       
  3275         }
  3255         }
  3276     }
  3256     }
  3277 
  3257 
  3278     void checkSunAPI(final DiagnosticPosition pos, final Symbol s) {
  3258     void checkSunAPI(final DiagnosticPosition pos, final Symbol s) {
  3279         if ((s.flags() & PROPRIETARY) != 0) {
  3259         if ((s.flags() & PROPRIETARY) != 0) {
  3408             && operand.getTag().isSubRangeOf(LONG)
  3388             && operand.getTag().isSubRangeOf(LONG)
  3409             && ((Number) (operand.constValue())).longValue() == 0) {
  3389             && ((Number) (operand.constValue())).longValue() == 0) {
  3410             int opc = ((OperatorSymbol)operator).opcode;
  3390             int opc = ((OperatorSymbol)operator).opcode;
  3411             if (opc == ByteCodes.idiv || opc == ByteCodes.imod
  3391             if (opc == ByteCodes.idiv || opc == ByteCodes.imod
  3412                 || opc == ByteCodes.ldiv || opc == ByteCodes.lmod) {
  3392                 || opc == ByteCodes.ldiv || opc == ByteCodes.lmod) {
  3413                 deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
  3393                 deferredLintHandler.report(() -> warnDivZero(pos));
  3414                     @Override
       
  3415                     public void report() {
       
  3416                         warnDivZero(pos);
       
  3417                     }
       
  3418                 });
       
  3419             }
  3394             }
  3420         }
  3395         }
  3421     }
  3396     }
  3422 
  3397 
  3423     /**
  3398     /**
  3890             }
  3865             }
  3891         }
  3866         }
  3892 
  3867 
  3893     void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) {
  3868     void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) {
  3894         if (msym.kind != MDL) {
  3869         if (msym.kind != MDL) {
  3895             deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
  3870             deferredLintHandler.report(() -> {
  3896                 @Override
  3871                 if (lint.isEnabled(LintCategory.MODULE))
  3897                 public void report() {
  3872                     log.warning(LintCategory.MODULE, pos, Warnings.ModuleNotFound(msym));
  3898                     if (lint.isEnabled(Lint.LintCategory.MODULE))
       
  3899                         log.warning(LintCategory.MODULE, pos, Warnings.ModuleNotFound(msym));
       
  3900                 }
       
  3901             });
  3873             });
  3902         }
  3874         }
  3903     }
  3875     }
  3904 
  3876 
  3905 }
  3877 }