@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;
  }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
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);
  }