Completion: multiple extension methods with different substitutions may be shown

This commit is contained in:
Valentin Kipyatkov
2014-12-02 13:57:13 +03:00
parent 2c08b3e229
commit 1d288e6dcc
9 changed files with 56 additions and 25 deletions
@@ -133,7 +133,7 @@ public class ReferenceVariantsHelper(
for (descriptor in resolutionScope.getDescriptorsFiltered(kindFilter, nameFilter)) {
if (descriptor is CallableDescriptor && descriptor.getExtensionReceiverParameter() != null) {
descriptorsSet.addIfNotNull(descriptor.substituteExtensionIfCallable(receiverValues, context, dataFlowInfo, false))
descriptorsSet.addAll(descriptor.substituteExtensionIfCallable(receiverValues, context, dataFlowInfo, false))
}
else {
descriptorsSet.add(descriptor)
@@ -201,8 +201,7 @@ public class ReferenceVariantsHelper(
) {
if (!kindFilter.excludes.contains(DescriptorKindExclude.Extensions)) {
for (callable in resolutionScope.getDescriptorsFiltered(kindFilter.exclude(DescriptorKindExclude.NonExtensions), nameFilter)) {
val substituted = (callable as CallableDescriptor).substituteExtensionIfCallable(receiver, isInfixCall, context, dataFlowInfo)
addIfNotNull(substituted)
addAll((callable as CallableDescriptor).substituteExtensionIfCallable(receiver, isInfixCall, context, dataFlowInfo))
}
}
}
@@ -35,18 +35,14 @@ import java.util.HashSet
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor
import org.jetbrains.jet.lang.types.TypeSubstitutor
//TODO: what if multiple receiver types match? this can result in different substitutions
public fun CallableDescriptor.substituteExtensionIfCallable(receivers: Collection<ReceiverValue>,
context: BindingContext,
dataFlowInfo: DataFlowInfo,
isInfixCall: Boolean): CallableDescriptor? {
return receivers.stream()
.map { substituteExtensionIfCallable(it, isInfixCall, context, dataFlowInfo) }
.firstOrNull { it != null }
isInfixCall: Boolean): Collection<CallableDescriptor> {
return receivers.flatMap { substituteExtensionIfCallable(it, isInfixCall, context, dataFlowInfo) }
}
public fun CallableDescriptor.substituteExtensionIfCallableWithImplicitReceiver(scope: JetScope, context: BindingContext, dataFlowInfo: DataFlowInfo): CallableDescriptor?
public fun CallableDescriptor.substituteExtensionIfCallableWithImplicitReceiver(scope: JetScope, context: BindingContext, dataFlowInfo: DataFlowInfo): Collection<CallableDescriptor>
= substituteExtensionIfCallable(scope.getImplicitReceiversHierarchy().map { it.getValue() }, context, dataFlowInfo, false)
public fun CallableDescriptor.substituteExtensionIfCallable(
@@ -54,21 +50,18 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
isInfixCall: Boolean,
bindingContext: BindingContext,
dataFlowInfo: DataFlowInfo
): CallableDescriptor? {
): Collection<CallableDescriptor> {
val receiverParameter = getExtensionReceiverParameter()!!
if (!receiver.exists()) return null
if (!receiver.exists()) return listOf()
if (isInfixCall && (this !is SimpleFunctionDescriptor || getValueParameters().size() != 1)) {
return null
return listOf()
}
for (type in SmartCastUtils.getSmartCastVariants(receiver, bindingContext, dataFlowInfo)) {
val substitutor = checkReceiverResolution(type, receiverParameter, getTypeParameters())
if (substitutor != null) {
return substitute(substitutor)
}
}
return null
return SmartCastUtils.getSmartCastVariants(receiver, bindingContext, dataFlowInfo)
.map { checkReceiverResolution(it, receiverParameter, getTypeParameters()) }
.filterNotNull()
.map { substitute(it) }
}
private fun checkReceiverResolution(