715 List<Type> argtypes, |
715 List<Type> argtypes, |
716 List<Type> formals, |
716 List<Type> formals, |
717 Warner warn) { |
717 Warner warn) { |
718 //should we expand formals? |
718 //should we expand formals? |
719 boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); |
719 boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); |
720 List<JCExpression> trees = TreeInfo.args(env.tree); |
720 JCTree callTree = treeForDiagnostics(env); |
|
721 List<JCExpression> trees = TreeInfo.args(callTree); |
721 |
722 |
722 //inference context used during this method check |
723 //inference context used during this method check |
723 InferenceContext inferenceContext = deferredAttrContext.inferenceContext; |
724 InferenceContext inferenceContext = deferredAttrContext.inferenceContext; |
724 |
725 |
725 Type varargsFormal = useVarargs ? formals.last() : null; |
726 Type varargsFormal = useVarargs ? formals.last() : null; |
726 |
727 |
727 if (varargsFormal == null && |
728 if (varargsFormal == null && |
728 argtypes.size() != formals.size()) { |
729 argtypes.size() != formals.size()) { |
729 reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args |
730 reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args |
730 } |
731 } |
731 |
732 |
732 while (argtypes.nonEmpty() && formals.head != varargsFormal) { |
733 while (argtypes.nonEmpty() && formals.head != varargsFormal) { |
733 DiagnosticPosition pos = trees != null ? trees.head : null; |
734 DiagnosticPosition pos = trees != null ? trees.head : null; |
734 checkArg(pos, false, argtypes.head, formals.head, deferredAttrContext, warn); |
735 checkArg(pos, false, argtypes.head, formals.head, deferredAttrContext, warn); |
736 formals = formals.tail; |
737 formals = formals.tail; |
737 trees = trees != null ? trees.tail : trees; |
738 trees = trees != null ? trees.tail : trees; |
738 } |
739 } |
739 |
740 |
740 if (formals.head != varargsFormal) { |
741 if (formals.head != varargsFormal) { |
741 reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args |
742 reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args |
742 } |
743 } |
743 |
744 |
744 if (useVarargs) { |
745 if (useVarargs) { |
745 //note: if applicability check is triggered by most specific test, |
746 //note: if applicability check is triggered by most specific test, |
746 //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) |
747 //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) |
751 argtypes = argtypes.tail; |
752 argtypes = argtypes.tail; |
752 trees = trees != null ? trees.tail : trees; |
753 trees = trees != null ? trees.tail : trees; |
753 } |
754 } |
754 } |
755 } |
755 } |
756 } |
|
757 |
|
758 // where |
|
759 private JCTree treeForDiagnostics(Env<AttrContext> env) { |
|
760 return env.info.preferredTreeForDiagnostics != null ? env.info.preferredTreeForDiagnostics : env.tree; |
|
761 } |
756 |
762 |
757 /** |
763 /** |
758 * Does the actual argument conforms to the corresponding formal? |
764 * Does the actual argument conforms to the corresponding formal? |
759 */ |
765 */ |
760 abstract void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn); |
766 abstract void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn); |
1826 Symbol sym; |
1832 Symbol sym; |
1827 Env<AttrContext> env1 = env; |
1833 Env<AttrContext> env1 = env; |
1828 boolean staticOnly = false; |
1834 boolean staticOnly = false; |
1829 while (env1.outer != null) { |
1835 while (env1.outer != null) { |
1830 if (isStatic(env1)) staticOnly = true; |
1836 if (isStatic(env1)) staticOnly = true; |
1831 sym = findMethod( |
1837 Assert.check(env1.info.preferredTreeForDiagnostics == null); |
1832 env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, |
1838 env1.info.preferredTreeForDiagnostics = env.tree; |
1833 allowBoxing, useVarargs, false); |
1839 try { |
1834 if (sym.exists()) { |
1840 sym = findMethod( |
1835 if (staticOnly && |
1841 env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, |
1836 sym.kind == MTH && |
1842 allowBoxing, useVarargs, false); |
1837 sym.owner.kind == TYP && |
1843 if (sym.exists()) { |
1838 (sym.flags() & STATIC) == 0) return new StaticError(sym); |
1844 if (staticOnly && |
1839 else return sym; |
1845 sym.kind == MTH && |
1840 } else if (sym.kind < bestSoFar.kind) { |
1846 sym.owner.kind == TYP && |
1841 bestSoFar = sym; |
1847 (sym.flags() & STATIC) == 0) return new StaticError(sym); |
|
1848 else return sym; |
|
1849 } else if (sym.kind < bestSoFar.kind) { |
|
1850 bestSoFar = sym; |
|
1851 } |
|
1852 } finally { |
|
1853 env1.info.preferredTreeForDiagnostics = null; |
1842 } |
1854 } |
1843 if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
1855 if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; |
1844 env1 = env1.outer; |
1856 env1 = env1.outer; |
1845 } |
1857 } |
1846 |
1858 |
4212 @Override |
4224 @Override |
4213 public JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, |
4225 public JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, |
4214 DiagnosticPosition preferedPos, DiagnosticSource preferredSource, |
4226 DiagnosticPosition preferedPos, DiagnosticSource preferredSource, |
4215 DiagnosticType preferredKind, JCDiagnostic d) { |
4227 DiagnosticType preferredKind, JCDiagnostic d) { |
4216 JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0]; |
4228 JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0]; |
4217 return diags.create(preferredKind, preferredSource, d.getDiagnosticPosition(), |
4229 DiagnosticPosition pos = d.getDiagnosticPosition(); |
|
4230 if (pos == null) { |
|
4231 pos = preferedPos; |
|
4232 } |
|
4233 return diags.create(preferredKind, preferredSource, pos, |
4218 "prob.found.req", cause); |
4234 "prob.found.req", cause); |
4219 } |
4235 } |
4220 }); |
4236 }); |
4221 } |
4237 } |
4222 } |
4238 } |