From 66e89280b699783748e0d1b37e5b230ef535c6ee Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 18 Mar 2013 15:49:40 +0400 Subject: [PATCH] refactoring (simplified recordReferenceForInvokeFunction, isExpressionWithValidReference) --- .../jet/lang/resolve/BindingContextUtils.java | 10 +++----- .../lang/resolve/calls/CandidateResolver.java | 25 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java index 8c1fdb40933..c70e27d8ac4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java @@ -310,15 +310,11 @@ public class BindingContextUtils { @NotNull JetExpression expression, @NotNull BindingContext context ) { - if (!(expression instanceof JetReferenceExpression)) { - return false; + if (expression instanceof JetCallExpression) { + return isCallExpressionWithValidReference(expression, context); } - if (!(expression instanceof JetCallExpression)) { - return true; - } - - return isCallExpressionWithValidReference(expression, context); + return expression instanceof JetReferenceExpression; } public static boolean isCallExpressionWithValidReference( diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index acb9585636f..0af3abff508 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -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.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.CallTransformer.CallForImplicitInvoke; import static org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus.*; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; @@ -329,19 +330,15 @@ public class CandidateResolver { recordReferenceForInvokeFunction(context); } - private void recordReferenceForInvokeFunction(CallCandidateResolutionContext context) { - // TODO Replace using CallForImplicitInvoke - JetExpression calleeExpression = context.call.getCalleeExpression(); - if (calleeExpression != null) { - PsiElement parent = calleeExpression.getParent(); - if (parent instanceof JetCallExpression) { - JetCallExpression callExpression = (JetCallExpression) parent; - if (BindingContextUtils.isCallExpressionWithValidReference(callExpression, context.trace.getBindingContext())) { - CallableDescriptor resultingDescriptor = context.candidateCall.getResultingDescriptor(); - context.trace.record(BindingContext.EXPRESSION_TYPE, callExpression, resultingDescriptor.getReturnType()); - context.trace.record(BindingContext.REFERENCE_TARGET, callExpression, resultingDescriptor); - } - } + private static void recordReferenceForInvokeFunction(CallCandidateResolutionContext context) { + PsiElement callElement = context.call.getCallElement(); + if (!(callElement instanceof JetCallExpression)) return; + + JetCallExpression callExpression = (JetCallExpression) callElement; + CallableDescriptor resultingDescriptor = context.candidateCall.getResultingDescriptor(); + if (BindingContextUtils.isCallExpressionWithValidReference(callExpression, context.trace.getBindingContext())) { + 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.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 - context.call instanceof CallTransformer.CallForImplicitInvoke)); + context.call instanceof CallForImplicitInvoke)); return new ValueArgumentsCheckingResult(resultStatus, checkingResult.argumentTypes); }