Dropped BindingContext.RESOLUTION_SCOPE
This commit is contained in:
+1
-1
@@ -172,7 +172,7 @@ public class CliLightClassGenerationSupport(project: Project) : LightClassGenera
|
|||||||
|
|
||||||
public class NoScopeRecordCliBindingTrace : CliBindingTrace() {
|
public class NoScopeRecordCliBindingTrace : CliBindingTrace() {
|
||||||
override fun <K, V> record(slice: WritableSlice<K, V>, key: K, value: V) {
|
override fun <K, V> record(slice: WritableSlice<K, V>, key: K, value: V) {
|
||||||
if (slice === BindingContext.RESOLUTION_SCOPE || slice === BindingContext.LEXICAL_SCOPE) {
|
if (slice === BindingContext.LEXICAL_SCOPE) {
|
||||||
// In the compiler there's no need to keep scopes
|
// In the compiler there's no need to keep scopes
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ public interface BindingContext {
|
|||||||
|
|
||||||
WritableSlice<KtWhenExpression, Boolean> EXHAUSTIVE_WHEN = Slices.createSimpleSlice();
|
WritableSlice<KtWhenExpression, Boolean> EXHAUSTIVE_WHEN = Slices.createSimpleSlice();
|
||||||
|
|
||||||
@Deprecated WritableSlice<KtExpression, KtScope> RESOLUTION_SCOPE = Slices.createSimpleSlice();
|
|
||||||
WritableSlice<KtElement, LexicalScope> LEXICAL_SCOPE = Slices.createSimpleSlice();
|
WritableSlice<KtElement, LexicalScope> LEXICAL_SCOPE = Slices.createSimpleSlice();
|
||||||
|
|
||||||
WritableSlice<ScriptDescriptor, KtScope> SCRIPT_SCOPE = Slices.createSimpleSlice();
|
WritableSlice<ScriptDescriptor, KtScope> SCRIPT_SCOPE = Slices.createSimpleSlice();
|
||||||
|
|||||||
@@ -22,16 +22,13 @@ import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext.DECLARATION_TO_DESCRIPTOR
|
import org.jetbrains.kotlin.resolve.BindingContext.*
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext.FUNCTION
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext.LABEL_TARGET
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
||||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo
|
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo
|
||||||
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice
|
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice
|
||||||
@@ -73,14 +70,8 @@ public fun <C : ResolutionContext<C>> ResolutionContext<C>.recordDataFlowInfo(ex
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun BindingTrace.recordScope(scope: LexicalScope, element: KtElement?) {
|
public fun BindingTrace.recordScope(scope: LexicalScope, element: KtElement?) {
|
||||||
if (element == null) return
|
if (element != null) {
|
||||||
|
record(BindingContext.LEXICAL_SCOPE, element, scope.takeSnapshot())
|
||||||
val scopeToRecord = scope.takeSnapshot()
|
|
||||||
record(BindingContext.LEXICAL_SCOPE, element, scopeToRecord)
|
|
||||||
|
|
||||||
// todo: remove it later
|
|
||||||
if (element is KtExpression) {
|
|
||||||
record(BindingContext.RESOLUTION_SCOPE, element, scopeToRecord.asKtScope())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.*
|
import org.jetbrains.kotlin.resolve.lazy.*
|
||||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
|
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.utils.asLexicalScope
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||||
|
|
||||||
public class ResolveElementCache(
|
public class ResolveElementCache(
|
||||||
@@ -308,9 +309,9 @@ public class ResolveElementCache(
|
|||||||
if (ktElement is KtSimpleNameExpression) {
|
if (ktElement is KtSimpleNameExpression) {
|
||||||
val header = ktElement.getParentOfType<KtPackageDirective>(true)!!
|
val header = ktElement.getParentOfType<KtPackageDirective>(true)!!
|
||||||
|
|
||||||
if (trace.getBindingContext()[BindingContext.RESOLUTION_SCOPE, ktElement] == null) {
|
if (trace.getBindingContext()[BindingContext.LEXICAL_SCOPE, ktElement] == null) {
|
||||||
val scope = resolveSession.getModuleDescriptor().getPackage(header.getFqName(ktElement).parent()).memberScope
|
val scope = resolveSession.getModuleDescriptor().getPackage(header.getFqName(ktElement).parent()).memberScope
|
||||||
trace.record(BindingContext.RESOLUTION_SCOPE, ktElement, scope)
|
trace.record(BindingContext.LEXICAL_SCOPE, ktElement, scope.asLexicalScope())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Name.isValidIdentifier(ktElement.getReferencedName())) {
|
if (Name.isValidIdentifier(ktElement.getReferencedName())) {
|
||||||
|
|||||||
@@ -573,7 +573,7 @@ class ExpectedInfos(
|
|||||||
if (operationToken != KtTokens.IN_KEYWORD && operationToken != KtTokens.NOT_IN || expressionWithType != binaryExpression.right) return null
|
if (operationToken != KtTokens.IN_KEYWORD && operationToken != KtTokens.NOT_IN || expressionWithType != binaryExpression.right) return null
|
||||||
|
|
||||||
val leftOperandType = binaryExpression.left?.let { bindingContext.getType(it) } ?: return null
|
val leftOperandType = binaryExpression.left?.let { bindingContext.getType(it) } ?: return null
|
||||||
val scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expressionWithType)!!
|
val scope = expressionWithType.getResolutionScope(bindingContext, resolutionFacade)
|
||||||
val detector = TypesWithContainsDetector(scope, leftOperandType, resolutionFacade)
|
val detector = TypesWithContainsDetector(scope, leftOperandType, resolutionFacade)
|
||||||
|
|
||||||
val byTypeFilter = object : ByTypeFilter {
|
val byTypeFilter = object : ByTypeFilter {
|
||||||
|
|||||||
+2
-1
@@ -204,7 +204,8 @@ class SmartCompletion(
|
|||||||
.addTo(items, inheritanceSearchers, expectedInfos)
|
.addTo(items, inheritanceSearchers, expectedInfos)
|
||||||
|
|
||||||
if (expression is KtSimpleNameExpression) {
|
if (expression is KtSimpleNameExpression) {
|
||||||
StaticMembers(bindingContext, lookupElementFactory).addToCollection(items, expectedInfos, expression, descriptorsToSkip)
|
StaticMembers(bindingContext, lookupElementFactory, resolutionFacade)
|
||||||
|
.addToCollection(items, expectedInfos, expression, descriptorsToSkip)
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassLiteralItems.addToCollection(items, expectedInfos, lookupElementFactory, isJvmModule)
|
ClassLiteralItems.addToCollection(items, expectedInfos, lookupElementFactory, isJvmModule)
|
||||||
|
|||||||
+7
-4
@@ -27,7 +27,9 @@ import org.jetbrains.kotlin.idea.completion.ExpectedInfo
|
|||||||
import org.jetbrains.kotlin.idea.completion.LookupElementFactory
|
import org.jetbrains.kotlin.idea.completion.LookupElementFactory
|
||||||
import org.jetbrains.kotlin.idea.completion.fuzzyType
|
import org.jetbrains.kotlin.idea.completion.fuzzyType
|
||||||
import org.jetbrains.kotlin.idea.completion.shortenReferences
|
import org.jetbrains.kotlin.idea.completion.shortenReferences
|
||||||
|
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
||||||
import org.jetbrains.kotlin.idea.core.isVisible
|
import org.jetbrains.kotlin.idea.core.isVisible
|
||||||
|
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.idea.util.fuzzyReturnType
|
import org.jetbrains.kotlin.idea.util.fuzzyReturnType
|
||||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||||
@@ -40,8 +42,9 @@ import org.jetbrains.kotlin.types.TypeUtils
|
|||||||
|
|
||||||
// adds java static members, enum members and members from companion object
|
// adds java static members, enum members and members from companion object
|
||||||
class StaticMembers(
|
class StaticMembers(
|
||||||
val bindingContext: BindingContext,
|
private val bindingContext: BindingContext,
|
||||||
val lookupElementFactory: LookupElementFactory
|
private val lookupElementFactory: LookupElementFactory,
|
||||||
|
private val resolutionFacade: ResolutionFacade
|
||||||
) {
|
) {
|
||||||
public fun addToCollection(collection: MutableCollection<LookupElement>,
|
public fun addToCollection(collection: MutableCollection<LookupElement>,
|
||||||
expectedInfos: Collection<ExpectedInfo>,
|
expectedInfos: Collection<ExpectedInfo>,
|
||||||
@@ -65,10 +68,10 @@ class StaticMembers(
|
|||||||
context: KtSimpleNameExpression,
|
context: KtSimpleNameExpression,
|
||||||
enumEntriesToSkip: Set<DeclarationDescriptor>) {
|
enumEntriesToSkip: Set<DeclarationDescriptor>) {
|
||||||
|
|
||||||
val scope = bindingContext[BindingContext.RESOLUTION_SCOPE, context] ?: return
|
val containingDescriptor = context.getResolutionScope(bindingContext, resolutionFacade).ownerDescriptor
|
||||||
|
|
||||||
fun processMember(descriptor: DeclarationDescriptor) {
|
fun processMember(descriptor: DeclarationDescriptor) {
|
||||||
if (descriptor is DeclarationDescriptorWithVisibility && !descriptor.isVisible(scope.getContainingDeclaration(), bindingContext, context)) return
|
if (descriptor is DeclarationDescriptorWithVisibility && !descriptor.isVisible(containingDescriptor, bindingContext, context)) return
|
||||||
|
|
||||||
val matcher: (ExpectedInfo) -> ExpectedInfoMatch
|
val matcher: (ExpectedInfo) -> ExpectedInfoMatch
|
||||||
if (descriptor is CallableDescriptor) {
|
if (descriptor is CallableDescriptor) {
|
||||||
|
|||||||
+5
-3
@@ -25,14 +25,15 @@ import org.jetbrains.kotlin.idea.util.FuzzyType
|
|||||||
import org.jetbrains.kotlin.idea.util.nullability
|
import org.jetbrains.kotlin.idea.util.nullability
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class TypesWithContainsDetector(
|
class TypesWithContainsDetector(
|
||||||
private val scope: KtScope,
|
private val scope: LexicalScope,
|
||||||
private val argumentType: KotlinType,
|
private val argumentType: KotlinType,
|
||||||
private val resolutionFacade: ResolutionFacade
|
private val resolutionFacade: ResolutionFacade
|
||||||
) {
|
) {
|
||||||
@@ -41,7 +42,8 @@ class TypesWithContainsDetector(
|
|||||||
private val booleanType = resolutionFacade.moduleDescriptor.builtIns.booleanType
|
private val booleanType = resolutionFacade.moduleDescriptor.builtIns.booleanType
|
||||||
private val heuristicSignatures = resolutionFacade.ideService<HeuristicSignatures>()
|
private val heuristicSignatures = resolutionFacade.ideService<HeuristicSignatures>()
|
||||||
|
|
||||||
private val typesWithExtensionContains: Collection<KotlinType> = scope.getFunctions(containsName, NoLookupLocation.FROM_IDE)
|
private val typesWithExtensionContains: Collection<KotlinType> = scope
|
||||||
|
.collectAllFromMeAndParent { it.getDeclaredFunctions(containsName, NoLookupLocation.FROM_IDE) }
|
||||||
.filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) }
|
.filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) }
|
||||||
.map { it.getExtensionReceiverParameter()!!.getType() }
|
.map { it.getExtensionReceiverParameter()!!.getType() }
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.core
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||||
@@ -28,6 +29,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.resolve.getOriginalTopmostOverriddenDescriptors
|
import org.jetbrains.kotlin.resolve.getOriginalTopmostOverriddenDescriptors
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
||||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||||
|
|
||||||
@@ -48,13 +50,11 @@ fun DeclarationDescriptorWithVisibility.isVisible(
|
|||||||
return Visibilities.isVisible(normalizeReceiver, this, from)
|
return Visibilities.isVisible(normalizeReceiver, this, from)
|
||||||
}
|
}
|
||||||
|
|
||||||
val jetScope = bindingContext[BindingContext.RESOLUTION_SCOPE, element]
|
val resolutionScope = element.getResolutionScope(bindingContext, element.getResolutionFacade())
|
||||||
val implicitReceivers = jetScope?.getImplicitReceiversHierarchy()
|
val implicitReceivers = resolutionScope.getImplicitReceiversHierarchy()
|
||||||
if (implicitReceivers != null) {
|
for (implicitReceiver in implicitReceivers) {
|
||||||
for (implicitReceiver in implicitReceivers) {
|
val normalizeReceiver = ExpressionTypingUtils.normalizeReceiverValueForVisibility(implicitReceiver.getValue(), bindingContext)
|
||||||
val normalizeReceiver = ExpressionTypingUtils.normalizeReceiverValueForVisibility(implicitReceiver.getValue(), bindingContext)
|
if (Visibilities.isVisible(normalizeReceiver, this, from)) return true
|
||||||
if (Visibilities.isVisible(normalizeReceiver, this, from)) return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user