if (target instanceof MemberReferenceExpression) {
target = ((MemberReferenceExpression) target).getTarget();
}
final ResolveResult targetResult = _resolver.apply(target);
if (targetResult != null && targetResult.getType() != null) {
method = MetadataHelper.asMemberOf(method, targetResult.getType());
}
final List<ParameterDefinition> parameters = method.getParameters();
final AstNodeCollection<Expression> arguments = parent.getChildrenByRole(Roles.ARGUMENT);
final int argumentPosition = firstIndexWhere(
arguments,
new Predicate<Expression>() {
@Override
public boolean test(final Expression e) {
return e == node;
}
}
);
if (argumentPosition < 0) {
return;
}
int parameterPosition = 0;
while (parameterPosition < parameters.size() && parameters.get(parameterPosition).isSynthetic()) {
++parameterPosition;
}
parameterPosition += argumentPosition;
if (parameterPosition < 0 || parameterPosition >= parameters.size()) {
return;
}
final ConversionType valueToCast = MetadataHelper.getConversionType(castType, valueType);
if (valueToCast == ConversionType.IDENTITY) {
//
// T t; f((T)t) => f(t)
//
value.remove();
node.replaceWith(value);
return;
}
final ParameterDefinition parameter = parameters.get(parameterPosition);
final TypeReference targetType = parameter.getParameterType();
final ConversionType castToTarget = MetadataHelper.getConversionType(targetType, castType);
if (castToTarget != ConversionType.IDENTITY && castToTarget != ConversionType.IMPLICIT) {
return;
}
final ConversionType valueToTarget = MetadataHelper.getConversionType(targetType, valueType);
if (valueToTarget != ConversionType.IMPLICIT) {
return;
}
final List<TypeReference> argumentTypes = new ArrayList<>();
final int syntheticParameters = parameterPosition - argumentPosition;
for (int j = 0; j < syntheticParameters; j++) {
argumentTypes.add(parameters.get(j).getParameterType());
}
for (final Expression argument : arguments) {
final ResolveResult argumentResult = _resolver.apply(argument);
if (argumentResult == null || argumentResult.getType() == null) {
return;
}
argumentTypes.add(argumentResult.getType());
}
final TypeReference declaringType = method.getDeclaringType();
final List<MethodReference> candidates = MetadataHelper.findMethods(