} else {
candidateMethod = null;
}
if (candidateMethod != null) {
boolean variableArity = candidateMethod.isVarargs();
InferenceContext18 infCtx = null;
if (candidateMethod instanceof ParameterizedMethodBinding) {
infCtx = invocation.getInferenceContext((ParameterizedMethodBinding) candidateMethod);
if (infCtx != null) {
if (infCtx.stepCompleted != InferenceContext18.TYPE_INFERRED) {
// only work in the exact state of TYPE_INFERRED
// - below we're not yet ready
// - above we're already done-done
return;
}
variableArity &= infCtx.isVarArgs(); // TODO: if no infCtx is available, do we have to re-check if this is a varargs invocation?
}
} else if (invocation instanceof AllocationExpression) {
if (((AllocationExpression)invocation).suspendedResolutionState != null)
return; // not yet ready
}
final TypeBinding[] parameters = candidateMethod.parameters;
Expression[] innerArguments = invocation.arguments();
Expression [] arguments = innerArguments;
if (infCtx == null && variableArity && parameters.length == arguments.length) { // re-check
TypeBinding lastParam = parameters[parameters.length-1];
Expression lastArg = arguments[arguments.length-1];
if (lastArg.isCompatibleWith(lastParam, null)) {
variableArity = false;
}
}
for (int i = 0, length = arguments == null ? 0 : arguments.length; i < length; i++) {
Expression argument = arguments[i];
TypeBinding updatedArgumentType = null;
TypeBinding parameterType = InferenceContext18.getParameter(parameters, i, variableArity);
if (parameterType == null && problemReason != ProblemReasons.NoError)
continue; // not much we can do without a target type, assume it only happens after some resolve error
if (argument instanceof LambdaExpression && ((LambdaExpression) argument).hasErrors())
continue; // don't update if inner poly has errors
if (argument instanceof Invocation) {
Invocation innerInvocation = (Invocation)argument;
MethodBinding binding = innerInvocation.binding(parameterType, true, scope);
if (binding instanceof ParameterizedGenericMethodBinding) {
ParameterizedGenericMethodBinding parameterizedMethod = (ParameterizedGenericMethodBinding) binding;
InferenceContext18 innerContext = innerInvocation.getInferenceContext(parameterizedMethod);
if (innerContext != null) {
if (!innerContext.hasResultFor(parameterType)) {
argument.setExpectedType(parameterType);
MethodBinding improvedBinding = innerContext.inferInvocationType(innerInvocation, parameterizedMethod);
if (!improvedBinding.isValidBinding()) {
innerContext.reportInvalidInvocation(innerInvocation, improvedBinding);
}
if (innerInvocation.updateBindings(improvedBinding, parameterType)) {
resolvePolyExpressionArguments(innerInvocation, improvedBinding, scope);
}
} else if (innerContext.stepCompleted < InferenceContext18.BINDINGS_UPDATED) {
innerContext.rebindInnerPolies(parameterizedMethod, innerInvocation);
}
}
continue; // otherwise these have been dealt with during inner method lookup
}
}