No shadowed declaration filtering for callable references (as well as imports)

This commit is contained in:
Valentin Kipyatkov
2015-10-02 13:44:13 +03:00
parent d547ea9b57
commit 184d59a645
3 changed files with 31 additions and 10 deletions
@@ -64,7 +64,10 @@ public class ReferenceVariantsHelper(
= getReferenceVariantsNoVisibilityFilter(expression, kindFilter, nameFilter, callTypeAndReceiver, useRuntimeReceiverType)
.filter { !it.isAnnotatedAsHidden() && visibilityFilter(it) }
variants = ShadowedDeclarationsFilter(context, resolutionFacade, expression, callTypeAndReceiver).filter(variants)
ShadowedDeclarationsFilter.create(context, resolutionFacade, expression, callTypeAndReceiver)?.let {
variants = it.filter(variants)
}
if (filterOutJavaGettersAndSetters) {
val accessorMethodsToRemove = HashSet<FunctionDescriptor>()
@@ -36,20 +36,38 @@ import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
import java.util.*
public class ShadowedDeclarationsFilter(
public class ShadowedDeclarationsFilter private constructor(
private val bindingContext: BindingContext,
private val resolutionFacade: ResolutionFacade,
private val context: JetExpression,
callTypeAndReceiver: CallTypeAndReceiver<*, *>
private val explicitReceiverValue: ReceiverValue
) {
companion object {
fun create(
bindingContext: BindingContext,
resolutionFacade: ResolutionFacade,
context: JetExpression,
callTypeAndReceiver: CallTypeAndReceiver<*, *>
): ShadowedDeclarationsFilter? {
val receiverExpression = when (callTypeAndReceiver) {
is CallTypeAndReceiver.DEFAULT -> null
is CallTypeAndReceiver.DOT -> callTypeAndReceiver.receiver
is CallTypeAndReceiver.SAFE -> callTypeAndReceiver.receiver
is CallTypeAndReceiver.INFIX -> callTypeAndReceiver.receiver
else -> return null // TODO: support shadowed declarations filtering for callable references
}
val explicitReceiverValue = receiverExpression?.let {
val type = bindingContext.getType(it) ?: return null
ExpressionReceiver(it, type)
} ?: ReceiverValue.NO_RECEIVER
return ShadowedDeclarationsFilter(bindingContext, resolutionFacade, context, explicitReceiverValue)
}
}
private val psiFactory = JetPsiFactory(resolutionFacade.project)
private val dummyExpressionFactory = DummyExpressionFactory(psiFactory)
private val explicitReceiverValue = (callTypeAndReceiver.receiver as? JetExpression)?.let {
val type = bindingContext.getType(it) ?: return@let null
ExpressionReceiver(it, type)
} ?: ReceiverValue.NO_RECEIVER
public fun <TDescriptor : DeclarationDescriptor> filter(declarations: Collection<TDescriptor>): Collection<TDescriptor> {
return declarations
.groupBy { signature(it) }
@@ -289,8 +289,8 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
}
private fun Collection<CallableDescriptor>.filterShadowedNonImported(): Collection<CallableDescriptor> {
return ShadowedDeclarationsFilter(bindingContext, resolutionFacade, nameExpression!!, callTypeAndReceiver)
.filterNonImported(this, referenceVariants)
val filter = ShadowedDeclarationsFilter.create(bindingContext, resolutionFacade, nameExpression!!, callTypeAndReceiver)
return if (filter != null) filter.filterNonImported(this, referenceVariants) else this
}
protected fun addAllClasses(kindFilter: (ClassKind) -> Boolean) {