diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/moduleVisibilityUtils.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/moduleVisibilityUtils.kt index ffe82acf6f8..4b3693cb13a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/moduleVisibilityUtils.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/moduleVisibilityUtils.kt @@ -87,5 +87,5 @@ fun getSourceElement(descriptor: DeclarationDescriptor): SourceElement = descriptor.toSourceElement } -private val DeclarationDescriptor.toSourceElement: SourceElement +val DeclarationDescriptor.toSourceElement: SourceElement get() = if (this is DeclarationDescriptorWithSource) source else SourceElement.NO_SOURCE diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt index 95e0ea6e743..33a989081e3 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt @@ -227,7 +227,10 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l return result } - override fun getSyntheticExtensionProperties(receiverTypes: Collection): Collection { + override fun getSyntheticExtensionProperties( + receiverTypes: Collection, + location: LookupLocation + ): Collection { val result = ArrayList() val processedTypes = HashSet() receiverTypes.forEach { result.collectSyntheticProperties(it.constructor, processedTypes) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticScopes.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticScopes.kt index 8dfe8f02278..0cf1aef204c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticScopes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticScopes.kt @@ -30,7 +30,7 @@ interface SyntheticScope { fun getSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation): Collection fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection - fun getSyntheticExtensionProperties(receiverTypes: Collection): Collection + fun getSyntheticExtensionProperties(receiverTypes: Collection, location: LookupLocation): Collection fun getSyntheticMemberFunctions(receiverTypes: Collection): Collection fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection fun getSyntheticConstructors(scope: ResolutionScope): Collection @@ -70,7 +70,10 @@ interface SyntheticScope { return emptyList() } - override fun getSyntheticExtensionProperties(receiverTypes: Collection): Collection { + override fun getSyntheticExtensionProperties( + receiverTypes: Collection, + location: LookupLocation + ): Collection { return emptyList() } @@ -113,8 +116,8 @@ fun SyntheticScopes.collectSyntheticStaticFunctions(scope: ResolutionScope, name fun SyntheticScopes.collectSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation) = scopes.flatMap { it.getSyntheticConstructors(scope, name, location) } -fun SyntheticScopes.collectSyntheticExtensionProperties(receiverTypes: Collection) - = scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes) } +fun SyntheticScopes.collectSyntheticExtensionProperties(receiverTypes: Collection, location: LookupLocation) + = scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes, location) } fun SyntheticScopes.collectSyntheticMemberFunctions(receiverTypes: Collection) = scopes.flatMap { it.getSyntheticMemberFunctions(receiverTypes) } diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt index 9bf3a67c3dd..275a7fb56a7 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt @@ -23,14 +23,14 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.util.* +import org.jetbrains.kotlin.incremental.KotlinLookupLocation +import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi +import org.jetbrains.kotlin.load.kotlin.toSourceElement import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqNameUnsafe import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.psi.KtDeclaration -import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.kotlin.psi.KtSimpleNameExpression -import org.jetbrains.kotlin.psi.KtVariableDeclaration +import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfoBefore @@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope +import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.expressions.DoubleColonLHS @@ -415,7 +416,10 @@ class ReferenceVariantsHelper( val syntheticScopes = resolutionFacade.getFrontendService(SyntheticScopes::class.java) if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) { - for (extension in syntheticScopes.collectSyntheticExtensionProperties(receiverTypes)) { + val lookupLocation = (scope.ownerDescriptor.toSourceElement.getPsi() as? KtElement)?.let { KotlinLookupLocation(it) } + ?: NoLookupLocation.FROM_IDE + + for (extension in syntheticScopes.collectSyntheticExtensionProperties(receiverTypes, lookupLocation)) { process(extension) } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/DebuggerFieldExpressionCodegenExtension.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/DebuggerFieldExpressionCodegenExtension.kt index 39c32bcfd0e..fe83bf3630a 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/DebuggerFieldExpressionCodegenExtension.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/DebuggerFieldExpressionCodegenExtension.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.codegen.StackValue import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.incremental.components.LookupTracker +import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall @@ -33,7 +34,7 @@ class DebuggerFieldExpressionCodegenExtension : ExpressionCodegenExtension { val containingClass = propertyDescriptor.containingDeclaration as? JavaClassDescriptor if (containingClass != null) { val correspondingGetter = JavaSyntheticPropertiesScope(LockBasedStorageManager.NO_LOCKS, LookupTracker.DO_NOTHING) - .getSyntheticExtensionProperties(listOf(containingClass.defaultType)) + .getSyntheticExtensionProperties(listOf(containingClass.defaultType), NoLookupLocation.FROM_BACKEND) .firstOrNull { it.name == propertyDescriptor.name } if (correspondingGetter != null) { diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/DebuggerFieldSyntheticScopeProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/DebuggerFieldSyntheticScopeProvider.kt index 5aa332ac497..050f3ab5592 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/DebuggerFieldSyntheticScopeProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/DebuggerFieldSyntheticScopeProvider.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl import org.jetbrains.kotlin.idea.project.platform import org.jetbrains.kotlin.incremental.KotlinLookupLocation import org.jetbrains.kotlin.incremental.components.LookupLocation +import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.load.java.components.JavaSourceElementFactoryImpl import org.jetbrains.kotlin.load.java.components.TypeUsage import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor @@ -53,12 +54,24 @@ private class DebuggerFieldSyntheticScope(val javaSyntheticPropertiesScope: Java receiverTypes: Collection, name: Name, location: LookupLocation + ): Collection { + return getSyntheticExtensionProperties(receiverTypes, location).filter { it.name == name } + } + + override fun getSyntheticExtensionProperties( + receiverTypes: Collection, + location: LookupLocation ): Collection { if (!isInEvaluator(location)) { return emptyList() } - return getSyntheticExtensionProperties(receiverTypes).filter { it.name == name } + val result = mutableListOf() + for (type in receiverTypes) { + val clazz = type.constructor.declarationDescriptor as? ClassDescriptor ?: continue + result += getSyntheticPropertiesForClass(clazz) + } + return result } private fun isInEvaluator(location: LookupLocation): Boolean { @@ -73,20 +86,11 @@ private class DebuggerFieldSyntheticScope(val javaSyntheticPropertiesScope: Java return containingFile.suppressDiagnosticsInDebugMode } - override fun getSyntheticExtensionProperties(receiverTypes: Collection): Collection { - val result = mutableListOf() - for (type in receiverTypes) { - val clazz = type.constructor.declarationDescriptor as? ClassDescriptor ?: continue - result += getSyntheticPropertiesForClass(clazz) - } - return result - } - private fun getSyntheticPropertiesForClass(clazz: ClassDescriptor): Collection { val collected = mutableMapOf() val syntheticPropertyNames = javaSyntheticPropertiesScope - .getSyntheticExtensionProperties(listOf(clazz.defaultType)) + .getSyntheticExtensionProperties(listOf(clazz.defaultType), NoLookupLocation.FROM_SYNTHETIC_SCOPE) .mapTo(mutableSetOf()) { it.name } collectPropertiesWithParent(clazz, syntheticPropertyNames, collected)