コード例 #1
0
ファイル: BodyResolver.java プロジェクト: abond/kotlin
  public void resolveFunctionBody(
      @NotNull DataFlowInfo outerDataFlowInfo,
      @NotNull BindingTrace trace,
      @NotNull JetDeclarationWithBody function,
      @NotNull FunctionDescriptor functionDescriptor,
      @NotNull LexicalScope declaringScope) {
    computeDeferredType(functionDescriptor.getReturnType());

    resolveFunctionBody(
        outerDataFlowInfo,
        trace,
        function,
        functionDescriptor,
        declaringScope,
        null,
        CallChecker.DoNothing.INSTANCE$);

    assert functionDescriptor.getReturnType() != null;
  }
コード例 #2
0
  @NotNull
  private static KotlinType getFunctionExpectedReturnType(
      @NotNull FunctionDescriptor descriptor,
      @NotNull KtElement function,
      @NotNull ExpressionTypingContext context) {
    KotlinType expectedType;
    if (function instanceof KtSecondaryConstructor) {
      expectedType = DescriptorUtilsKt.getBuiltIns(descriptor).getUnitType();
    } else if (function instanceof KtFunction) {
      KtFunction ktFunction = (KtFunction) function;
      expectedType = context.trace.get(EXPECTED_RETURN_TYPE, ktFunction);

      if ((expectedType == null)
          && (ktFunction.getTypeReference() != null || ktFunction.hasBlockBody())) {
        expectedType = descriptor.getReturnType();
      }
    } else {
      expectedType = descriptor.getReturnType();
    }
    return expectedType != null ? expectedType : TypeUtils.NO_EXPECTED_TYPE;
  }
コード例 #3
0
ファイル: BodyResolver.java プロジェクト: abond/kotlin
  public void resolveFunctionBody(
      @NotNull DataFlowInfo outerDataFlowInfo,
      @NotNull BindingTrace trace,
      @NotNull JetDeclarationWithBody function,
      @NotNull FunctionDescriptor functionDescriptor,
      @NotNull LexicalScope scope,
      @Nullable Function1<LexicalScope, DataFlowInfo> beforeBlockBody,
      @NotNull CallChecker callChecker) {
    LexicalScope innerScope =
        FunctionDescriptorUtil.getFunctionInnerScope(scope, functionDescriptor, trace);
    List<JetParameter> valueParameters = function.getValueParameters();
    List<ValueParameterDescriptor> valueParameterDescriptors =
        functionDescriptor.getValueParameters();

    valueParameterResolver.resolveValueParameters(
        valueParameters,
        valueParameterDescriptors,
        ExpressionTypingContext.newContext(
            trace, innerScope, outerDataFlowInfo, NO_EXPECTED_TYPE, callChecker));

    // Synthetic "field" creation
    if (functionDescriptor instanceof PropertyAccessorDescriptor) {
      PropertyAccessorDescriptor accessorDescriptor =
          (PropertyAccessorDescriptor) functionDescriptor;
      JetProperty property = (JetProperty) function.getParent();
      final SyntheticFieldDescriptor fieldDescriptor =
          new SyntheticFieldDescriptor(accessorDescriptor, property);
      innerScope =
          new LexicalScopeImpl(
              innerScope,
              functionDescriptor,
              true,
              functionDescriptor.getExtensionReceiverParameter(),
              "Accessor inner scope with synthetic field",
              RedeclarationHandler.DO_NOTHING,
              new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
                @Override
                public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
                  handler.addVariableOrClassDescriptor(fieldDescriptor);
                  return Unit.INSTANCE$;
                }
              });
      // Check parameter name shadowing
      for (JetParameter parameter : function.getValueParameters()) {
        if (SyntheticFieldDescriptor.NAME.equals(parameter.getNameAsName())) {
          trace.report(Errors.ACCESSOR_PARAMETER_NAME_SHADOWING.on(parameter));
        }
      }
    }

    DataFlowInfo dataFlowInfo = null;

    if (beforeBlockBody != null) {
      dataFlowInfo = beforeBlockBody.invoke(innerScope);
    }

    if (function.hasBody()) {
      expressionTypingServices.checkFunctionReturnType(
          innerScope,
          function,
          functionDescriptor,
          dataFlowInfo != null ? dataFlowInfo : outerDataFlowInfo,
          null,
          trace);
    }

    assert functionDescriptor.getReturnType() != null;
  }