langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
changeset 22163 3651128c74eb
parent 22161 d79fb23b5dca
child 22167 e0ba35f27975
equal deleted inserted replaced
22162:3b3e23e67329 22163:3651128c74eb
    76  *  If you write code that depends on this, you do so at your own risk.
    76  *  If you write code that depends on this, you do so at your own risk.
    77  *  This code and its internal interfaces are subject to change or
    77  *  This code and its internal interfaces are subject to change or
    78  *  deletion without notice.</b>
    78  *  deletion without notice.</b>
    79  */
    79  */
    80 public class Resolve {
    80 public class Resolve {
    81     protected static final Context.Key<Resolve> resolveKey =
    81     protected static final Context.Key<Resolve> resolveKey = new Context.Key<>();
    82         new Context.Key<Resolve>();
       
    83 
    82 
    84     Names names;
    83     Names names;
    85     Log log;
    84     Log log;
    86     Symtab syms;
    85     Symtab syms;
    87     Attr attr;
    86     Attr attr;
   916 
   915 
   917         @Override
   916         @Override
   918         public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) {
   917         public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) {
   919             return new MostSpecificCheck(strict, actuals);
   918             return new MostSpecificCheck(strict, actuals);
   920         }
   919         }
   921     };
   920     }
   922 
   921 
   923     /**
   922     /**
   924      * Check context to be used during method applicability checks. A method check
   923      * Check context to be used during method applicability checks. A method check
   925      * context might contain inference variables.
   924      * context might contain inference variables.
   926      */
   925      */
  1614                         (flags & SYNTHETIC) == 0 &&
  1613                         (flags & SYNTHETIC) == 0 &&
  1615                         (abstractOk ||
  1614                         (abstractOk ||
  1616                         (flags & DEFAULT) != 0 ||
  1615                         (flags & DEFAULT) != 0 ||
  1617                         (flags & ABSTRACT) == 0);
  1616                         (flags & ABSTRACT) == 0);
  1618             }
  1617             }
  1619         };
  1618         }
  1620 
  1619 
  1621     /** Find best qualified method matching given name, type and value
  1620     /** Find best qualified method matching given name, type and value
  1622      *  arguments.
  1621      *  arguments.
  1623      *  @param env       The current environment.
  1622      *  @param env       The current environment.
  1624      *  @param site      The original type from where the selection
  1623      *  @param site      The original type from where the selection
  3778             for (Candidate c : resolveContext.candidates) {
  3777             for (Candidate c : resolveContext.candidates) {
  3779                 if (c.isApplicable()) continue;
  3778                 if (c.isApplicable()) continue;
  3780                 bestSoFar = c;
  3779                 bestSoFar = c;
  3781             }
  3780             }
  3782             Assert.checkNonNull(bestSoFar);
  3781             Assert.checkNonNull(bestSoFar);
  3783             return new Pair<Symbol, JCDiagnostic>(bestSoFar.sym, bestSoFar.details);
  3782             return new Pair<>(bestSoFar.sym, bestSoFar.details);
  3784         }
  3783         }
  3785     }
  3784     }
  3786 
  3785 
  3787     /**
  3786     /**
  3788      * ResolveError error class indicating that a set of symbols
  3787      * ResolveError error class indicating that a set of symbols
  3825                         methodArguments(argtypes));
  3824                         methodArguments(argtypes));
  3826                 return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(filteredCandidates, site));
  3825                 return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(filteredCandidates, site));
  3827             } else if (filteredCandidates.size() == 1) {
  3826             } else if (filteredCandidates.size() == 1) {
  3828                 Map.Entry<Symbol, JCDiagnostic> _e =
  3827                 Map.Entry<Symbol, JCDiagnostic> _e =
  3829                                 filteredCandidates.entrySet().iterator().next();
  3828                                 filteredCandidates.entrySet().iterator().next();
  3830                 final Pair<Symbol, JCDiagnostic> p = new Pair<Symbol, JCDiagnostic>(_e.getKey(), _e.getValue());
  3829                 final Pair<Symbol, JCDiagnostic> p = new Pair<>(_e.getKey(), _e.getValue());
  3831                 JCDiagnostic d = new InapplicableSymbolError(resolveContext) {
  3830                 JCDiagnostic d = new InapplicableSymbolError(resolveContext) {
  3832                     @Override
  3831                     @Override
  3833                     protected Pair<Symbol, JCDiagnostic> errCandidate() {
  3832                     protected Pair<Symbol, JCDiagnostic> errCandidate() {
  3834                         return p;
  3833                         return p;
  3835                     }
  3834                     }
  3844                     location, site, name, argtypes, typeargtypes);
  3843                     location, site, name, argtypes, typeargtypes);
  3845             }
  3844             }
  3846         }
  3845         }
  3847         //where
  3846         //where
  3848             private Map<Symbol, JCDiagnostic> mapCandidates() {
  3847             private Map<Symbol, JCDiagnostic> mapCandidates() {
  3849                 Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<Symbol, JCDiagnostic>();
  3848                 Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<>();
  3850                 for (Candidate c : resolveContext.candidates) {
  3849                 for (Candidate c : resolveContext.candidates) {
  3851                     if (c.isApplicable()) continue;
  3850                     if (c.isApplicable()) continue;
  3852                     candidates.put(c.sym, c.details);
  3851                     candidates.put(c.sym, c.details);
  3853                 }
  3852                 }
  3854                 return candidates;
  3853                 return candidates;
  3855             }
  3854             }
  3856 
  3855 
  3857             Map<Symbol, JCDiagnostic> filterCandidates(Map<Symbol, JCDiagnostic> candidatesMap) {
  3856             Map<Symbol, JCDiagnostic> filterCandidates(Map<Symbol, JCDiagnostic> candidatesMap) {
  3858                 Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<Symbol, JCDiagnostic>();
  3857                 Map<Symbol, JCDiagnostic> candidates = new LinkedHashMap<>();
  3859                 for (Map.Entry<Symbol, JCDiagnostic> _entry : candidatesMap.entrySet()) {
  3858                 for (Map.Entry<Symbol, JCDiagnostic> _entry : candidatesMap.entrySet()) {
  3860                     JCDiagnostic d = _entry.getValue();
  3859                     JCDiagnostic d = _entry.getValue();
  3861                     if (!new Template(MethodCheckDiag.ARITY_MISMATCH.regex()).matches(d)) {
  3860                     if (!new Template(MethodCheckDiag.ARITY_MISMATCH.regex()).matches(d)) {
  3862                         candidates.put(_entry.getKey(), d);
  3861                         candidates.put(_entry.getKey(), d);
  3863                     }
  3862                     }
  4173                 return true;
  4172                 return true;
  4174             }
  4173             }
  4175         };
  4174         };
  4176 
  4175 
  4177         /** rewriter map used for method resolution simplification */
  4176         /** rewriter map used for method resolution simplification */
  4178         static final Map<Template, DiagnosticRewriter> rewriters =
  4177         static final Map<Template, DiagnosticRewriter> rewriters = new LinkedHashMap<>();
  4179                 new LinkedHashMap<Template, DiagnosticRewriter>();
       
  4180 
  4178 
  4181         static {
  4179         static {
  4182             String argMismatchRegex = MethodCheckDiag.ARG_MISMATCH.regex();
  4180             String argMismatchRegex = MethodCheckDiag.ARG_MISMATCH.regex();
  4183             rewriters.put(new Template(argMismatchRegex, skip),
  4181             rewriters.put(new Template(argMismatchRegex, skip),
  4184                     new DiagnosticRewriter() {
  4182                     new DiagnosticRewriter() {