public DataClassMethodGenerator(JetClassOrObject declaration, BindingContext bindingContext) { this.declaration = declaration; this.bindingContext = bindingContext; this.classDescriptor = BindingContextUtils.getNotNull(bindingContext, BindingContext.CLASS, declaration); this.builtIns = DescriptorUtilsKt.getBuiltIns(classDescriptor); }
@NotNull public Collection<KotlinType> getSupertypesForClosure(@NotNull FunctionDescriptor descriptor) { ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter(); //noinspection ConstantConditions KotlinType functionType = DescriptorUtilsKt.getBuiltIns(descriptor) .getFunctionType( Annotations.Companion.getEMPTY(), receiverParameter == null ? null : receiverParameter.getType(), ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()), descriptor.getReturnType()); return Arrays.asList(lambda.getDefaultType(), functionType); }
@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; }
@NotNull public Collection<KotlinType> getSupertypesForFunctionReference( @NotNull FunctionDescriptor descriptor) { ReceiverParameterDescriptor extensionReceiver = descriptor.getExtensionReceiverParameter(); ReceiverParameterDescriptor dispatchReceiver = descriptor.getDispatchReceiverParameter(); KotlinType receiverType = extensionReceiver != null ? extensionReceiver.getType() : dispatchReceiver != null ? dispatchReceiver.getType() : null; //noinspection ConstantConditions KotlinType functionType = DescriptorUtilsKt.getBuiltIns(descriptor) .getFunctionType( Annotations.Companion.getEMPTY(), receiverType, ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()), descriptor.getReturnType()); return Arrays.asList(functionReference.getDefaultType(), functionType); }