refactoring

(simplified recordReferenceForInvokeFunction, isExpressionWithValidReference)
This commit is contained in:
Svetlana Isakova
2013-03-18 15:49:40 +04:00
parent 8768d669ae
commit 66e89280b6
2 changed files with 14 additions and 21 deletions
@@ -310,15 +310,11 @@ public class BindingContextUtils {
@NotNull JetExpression expression, @NotNull JetExpression expression,
@NotNull BindingContext context @NotNull BindingContext context
) { ) {
if (!(expression instanceof JetReferenceExpression)) { if (expression instanceof JetCallExpression) {
return false; return isCallExpressionWithValidReference(expression, context);
} }
if (!(expression instanceof JetCallExpression)) { return expression instanceof JetReferenceExpression;
return true;
}
return isCallExpressionWithValidReference(expression, context);
} }
public static boolean isCallExpressionWithValidReference( public static boolean isCallExpressionWithValidReference(
@@ -59,6 +59,7 @@ import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.DONT_CARE;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.PLACEHOLDER_FUNCTION_TYPE; import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.PLACEHOLDER_FUNCTION_TYPE;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS; import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.SKIP_FUNCTION_ARGUMENTS; import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.SKIP_FUNCTION_ARGUMENTS;
import static org.jetbrains.jet.lang.resolve.calls.CallTransformer.CallForImplicitInvoke;
import static org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus.*; import static org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus.*;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
@@ -329,19 +330,15 @@ public class CandidateResolver {
recordReferenceForInvokeFunction(context); recordReferenceForInvokeFunction(context);
} }
private <D extends CallableDescriptor> void recordReferenceForInvokeFunction(CallCandidateResolutionContext<D> context) { private static <D extends CallableDescriptor> void recordReferenceForInvokeFunction(CallCandidateResolutionContext<D> context) {
// TODO Replace using CallForImplicitInvoke PsiElement callElement = context.call.getCallElement();
JetExpression calleeExpression = context.call.getCalleeExpression(); if (!(callElement instanceof JetCallExpression)) return;
if (calleeExpression != null) {
PsiElement parent = calleeExpression.getParent(); JetCallExpression callExpression = (JetCallExpression) callElement;
if (parent instanceof JetCallExpression) { CallableDescriptor resultingDescriptor = context.candidateCall.getResultingDescriptor();
JetCallExpression callExpression = (JetCallExpression) parent; if (BindingContextUtils.isCallExpressionWithValidReference(callExpression, context.trace.getBindingContext())) {
if (BindingContextUtils.isCallExpressionWithValidReference(callExpression, context.trace.getBindingContext())) { context.trace.record(BindingContext.EXPRESSION_TYPE, callExpression, resultingDescriptor.getReturnType());
CallableDescriptor resultingDescriptor = context.candidateCall.getResultingDescriptor(); context.trace.record(BindingContext.REFERENCE_TARGET, callExpression, resultingDescriptor);
context.trace.record(BindingContext.EXPRESSION_TYPE, callExpression, resultingDescriptor.getReturnType());
context.trace.record(BindingContext.REFERENCE_TARGET, callExpression, resultingDescriptor);
}
}
} }
} }
@@ -524,7 +521,7 @@ public class CandidateResolver {
candidateCall.getResultingDescriptor().getExpectedThisObject(), candidateCall.getThisObject(), candidateCall.getResultingDescriptor().getExpectedThisObject(), candidateCall.getThisObject(),
candidateCall.getExplicitReceiverKind().isThisObject(), candidateCall.getExplicitReceiverKind().isThisObject(),
// for the invocation 'foo(1)' where foo is a variable of function type we should mark 'foo' if there is unsafe call error // for the invocation 'foo(1)' where foo is a variable of function type we should mark 'foo' if there is unsafe call error
context.call instanceof CallTransformer.CallForImplicitInvoke)); context.call instanceof CallForImplicitInvoke));
return new ValueArgumentsCheckingResult(resultStatus, checkingResult.argumentTypes); return new ValueArgumentsCheckingResult(resultStatus, checkingResult.argumentTypes);
} }