Warner warn)
throws Infer.InferenceException {
boolean polymorphicSignature = m.isPolymorphicSignatureGeneric() && allowMethodHandles;
if (useVarargs && (m.flags() & VARARGS) == 0)
throw inapplicableMethodException.setMessage();
Type mt = types.memberType(site, m);
// tvars is the list of formal type variables for which type arguments
// need to inferred.
List<Type> tvars = null;
if (env.info.tvars != null) {
tvars = types.newInstances(env.info.tvars);
mt = types.subst(mt, env.info.tvars, tvars);
}
if (typeargtypes == null) typeargtypes = List.nil();
if (mt.tag != FORALL && typeargtypes.nonEmpty()) {
// This is not a polymorphic method, but typeargs are supplied
// which is fine, see JLS 15.12.2.1
} else if (mt.tag == FORALL && typeargtypes.nonEmpty()) {
ForAll pmt = (ForAll) mt;
if (typeargtypes.length() != pmt.tvars.length())
throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args
// Check type arguments are within bounds
List<Type> formals = pmt.tvars;
List<Type> actuals = typeargtypes;
while (formals.nonEmpty() && actuals.nonEmpty()) {
List<Type> bounds = types.subst(types.getBounds((TypeVar)formals.head),
pmt.tvars, typeargtypes);
for (; bounds.nonEmpty(); bounds = bounds.tail)
if (!types.isSubtypeUnchecked(actuals.head, bounds.head, warn))
throw inapplicableMethodException.setMessage("explicit.param.do.not.conform.to.bounds",actuals.head, bounds);
formals = formals.tail;
actuals = actuals.tail;
}
mt = types.subst(pmt.qtype, pmt.tvars, typeargtypes);
} else if (mt.tag == FORALL) {
ForAll pmt = (ForAll) mt;
List<Type> tvars1 = types.newInstances(pmt.tvars);
tvars = tvars.appendList(tvars1);
mt = types.subst(pmt.qtype, pmt.tvars, tvars1);
}
// find out whether we need to go the slow route via infer
boolean instNeeded = tvars.tail != null || /*inlined: tvars.nonEmpty()*/
polymorphicSignature;
for (List<Type> l = argtypes;
l.tail != null/*inlined: l.nonEmpty()*/ && !instNeeded;
l = l.tail) {
if (l.head.tag == FORALL) instNeeded = true;
}
if (instNeeded)
return polymorphicSignature ?
infer.instantiatePolymorphicSignatureInstance(env, site, m.name, (MethodSymbol)m, argtypes) :
infer.instantiateMethod(env,
tvars,
(MethodType)mt,
m,
argtypes,
allowBoxing,
useVarargs,
warn);
checkRawArgumentsAcceptable(env, argtypes, mt.getParameterTypes(),
allowBoxing, useVarargs, warn);
return mt;
}