コード例 #1
0
  @NotNull
  public JetTypeInfo getSimpleNameExpressionTypeInfo(
      @NotNull JetSimpleNameExpression nameExpression,
      @NotNull ReceiverValue receiver,
      @Nullable ASTNode callOperationNode,
      @NotNull ResolutionContext context) {
    boolean[] result = new boolean[1];

    TemporaryBindingTrace traceForVariable =
        TemporaryBindingTrace.create(context.trace, "trace to resolve as variable", nameExpression);
    JetType type =
        getVariableType(
            nameExpression,
            receiver,
            callOperationNode,
            context.replaceBindingTrace(traceForVariable),
            result);
    if (result[0]) {
      traceForVariable.commit();
      if (type instanceof NamespaceType && context.expressionPosition == ExpressionPosition.FREE) {
        type = null;
      }
      return JetTypeInfo.create(type, context.dataFlowInfo);
    }

    Call call =
        CallMaker.makeCall(
            nameExpression,
            receiver,
            callOperationNode,
            nameExpression,
            Collections.<ValueArgument>emptyList());
    TemporaryBindingTrace traceForFunction =
        TemporaryBindingTrace.create(context.trace, "trace to resolve as function", nameExpression);
    ResolvedCall<FunctionDescriptor> resolvedCall =
        getResolvedCallForFunction(
            call,
            nameExpression,
            receiver,
            context,
            ResolveMode.TOP_LEVEL_CALL,
            ResolutionResultsCache.create(),
            result);
    if (result[0]) {
      FunctionDescriptor functionDescriptor =
          resolvedCall != null ? resolvedCall.getResultingDescriptor() : null;
      traceForFunction.commit();
      boolean hasValueParameters =
          functionDescriptor == null || functionDescriptor.getValueParameters().size() > 0;
      context.trace.report(
          FUNCTION_CALL_EXPECTED.on(nameExpression, nameExpression, hasValueParameters));
      type = functionDescriptor != null ? functionDescriptor.getReturnType() : null;
      return JetTypeInfo.create(type, context.dataFlowInfo);
    }

    traceForVariable.commit();
    return JetTypeInfo.create(null, context.dataFlowInfo);
  }
コード例 #2
0
  @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;
  }