Using PsiElement.getResolutionScope instead of LEXICAL_SCOPE from BindingContext
This commit is contained in:
+5
-8
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
|
||||
@@ -117,7 +116,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
is CallTypeAndReceiver.CALLABLE_REFERENCE -> {
|
||||
val resolutionScope = context[BindingContext.LEXICAL_SCOPE, expression.parent as KtExpression] ?: return emptyList()
|
||||
val resolutionScope = expression.getResolutionScope(context, resolutionFacade)
|
||||
return getVariantsForCallableReference(callTypeAndReceiver.receiver, resolutionScope, kindFilter, nameFilter)
|
||||
}
|
||||
|
||||
@@ -130,7 +129,7 @@ public class ReferenceVariantsHelper(
|
||||
else -> throw RuntimeException() //TODO: see KT-9394
|
||||
}
|
||||
|
||||
val resolutionScope = context[BindingContext.LEXICAL_SCOPE, expression] ?: return emptyList()
|
||||
val resolutionScope = expression.getResolutionScope(context, resolutionFacade)
|
||||
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||
val containingDeclaration = resolutionScope.ownerDescriptor
|
||||
|
||||
@@ -180,10 +179,8 @@ public class ReferenceVariantsHelper(
|
||||
return qualifier.scope.getDescriptorsFiltered(kindFilter, nameFilter)
|
||||
}
|
||||
else {
|
||||
val lexicalScope = expression.getParentOfType<KtTypeReference>(strict = true)?.let {
|
||||
context[BindingContext.LEXICAL_SCOPE, it]
|
||||
} ?: return emptyList()
|
||||
return lexicalScope.collectDescriptorsFiltered(kindFilter, nameFilter)
|
||||
val scope = expression.getResolutionScope(context, resolutionFacade)
|
||||
return scope.collectDescriptorsFiltered(kindFilter, nameFilter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +332,7 @@ public class ReferenceVariantsHelper(
|
||||
expression: KtSimpleNameExpression,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
val resolutionScope = context[BindingContext.LEXICAL_SCOPE, expression] ?: return listOf()
|
||||
val resolutionScope = expression.getResolutionScope(context, resolutionFacade)
|
||||
return resolutionScope.collectDescriptorsFiltered(DescriptorKindFilter.PACKAGES, nameFilter).filter(visibilityFilter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||
@@ -187,6 +188,7 @@ public fun CallTypeAndReceiver<*, *>.receiverTypes(
|
||||
bindingContext: BindingContext,
|
||||
position: KtExpression,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
resolutionFacade: ResolutionFacade,
|
||||
predictableSmartCastsOnly: Boolean
|
||||
): Collection<KotlinType>? {
|
||||
val receiverExpression: KtExpression?
|
||||
@@ -218,7 +220,7 @@ public fun CallTypeAndReceiver<*, *>.receiverTypes(
|
||||
expressionType?.let { listOf(ExpressionReceiver(receiverExpression, expressionType)) } ?: return emptyList()
|
||||
}
|
||||
else {
|
||||
val resolutionScope = bindingContext[BindingContext.LEXICAL_SCOPE, position] ?: return emptyList()
|
||||
val resolutionScope = position.getResolutionScope(bindingContext, resolutionFacade)
|
||||
resolutionScope.getImplicitReceiversWithInstance().map { it.value }
|
||||
}
|
||||
|
||||
|
||||
@@ -188,14 +188,14 @@ public class ShadowedDeclarationsFilter private constructor(
|
||||
override fun getCallType() = Call.CallType.DEFAULT
|
||||
}
|
||||
|
||||
var lexicalScope = bindingContext[BindingContext.LEXICAL_SCOPE, context] ?: return descriptors
|
||||
var scope = context.getResolutionScope(bindingContext, resolutionFacade)
|
||||
|
||||
if (descriptorsToImport.isNotEmpty()) {
|
||||
lexicalScope = lexicalScope.addImportScope(ExplicitImportsScope(descriptorsToImport))
|
||||
scope = scope.addImportScope(ExplicitImportsScope(descriptorsToImport))
|
||||
}
|
||||
|
||||
val dataFlowInfo = bindingContext.getDataFlowInfo(context)
|
||||
val context = BasicCallResolutionContext.create(bindingTrace, lexicalScope, newCall, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo,
|
||||
val context = BasicCallResolutionContext.create(bindingTrace, scope, newCall, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo,
|
||||
ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
|
||||
CallChecker.DoNothing, false)
|
||||
val callResolver = resolutionFacade.frontendService<CallResolver>()
|
||||
|
||||
@@ -58,7 +58,7 @@ public fun LexicalScope.getVariableFromImplicitReceivers(name: Name): VariableDe
|
||||
return null
|
||||
}
|
||||
|
||||
public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolutionFacade: ResolutionFacade): LexicalScope {
|
||||
public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolutionFacade: ResolutionFacade/*TODO: get rid of this parameter*/): LexicalScope {
|
||||
for (parent in parentsWithSelf) {
|
||||
if (parent is KtElement) {
|
||||
val scope = bindingContext[BindingContext.LEXICAL_SCOPE, parent]
|
||||
|
||||
Reference in New Issue
Block a user