Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.calls.results
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromCallableReflectionType
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.UnwrappedType
fun FlatSignature.Companion.createFromReflectionType(
origin: T,
descriptor: CallableDescriptor,
numDefaults: Int,
// Reflection type for callable references with bound receiver doesn't contain receiver type
hasBoundExtensionReceiver: Boolean,
reflectionType: UnwrappedType
): FlatSignature {
// Note that receiver is taking over descriptor, not reflection type
// This is correct as extension receiver can't have any defaults/varargs/coercions, so there is no need to use reflection type
// Plus, currently, receiver for reflection type is taking from *candidate*, see buildReflectionType, this candidate can
// have transient receiver which is not the same in its signature
val receiver = descriptor.extensionReceiverParameter?.type
val parameters = reflectionType.getValueParameterTypesFromCallableReflectionType(
receiver != null && !hasBoundExtensionReceiver
).map { it.type }
return FlatSignature(
origin,
descriptor.typeParameters,
listOfNotNull(receiver) + parameters,
hasExtensionReceiver = receiver != null,
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
numDefaults = numDefaults,
isExpect = descriptor is MemberDescriptor && descriptor.isExpect,
isSyntheticMember = descriptor is SyntheticMemberDescriptor<*>
)
}
fun FlatSignature.Companion.create(
origin: T,
descriptor: CallableDescriptor,
numDefaults: Int,
parameterTypes: List
): FlatSignature {
val extensionReceiverType = descriptor.extensionReceiverParameter?.type
return FlatSignature(
origin,
descriptor.typeParameters,
valueParameterTypes =
listOfNotNull(extensionReceiverType) + parameterTypes,
hasExtensionReceiver = extensionReceiverType != null,
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
numDefaults = numDefaults,
isExpect = descriptor is MemberDescriptor && descriptor.isExpect,
isSyntheticMember = descriptor is SyntheticMemberDescriptor<*>
)
}
fun FlatSignature.Companion.createFromCallableDescriptor(
descriptor: D
): FlatSignature =
create(descriptor, descriptor, numDefaults = 0, parameterTypes = descriptor.valueParameters.map { it.argumentValueType })
fun FlatSignature.Companion.createForPossiblyShadowedExtension(descriptor: D): FlatSignature =
FlatSignature(
descriptor,
descriptor.typeParameters,
valueParameterTypes = descriptor.valueParameters.map { it.argumentValueType },
hasExtensionReceiver = false,
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
numDefaults = descriptor.valueParameters.count { it.hasDefaultValue() },
isExpect = descriptor is MemberDescriptor && descriptor.isExpect,
isSyntheticMember = descriptor is SyntheticMemberDescriptor<*>
)
val ValueParameterDescriptor.argumentValueType get() = varargElementType ?: type