@Nullable
  private ResolvedCall<FunctionDescriptor> getResolvedCallForFunction(
      @NotNull Call call,
      @NotNull JetExpression callExpression,
      @NotNull ReceiverValue receiver,
      @NotNull ResolutionContext context,
      @NotNull ResolveMode resolveMode,
      @NotNull boolean[] result) {

    CallResolver callResolver = expressionTypingServices.getCallResolver();
    OverloadResolutionResults<FunctionDescriptor> results =
        callResolver.resolveFunctionCall(
            BasicCallResolutionContext.create(context, call, resolveMode));
    if (!results.isNothing()) {
      checkSuper(receiver, results, context.trace, callExpression);
      result[0] = true;
      if (results.isSingleResult() && resolveMode == ResolveMode.TOP_LEVEL_CALL) {
        if (CallResolverUtil.hasReturnTypeDependentOnNotInferredParams(
            results.getResultingCall())) {
          return null;
        }
      }
      return results.isSingleResult() ? results.getResultingCall() : null;
    }
    result[0] = false;
    return null;
  }
  @Nullable
  private JetType getVariableType(
      @NotNull JetSimpleNameExpression nameExpression,
      @NotNull ReceiverValue receiver,
      @Nullable ASTNode callOperationNode,
      @NotNull ResolutionContext context,
      @NotNull boolean[] result) {
    TemporaryBindingTrace traceForVariable =
        TemporaryBindingTrace.create(
            context.trace, "trace to resolve as local variable or property", nameExpression);
    CallResolver callResolver = expressionTypingServices.getCallResolver();
    Call call = CallMaker.makePropertyCall(receiver, callOperationNode, nameExpression);
    OverloadResolutionResults<VariableDescriptor> resolutionResult =
        callResolver.resolveSimpleProperty(
            BasicCallResolutionContext.create(
                context.replaceBindingTrace(traceForVariable),
                call,
                ResolveMode.TOP_LEVEL_CALL,
                ResolutionResultsCache.create()));
    if (!resolutionResult.isNothing()) {
      traceForVariable.commit();
      checkSuper(receiver, resolutionResult, context.trace, nameExpression);
      result[0] = true;
      return resolutionResult.isSingleResult()
          ? resolutionResult.getResultingDescriptor().getReturnType()
          : null;
    }

    ResolutionContext newContext =
        receiver.exists() ? context.replaceScope(receiver.getType().getMemberScope()) : context;
    TemporaryBindingTrace traceForNamespaceOrClassObject =
        TemporaryBindingTrace.create(
            context.trace, "trace to resolve as namespace or class object", nameExpression);
    JetType jetType =
        lookupNamespaceOrClassObject(
            nameExpression, newContext.replaceBindingTrace(traceForNamespaceOrClassObject));
    if (jetType != null) {
      traceForNamespaceOrClassObject.commit();

      // Uncommitted changes in temp context
      context.trace.record(RESOLUTION_SCOPE, nameExpression, context.scope);
      if (context.dataFlowInfo.hasTypeInfoConstraints()) {
        context.trace.record(
            NON_DEFAULT_EXPRESSION_DATA_FLOW, nameExpression, context.dataFlowInfo);
      }
      result[0] = true;
      return jetType;
    }
    result[0] = false;
    return null;
  }
예제 #3
0
  private <D extends CallableDescriptor, F extends D>
      OverloadResolutionResultsImpl<F> doResolveCallOrGetCachedResults(
          @NotNull ResolutionResultsCache.MemberType<F> memberType,
          @NotNull BasicCallResolutionContext context,
          @NotNull List<ResolutionTask<D, F>> prioritizedTasks,
          @NotNull CallTransformer<D, F> callTransformer,
          @NotNull JetReferenceExpression reference) {
    OverloadResolutionResultsImpl<F> results = null;
    TracingStrategy tracing =
        prioritizedTasks.isEmpty()
            ? TracingStrategy.EMPTY
            : prioritizedTasks.iterator().next().tracing;
    TemporaryBindingTrace traceToResolveCall =
        TemporaryBindingTrace.create(context.trace, "trace to resolve call", context.call);
    CallKey callKey = CallResolverUtil.createCallKey(context);
    if (callKey != null) {
      OverloadResolutionResultsImpl<F> cachedResults =
          context.resolutionResultsCache.getResolutionResults(callKey, memberType);
      if (cachedResults != null) {
        DelegatingBindingTrace deltasTraceForResolve =
            context.resolutionResultsCache.getResolutionTrace(callKey);
        assert deltasTraceForResolve != null;
        deltasTraceForResolve.addAllMyDataTo(traceToResolveCall);
        results = cachedResults;
      }
    }
    if (results == null) {
      BasicCallResolutionContext newContext = context.replaceBindingTrace(traceToResolveCall);
      results = doResolveCall(newContext, prioritizedTasks, callTransformer, reference);
      DelegatingBindingTrace deltasTraceForTypeInference =
          ((OverloadResolutionResultsImpl) results).getTrace();
      if (deltasTraceForTypeInference != null) {
        deltasTraceForTypeInference.addAllMyDataTo(traceToResolveCall);
      }
      completeTypeInferenceDependentOnFunctionLiterals(newContext, results, tracing);
      cacheResults(memberType, context, results, traceToResolveCall, tracing);
    }
    traceToResolveCall.commit();

    if (!prioritizedTasks.isEmpty() && context.contextDependency == ContextDependency.INDEPENDENT) {
      results = completeTypeInferenceDependentOnExpectedType(context, results, tracing);
    }

    if (extension != null) {
      extension.run(results, context);
    }

    return results;
  }
예제 #4
0
 @NotNull
 public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(
     @NotNull BindingTrace trace,
     @NotNull JetScope scope,
     @NotNull Call call,
     @NotNull JetType expectedType,
     @NotNull DataFlowInfo dataFlowInfo) {
   return resolveFunctionCall(
       BasicCallResolutionContext.create(
           trace,
           scope,
           call,
           expectedType,
           dataFlowInfo,
           ContextDependency.INDEPENDENT,
           CheckValueArgumentsMode.ENABLED,
           ExpressionPosition.FREE,
           ResolutionResultsCacheImpl.create(),
           LabelResolver.create(),
           null));
 }
예제 #5
0
  public OverloadResolutionResults<FunctionDescriptor> resolveCallWithKnownCandidate(
      @NotNull Call call,
      @Nullable TracingStrategy tracing,
      @NotNull JetReferenceExpression reference,
      @NotNull ResolutionContext<?> context,
      @NotNull ResolutionCandidate<CallableDescriptor> candidate,
      @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments) {
    BasicCallResolutionContext basicCallResolutionContext =
        BasicCallResolutionContext.create(
            context, call, CheckValueArgumentsMode.ENABLED, dataFlowInfoForArguments);

    List<ResolutionTask<CallableDescriptor, FunctionDescriptor>> tasks =
        TaskPrioritizer
            .<CallableDescriptor, FunctionDescriptor>computePrioritizedTasksFromCandidates(
                basicCallResolutionContext, reference, Collections.singleton(candidate), tracing);
    return doResolveCallOrGetCachedResults(
        ResolutionResultsCache.FUNCTION_MEMBER_TYPE,
        basicCallResolutionContext,
        tasks,
        CallTransformer.FUNCTION_CALL_TRANSFORMER,
        reference);
  }