protected FunctionTypeReference processExpressionType(FunctionTypeReference incompleteClosureType, ITypeComputationResult expressionResult) { LightweightTypeReference expressionResultType = expressionResult.getReturnType(); if (expressionResultType == null || !expressionResultType.isPrimitiveVoid()) { FunctionTypeReference result = getFunctionTypeReference(false); LightweightTypeReference expectedReturnType = result.getTypeArguments().get(result.getTypeArguments().size() - 1); if (expressionResultType != null && !expressionResultType.isAny()) { result.setReturnType(expressionResultType); deferredBindTypeArgument(expectedReturnType, expressionResultType, BoundTypeArgumentSource.INFERRED); } else { LightweightTypeReference objectTypeReference = incompleteClosureType.getOwner().newReferenceToObject(); result.setReturnType(objectTypeReference); deferredBindTypeArgument(expectedReturnType, objectTypeReference, BoundTypeArgumentSource.INFERRED); } List<LightweightTypeReference> incompleteParameterTypes = incompleteClosureType.getParameterTypes(); for(int i = 0; i < incompleteParameterTypes.size(); i++) { result.addParameterType(incompleteParameterTypes.get(i)); } List<LightweightTypeReference> incompleteTypeArguments = incompleteClosureType.getTypeArguments(); List<LightweightTypeReference> resultTypeArguments = result.getTypeArguments(); for(int i = 0; i < incompleteTypeArguments.size(); i++) { deferredBindTypeArgument(resultTypeArguments.get(i), incompleteTypeArguments.get(i), BoundTypeArgumentSource.INFERRED); } return result; } else { incompleteClosureType.setReturnType(expressionResultType); return incompleteClosureType; } }
protected void prepareResultType() { resultClosureType = expectedClosureType.getOwner().newFunctionTypeReference(expectedClosureType.getType()); for (LightweightTypeReference argument : expectedClosureType.getTypeArguments()) { resultClosureType.addTypeArgument(argument); } }
protected void enhanceFunctionType(FunctionTypeReference reference, FunctionTypeReference result, Visiting visiting) { for(LightweightTypeReference parameterType: reference.getParameterTypes()) { result.addParameterType(visitTypeArgument(parameterType, visiting, true)); } for(LightweightTypeReference typeArgument: reference.getTypeArguments()) { result.addTypeArgument(visitTypeArgument(typeArgument, visiting)); } LightweightTypeReference returnType = reference.getReturnType(); if (returnType != null) { result.setReturnType(visitTypeArgument(returnType, visiting)); } }
protected ITypeComputationState assignParameters(ITypeAssigner typeAssigner, FunctionTypeReference incompleteClosureType) { List<LightweightTypeReference> operationParameterTypes = incompleteClosureType.getTypeArguments(); XClosure closure = getClosure(); boolean explicit = closure.isExplicitSyntax();
protected LocalTypeSubstitutor.SubstitutionResult doSubstituteFunctionType(FunctionTypeReference reference, FunctionTypeReference result, boolean didSubstitute) { for(LightweightTypeReference parameterType: reference.getParameterTypes()) { SubstitutionResult visited = visitTypeArgument(parameterType, VarianceInfo.IN); didSubstitute = didSubstitute || visited.didSubstitute; result.addParameterType(visited.typeReference); } for(LightweightTypeReference typeArgument: reference.getTypeArguments()) { SubstitutionResult visited = visitTypeArgument(typeArgument, VarianceInfo.INVARIANT); didSubstitute = didSubstitute || visited.didSubstitute; result.addTypeArgument(visited.typeReference); } LightweightTypeReference returnType = reference.getReturnType(); if (returnType != null) { SubstitutionResult visited = visitTypeArgument(returnType, VarianceInfo.OUT); didSubstitute = didSubstitute || visited.didSubstitute; result.setReturnType(visited.typeReference); } return new SubstitutionResult(result, didSubstitute); }