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 6e12b5e5836..49dd374c68b 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt @@ -56,7 +56,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor { val owner = getterOrSetter.getContainingDeclaration() as? ClassDescriptor ?: return null val originalGetterOrSetter = getterOrSetter.original - return resolutionScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(listOf(owner.defaultType)) } + return resolutionScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(listOf(owner.defaultType)) } .filterIsInstance() .firstOrNull { originalGetterOrSetter == it.getMethod || originalGetterOrSetter == it.setMethod } } @@ -130,7 +130,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : ImportingSc return null } - override fun getSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { //TODO: use location parameter! var result: SmartList? = null @@ -162,7 +162,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : ImportingSc return result } - override fun getSyntheticExtensionProperties(receiverTypes: Collection): Collection { + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection): Collection { val result = ArrayList() val processedTypes = HashSet() receiverTypes.forEach { result.collectSyntheticProperties(it.constructor, processedTypes) } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt index b23ef2d329b..2616e76b801 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt @@ -53,7 +53,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : ImportingScope return MyFunctionDescriptor.create(enhancedFunction) } - override fun getSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { var result: SmartList? = null for (type in receiverTypes) { for (function in type.memberScope.getFunctions(name, location)) { @@ -73,7 +73,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : ImportingScope } } - override fun getSyntheticExtensionFunctions(receiverTypes: Collection): Collection { + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection): Collection { return receiverTypes.flatMapTo(LinkedHashSet()) { type -> type.memberScope.getDescriptors(DescriptorKindFilter.FUNCTIONS) .filterIsInstance() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AllUnderImportsScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AllUnderImportsScope.kt index 84446606891..e61e40de8fa 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AllUnderImportsScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AllUnderImportsScope.kt @@ -37,28 +37,28 @@ class AllUnderImportsScope(descriptor: DeclarationDescriptor) : ImportingScope b listOf(NoSubpackagesInPackageScope(descriptor as PackageViewDescriptor)) } - override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = scopes.flatMap { it.getDescriptors(kindFilter, nameFilter) } - override fun getDeclaredClassifier(name: Name, location: LookupLocation) + override fun getContributedClassifier(name: Name, location: LookupLocation) = scopes.asSequence().map { it.getClassifier(name, location) }.filterNotNull().singleOrNull() - override fun getDeclaredVariables(name: Name, location: LookupLocation) + override fun getContributedVariables(name: Name, location: LookupLocation) = scopes.flatMap { it.getProperties(name, location) } - override fun getDeclaredFunctions(name: Name, location: LookupLocation) + override fun getContributedFunctions(name: Name, location: LookupLocation) = scopes.flatMap { it.getFunctions(name, location) } - override fun getSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation) + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation) = scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes, name, location) } - override fun getSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation) + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation) = scopes.flatMap { it.getSyntheticExtensionFunctions(receiverTypes, name, location) } - override fun getSyntheticExtensionProperties(receiverTypes: Collection) + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection) = scopes.flatMap { it.getSyntheticExtensionProperties(receiverTypes) } - override fun getSyntheticExtensionFunctions(receiverTypes: Collection) + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection) = scopes.flatMap { it.getSyntheticExtensionFunctions(receiverTypes) } override fun printStructure(p: Printer) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index bb29ec812d2..6a14ac581e5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -556,7 +556,7 @@ public class DescriptorResolver { Name name = nameExpression.getReferencedNameAsName(); - ClassifierDescriptor classifier = ScopeUtilsKt.getClassifier(scope, name, NoLookupLocation.UNSORTED); + ClassifierDescriptor classifier = ScopeUtilsKt.findClassifier(scope, name, NoLookupLocation.UNSORTED); if (classifier instanceof TypeParameterDescriptor && classifier.getContainingDeclaration() == descriptor) continue; if (classifier != null) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.kt index f5106def762..613aee75128 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/QualifiedExpressionResolver.kt @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier +import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addToStdlib.check @@ -55,7 +55,7 @@ public class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageVa ): ClassifierDescriptor? { if (userType.qualifier == null && !userType.startWithPackage) { // optimization for non-qualified types return userType.referenceExpression?.let { - val classifier = scope.getClassifier(it.getReferencedNameAsName(), KotlinLookupLocation(it)) + val classifier = scope.findClassifier(it.getReferencedNameAsName(), KotlinLookupLocation(it)) storeResult(trace, it, classifier, scope.ownerDescriptor, inImport = false, isQualifier = false) classifier } @@ -278,7 +278,7 @@ public class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageVa val firstDescriptor = scopeForFirstPart?.let { val firstPart = path.first() - it.getClassifier(firstPart.name, firstPart.location)?.apply { + it.findClassifier(firstPart.name, firstPart.location)?.apply { storeResult(trace, firstPart.expression, this, shouldBeVisibleFrom, inImport) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/SingleImportScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/SingleImportScope.kt index f4d57bcdbd6..8ae18c205c1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/SingleImportScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/SingleImportScope.kt @@ -24,19 +24,19 @@ import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.utils.Printer class SingleImportScope(private val aliasName: Name, private val descriptors: Collection) : ImportingScope by ImportingScope.Empty { - override fun getDeclaredClassifier(name: Name, location: LookupLocation) + override fun getContributedClassifier(name: Name, location: LookupLocation) = if (name == aliasName) descriptors.filterIsInstance().singleOrNull() else null override fun getContributedPackage(name: Name) = if (name == aliasName) descriptors.filterIsInstance().singleOrNull() else null - override fun getDeclaredVariables(name: Name, location: LookupLocation) + override fun getContributedVariables(name: Name, location: LookupLocation) = if (name == aliasName) descriptors.filterIsInstance() else emptyList() - override fun getDeclaredFunctions(name: Name, location: LookupLocation) + override fun getContributedFunctions(name: Name, location: LookupLocation) = if (name == aliasName) descriptors.filterIsInstance() else emptyList() - override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = descriptors override fun printStructure(p: Printer) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/CallableDescriptorCollectors.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/CallableDescriptorCollectors.kt index 764bdc8f2d0..2bb90ed30c6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/CallableDescriptorCollectors.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/CallableDescriptorCollectors.kt @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.scopes.KtScope import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent -import org.jetbrains.kotlin.resolve.scopes.utils.getLocalVariable +import org.jetbrains.kotlin.resolve.scopes.utils.findLocalVariable import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.util.OperatorNameConventions @@ -84,7 +84,7 @@ private object FunctionCollector : CallableDescriptorCollector { return lexicalScope.collectAllFromMeAndParent { if (it is LexicalChainedScope && it.isStaticScope) { - it.getDeclaredFunctions(name, location).filter { it.extensionReceiverParameter == null } + it.getContributedFunctions(name, location).filter { it.extensionReceiverParameter == null } } else { emptyList() @@ -95,8 +95,8 @@ private object FunctionCollector : CallableDescriptorCollector { return lexicalScope.collectAllFromMeAndParent { if (it !is ImportingScope && it.ownerDescriptor is FunctionDescriptor) { - it.getDeclaredFunctions(name, location).filter { it.extensionReceiverParameter == null } + - getConstructors(it.getDeclaredClassifier(name, location)) + it.getContributedFunctions(name, location).filter { it.extensionReceiverParameter == null } + + getConstructors(it.getContributedClassifier(name, location)) } else { emptyList() @@ -169,13 +169,13 @@ private object FunctionCollector : CallableDescriptorCollector { override fun getLocalNonExtensionsByName(lexicalScope: LexicalScope, name: Name, location: LookupLocation): Collection { - return listOfNotNull(lexicalScope.getLocalVariable(name)) + return listOfNotNull(lexicalScope.findLocalVariable(name)) } override fun getStaticInheritanceByName(lexicalScope: LexicalScope, name: Name, location: LookupLocation): Collection { return lexicalScope.collectAllFromMeAndParent { if (it is LexicalChainedScope && it.isStaticScope) { - it.getDeclaredVariables(name, location) + it.getContributedVariables(name, location) } else { emptyList() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt index 9462f593582..5725ef54a71 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt @@ -86,7 +86,7 @@ class LazyImportResolver( if (!directive.isAllUnder) { PlatformTypesMappedToKotlinChecker.checkPlatformTypesMappedToKotlin( - moduleDescriptor, traceForImportResolve, directive, directiveImportScope.getDescriptors()) + moduleDescriptor, traceForImportResolve, directive, directiveImportScope.getContributedDescriptors()) } directiveImportScope @@ -100,7 +100,7 @@ class LazyImportResolver( val alias = KtPsiUtil.getAliasName(importDirective)?.identifier if (scope != null && alias != null) { - if (scope.getDeclaredClassifier(Name.identifier(alias), KotlinLookupLocation(importDirective)) != null) { + if (scope.getContributedClassifier(Name.identifier(alias), KotlinLookupLocation(importDirective)) != null) { explicitClassImports.put(alias, importDirective) } } @@ -184,58 +184,58 @@ class LazyImportScope( return Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, importResolver.moduleDescriptor) == includeVisible } - override fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { + override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { return importResolver.selectSingleFromImports(name) { scope, name -> - val descriptor = scope.getDeclaredClassifier(name, location) + val descriptor = scope.getContributedClassifier(name, location) if (descriptor != null && isClassVisible(descriptor as ClassDescriptor/*no type parameter can be imported*/)) descriptor else null } } override fun getContributedPackage(name: Name) = null - override fun getDeclaredVariables(name: Name, location: LookupLocation): Collection { + override fun getContributedVariables(name: Name, location: LookupLocation): Collection { if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf() - return importResolver.collectFromImports(name) { scope, name -> scope.getDeclaredVariables(name, location) } + return importResolver.collectFromImports(name) { scope, name -> scope.getContributedVariables(name, location) } } - override fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection { + override fun getContributedFunctions(name: Name, location: LookupLocation): Collection { if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf() - return importResolver.collectFromImports(name) { scope, name -> scope.getDeclaredFunctions(name, location) } + return importResolver.collectFromImports(name) { scope, name -> scope.getContributedFunctions(name, location) } } - override fun getSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf() - return importResolver.collectFromImports(name) { scope, name -> scope.getSyntheticExtensionProperties(receiverTypes, name, location) } + return importResolver.collectFromImports(name) { scope, name -> scope.getContributedSyntheticExtensionProperties(receiverTypes, name, location) } } - override fun getSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf() - return importResolver.collectFromImports(name) { scope, name -> scope.getSyntheticExtensionFunctions(receiverTypes, name, location) } + return importResolver.collectFromImports(name) { scope, name -> scope.getContributedSyntheticExtensionFunctions(receiverTypes, name, location) } } - override fun getSyntheticExtensionProperties(receiverTypes: Collection): Collection { + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection): Collection { // we do not perform any filtering by visibility here because all descriptors from both visible/invisible filter scopes are to be added anyway if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf() return importResolver.storageManager.compute { importResolver.indexedImports.imports.flatMapTo(LinkedHashSet()) { import -> - importResolver.getImportScope(import).getSyntheticExtensionProperties(receiverTypes) + importResolver.getImportScope(import).getContributedSyntheticExtensionProperties(receiverTypes) } } } - override fun getSyntheticExtensionFunctions(receiverTypes: Collection): Collection { + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection): Collection { // we do not perform any filtering by visibility here because all descriptors from both visible/invisible filter scopes are to be added anyway if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf() return importResolver.storageManager.compute { importResolver.indexedImports.imports.flatMapTo(LinkedHashSet()) { import -> - importResolver.getImportScope(import).getSyntheticExtensionFunctions(receiverTypes) + importResolver.getImportScope(import).getContributedSyntheticExtensionFunctions(receiverTypes) } } } - override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection { + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection { // we do not perform any filtering by visibility here because all descriptors from both visible/invisible filter scopes are to be added anyway if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf() @@ -245,7 +245,7 @@ class LazyImportScope( val importPath = directive.getImportPath() ?: continue val importedName = importPath.getImportedName() if (importedName == null || nameFilter(importedName)) { - descriptors.addAll(importResolver.getImportScope(directive).getDescriptors(kindFilter, nameFilter)) + descriptors.addAll(importResolver.getImportScope(directive).getContributedDescriptors(kindFilter, nameFilter)) } } descriptors diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalChainedScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalChainedScope.kt index e2459c10f6a..13e06126e32 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalChainedScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalChainedScope.kt @@ -38,13 +38,13 @@ public class LexicalChainedScope( override val parent = parent.takeSnapshot() private val scopeChain = memberScopes.clone() - override fun getDeclaredDescriptors() = getFromAllScopes(scopeChain) { it.getAllDescriptors() } + override fun getContributedDescriptors() = getFromAllScopes(scopeChain) { it.getAllDescriptors() } - override fun getDeclaredClassifier(name: Name, location: LookupLocation) = getFirstMatch(scopeChain) { it.getClassifier(name, location) } + override fun getContributedClassifier(name: Name, location: LookupLocation) = getFirstMatch(scopeChain) { it.getClassifier(name, location) } - override fun getDeclaredVariables(name: Name, location: LookupLocation) = getFromAllScopes(scopeChain) { it.getProperties(name, location) } + override fun getContributedVariables(name: Name, location: LookupLocation) = getFromAllScopes(scopeChain) { it.getProperties(name, location) } - override fun getDeclaredFunctions(name: Name, location: LookupLocation) = getFromAllScopes(scopeChain) { it.getFunctions(name, location) } + override fun getContributedFunctions(name: Name, location: LookupLocation) = getFromAllScopes(scopeChain) { it.getFunctions(name, location) } override fun toString(): String = debugName diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeImpl.kt index 77f9a8d90c5..a13ed5524ee 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeImpl.kt @@ -44,13 +44,13 @@ public class LexicalScopeImpl @JvmOverloads constructor( InitializeHandler(redeclarationHandler).initialize() } - override fun getDeclaredDescriptors() = addedDescriptors + override fun getContributedDescriptors() = addedDescriptors - override fun getDeclaredClassifier(name: Name, location: LookupLocation) = getDeclaredClassifier(name) + override fun getContributedClassifier(name: Name, location: LookupLocation) = getDeclaredClassifier(name) - override fun getDeclaredVariables(name: Name, location: LookupLocation) = getDeclaredVariables(name) + override fun getContributedVariables(name: Name, location: LookupLocation) = getDeclaredVariables(name) - override fun getDeclaredFunctions(name: Name, location: LookupLocation) = getDeclaredFunctions(name) + override fun getContributedFunctions(name: Name, location: LookupLocation) = getDeclaredFunctions(name) override fun toString(): String = debugName diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalWritableScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalWritableScope.kt index b27fc1f38ba..756077b3a5d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalWritableScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalWritableScope.kt @@ -70,13 +70,13 @@ class LexicalWritableScope( addVariableOrClassDescriptor(classifierDescriptor) } - override fun getDeclaredDescriptors() = checkMayRead().addedDescriptors + override fun getContributedDescriptors() = checkMayRead().addedDescriptors - override fun getDeclaredClassifier(name: Name, location: LookupLocation) = checkMayRead().getDeclaredClassifier(name) + override fun getContributedClassifier(name: Name, location: LookupLocation) = checkMayRead().getDeclaredClassifier(name) - override fun getDeclaredVariables(name: Name, location: LookupLocation) = checkMayRead().getDeclaredVariables(name) + override fun getContributedVariables(name: Name, location: LookupLocation) = checkMayRead().getDeclaredVariables(name) - override fun getDeclaredFunctions(name: Name, location: LookupLocation) = checkMayRead().getDeclaredFunctions(name) + override fun getContributedFunctions(name: Name, location: LookupLocation) = checkMayRead().getDeclaredFunctions(name) private fun checkMayRead(): LexicalWritableScope { if (lockLevel != WritableScope.LockLevel.READING && lockLevel != WritableScope.LockLevel.BOTH) { @@ -101,15 +101,15 @@ class LexicalWritableScope( override val implicitReceiver: ReceiverParameterDescriptor? get() = this@LexicalWritableScope.implicitReceiver - override fun getDeclaredDescriptors() = this@LexicalWritableScope.addedDescriptors.subList(0, descriptorLimit) + override fun getContributedDescriptors() = this@LexicalWritableScope.addedDescriptors.subList(0, descriptorLimit) - override fun getDeclaredClassifier(name: Name, location: LookupLocation) + override fun getContributedClassifier(name: Name, location: LookupLocation) = this@LexicalWritableScope.getDeclaredClassifier(name, descriptorLimit) - override fun getDeclaredVariables(name: Name, location: LookupLocation) + override fun getContributedVariables(name: Name, location: LookupLocation) = this@LexicalWritableScope.getDeclaredVariables(name, descriptorLimit) - override fun getDeclaredFunctions(name: Name, location: LookupLocation) + override fun getContributedFunctions(name: Name, location: LookupLocation) = this@LexicalWritableScope.getDeclaredFunctions(name, descriptorLimit) override fun toString(): String = "Snapshot($descriptorLimit) for $debugName" diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt index 637bd34d2d3..cceb159d1b3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/utils/ScopeUtils.kt @@ -66,38 +66,36 @@ public fun LexicalScope.getDeclarationsByLabel(labelName: Name): Collection Boolean = { true } ): Collection { if (kindFilter.kindMask == 0) return listOf() - return collectAllFromMeAndParent { it.getDescriptors(kindFilter, nameFilter) } + return collectAllFromMeAndParent { it.getContributedDescriptors(kindFilter, nameFilter) } .filter { kindFilter.accepts(it) && nameFilter(it.name) } } @Deprecated("Use getOwnProperties instead") -public fun LexicalScope.getLocalVariable(name: Name): VariableDescriptor? { +public fun LexicalScope.findLocalVariable(name: Name): VariableDescriptor? { return findFirstFromMeAndParent { when { - it is LexicalScopeWrapper -> it.delegate.getLocalVariable(name) + it is LexicalScopeWrapper -> it.delegate.findLocalVariable(name) it is MemberScopeToImportingScopeAdapter -> it.memberScope.getLocalVariable(name) /* todo remove hack*/ - it !is ImportingScope && it !is LexicalChainedScope -> it.getDeclaredVariables(name, NoLookupLocation.UNSORTED).singleOrNull() /* todo check this*/ + it !is ImportingScope && it !is LexicalChainedScope -> it.getContributedVariables(name, NoLookupLocation.UNSORTED).singleOrNull() /* todo check this*/ else -> null } } } -public fun LexicalScope.getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { - return findFirstFromMeAndParent { it.getDeclaredClassifier(name, location) } -} +public fun LexicalScope.findClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? + = findFirstFromMeAndParent { it.getContributedClassifier(name, location) } -public fun LexicalScope.getPackage(name: Name): PackageViewDescriptor? { - return findFirstFromImportingScopes { it.getContributedPackage(name) } -} +public fun LexicalScope.findPackage(name: Name): PackageViewDescriptor? + = findFirstFromImportingScopes { it.getContributedPackage(name) } public fun LexicalScope.takeSnapshot(): LexicalScope = if (this is LexicalWritableScope) takeSnapshot() else this @@ -122,34 +120,34 @@ public fun KtScope.asLexicalScope(): LexicalScope private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope { val lexicalScope = lexicalScope.takeSnapshot() - override fun getClassifier(name: Name, location: LookupLocation) = lexicalScope.getClassifier(name, location) + override fun getClassifier(name: Name, location: LookupLocation) = lexicalScope.findClassifier(name, location) - override fun getPackage(name: Name) = lexicalScope.getPackage(name) + override fun getPackage(name: Name) = lexicalScope.findPackage(name) override fun getProperties(name: Name, location: LookupLocation): Collection { - return lexicalScope.collectAllFromImportingScopes { it.getDeclaredVariables(name, location) } + return lexicalScope.collectAllFromImportingScopes { it.getContributedVariables(name, location) } } override fun getFunctions(name: Name, location: LookupLocation): Collection { - return lexicalScope.collectAllFromMeAndParent { it.getDeclaredFunctions(name, location) } + return lexicalScope.collectAllFromMeAndParent { it.getContributedFunctions(name, location) } } - override fun getLocalVariable(name: Name) = lexicalScope.getLocalVariable(name) + override fun getLocalVariable(name: Name) = lexicalScope.findLocalVariable(name) override fun getSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { - return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(receiverTypes, name, location) } + return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes, name, location) } } override fun getSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection { - return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionFunctions(receiverTypes, name, location) } + return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes, name, location) } } override fun getSyntheticExtensionProperties(receiverTypes: Collection): Collection { - return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(receiverTypes) } + return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes) } } override fun getSyntheticExtensionFunctions(receiverTypes: Collection): Collection { - return lexicalScope.collectAllFromImportingScopes { it.getSyntheticExtensionFunctions(receiverTypes) } + return lexicalScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes) } } override fun getContainingDeclaration() = lexicalScope.ownerDescriptor @@ -157,11 +155,11 @@ private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope { override fun getDeclarationsByLabel(labelName: Name) = lexicalScope.getDeclarationsByLabel(labelName) override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection { - return lexicalScope.collectAllFromMeAndParent { it.getDescriptors(kindFilter, nameFilter) } + return lexicalScope.collectAllFromMeAndParent { it.getContributedDescriptors(kindFilter, nameFilter) } } override fun getImplicitReceiversHierarchy() = lexicalScope.getImplicitReceiversHierarchy() - override fun getOwnDeclaredDescriptors() = lexicalScope.getDeclaredDescriptors() + override fun getOwnDeclaredDescriptors() = lexicalScope.getContributedDescriptors() override fun equals(other: Any?) = other is LexicalToKtScopeAdapter && other.lexicalScope == this.lexicalScope @@ -183,31 +181,31 @@ private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope { private class MemberScopeToImportingScopeAdapter(override val parent: ImportingScope?, val memberScope: KtScope) : ImportingScope { override fun getContributedPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name) - override fun getSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation) + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation) = memberScope.getSyntheticExtensionProperties(receiverTypes, name, location) - override fun getSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation) + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation) = memberScope.getSyntheticExtensionFunctions(receiverTypes, name, location) - override fun getSyntheticExtensionProperties(receiverTypes: Collection) + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection) = memberScope.getSyntheticExtensionProperties(receiverTypes) - override fun getSyntheticExtensionFunctions(receiverTypes: Collection) + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection) = memberScope.getSyntheticExtensionFunctions(receiverTypes) - override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = memberScope.getDescriptors(kindFilter, nameFilter) override val ownerDescriptor: DeclarationDescriptor get() = memberScope.getContainingDeclaration() - override fun getDeclaredDescriptors() = memberScope.getOwnDeclaredDescriptors() + override fun getContributedDescriptors() = memberScope.getOwnDeclaredDescriptors() - override fun getDeclaredClassifier(name: Name, location: LookupLocation) = memberScope.getClassifier(name, location) + override fun getContributedClassifier(name: Name, location: LookupLocation) = memberScope.getClassifier(name, location) - override fun getDeclaredVariables(name: Name, location: LookupLocation) = memberScope.getProperties(name, location) + override fun getContributedVariables(name: Name, location: LookupLocation) = memberScope.getProperties(name, location) - override fun getDeclaredFunctions(name: Name, location: LookupLocation) = memberScope.getFunctions(name, location) + override fun getContributedFunctions(name: Name, location: LookupLocation) = memberScope.getFunctions(name, location) override fun equals(other: Any?) = other is MemberScopeToImportingScopeAdapter && other.memberScope == memberScope diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index 351ac6939e9..812aa79db46 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -455,7 +455,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { { // http://youtrack.jetbrains.net/issue/KT-527 - VariableDescriptor olderVariable = ScopeUtilsKt.getLocalVariable(context.scope, variableDescriptor.getName()); + VariableDescriptor olderVariable = ScopeUtilsKt.findLocalVariable(context.scope, variableDescriptor.getName()); if (olderVariable != null && isLocal(context.scope.getOwnerDescriptor(), olderVariable)) { PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(variableDescriptor); context.trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().asString())); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java index 73dff40fac2..efb63042bba 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java @@ -154,7 +154,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito } { - VariableDescriptor olderVariable = ScopeUtilsKt.getLocalVariable(scope, propertyDescriptor.getName()); + VariableDescriptor olderVariable = ScopeUtilsKt.findLocalVariable(scope, propertyDescriptor.getName()); ExpressionTypingUtils.checkVariableShadowing(context, propertyDescriptor, olderVariable); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/MultiDeclarationResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/MultiDeclarationResolver.kt index 85fa193915d..b3c88dc8d3b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/MultiDeclarationResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/MultiDeclarationResolver.kt @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.TypeResolver import org.jetbrains.kotlin.resolve.dataClassUtils.createComponentName import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.resolve.scopes.utils.getLocalVariable +import org.jetbrains.kotlin.resolve.scopes.utils.findLocalVariable import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType @@ -75,7 +75,7 @@ public class MultiDeclarationResolver( } val variableDescriptor = descriptorResolver.resolveLocalVariableDescriptorWithType(writableScope, entry, componentType, context.trace) - val olderVariable = writableScope.getLocalVariable(variableDescriptor.getName()) + val olderVariable = writableScope.findLocalVariable(variableDescriptor.getName()) ExpressionTypingUtils.checkVariableShadowing(context, variableDescriptor, olderVariable) writableScope.addVariableDescriptor(variableDescriptor) diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/ExplicitImportsScope.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/ExplicitImportsScope.kt index 9f798f40f31..a2a72b5090e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/ExplicitImportsScope.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/ExplicitImportsScope.kt @@ -23,19 +23,19 @@ import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull public class ExplicitImportsScope(private val descriptors: Collection) : ImportingScope by ImportingScope.Empty { - override fun getDeclaredClassifier(name: Name, location: LookupLocation) + override fun getContributedClassifier(name: Name, location: LookupLocation) = descriptors.filter { it.getName() == name }.firstIsInstanceOrNull() override fun getContributedPackage(name: Name) = descriptors.filter { it.getName() == name }.firstIsInstanceOrNull() - override fun getDeclaredVariables(name: Name, location: LookupLocation) + override fun getContributedVariables(name: Name, location: LookupLocation) = descriptors.filter { it.getName() == name }.filterIsInstance() - override fun getDeclaredFunctions(name: Name, location: LookupLocation) + override fun getContributedFunctions(name: Name, location: LookupLocation) = descriptors.filter { it.getName() == name }.filterIsInstance() - override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = descriptors override fun printStructure(p: Printer) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt index d748feb7fa8..271fe812ee6 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt @@ -36,22 +36,18 @@ interface LexicalScope { * All visible descriptors from current scope possibly filtered by the given name and kind filters * (that means that the implementation is not obliged to use the filters but may do so when it gives any performance advantage). */ - open fun getDescriptors( + open fun getContributedDescriptors( kindFilter: DescriptorKindFilter = DescriptorKindFilter.ALL, nameFilter: (Name) -> Boolean = KtScope.ALL_NAME_FILTER - ): Collection = getDeclaredDescriptors() + ): Collection = getContributedDescriptors() - //TODO: rename - fun getDeclaredDescriptors(): Collection + fun getContributedDescriptors(): Collection - //TODO: rename - fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? + fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? - //TODO: rename - fun getDeclaredVariables(name: Name, location: LookupLocation): Collection + fun getContributedVariables(name: Name, location: LookupLocation): Collection - //TODO: rename - fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection + fun getContributedFunctions(name: Name, location: LookupLocation): Collection fun printStructure(p: Printer) @@ -68,13 +64,13 @@ interface LexicalScope { override val implicitReceiver: ReceiverParameterDescriptor? get() = null - override fun getDeclaredDescriptors(): Collection = emptyList() + override fun getContributedDescriptors(): Collection = emptyList() - override fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null + override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null - override fun getDeclaredVariables(name: Name, location: LookupLocation): Collection = emptyList() + override fun getContributedVariables(name: Name, location: LookupLocation): Collection = emptyList() - override fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection = emptyList() + override fun getContributedFunctions(name: Name, location: LookupLocation): Collection = emptyList() override fun printStructure(p: Printer) = throw UnsupportedOperationException() } @@ -94,28 +90,28 @@ interface ImportingScope : LexicalScope { fun getContributedPackage(name: Name): PackageViewDescriptor? - fun getSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection - fun getSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection + fun getContributedSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection + fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection - fun getSyntheticExtensionProperties(receiverTypes: Collection): Collection - fun getSyntheticExtensionFunctions(receiverTypes: Collection): Collection + fun getContributedSyntheticExtensionProperties(receiverTypes: Collection): Collection + fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection): Collection // please, do not override this method - override fun getDeclaredDescriptors(): Collection { - return getDescriptors() + override fun getContributedDescriptors(): Collection { + return getContributedDescriptors(DescriptorKindFilter.ALL, { true }) } - override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection object Empty : ImportingScope, LexicalScope by LexicalScope.Empty { override fun getContributedPackage(name: Name) = null - override fun getSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection = emptyList() + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection, name: Name, location: LookupLocation): Collection = emptyList() - override fun getSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection = emptyList() + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection, name: Name, location: LookupLocation): Collection = emptyList() - override fun getSyntheticExtensionProperties(receiverTypes: Collection): Collection = emptyList() + override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection): Collection = emptyList() - override fun getSyntheticExtensionFunctions(receiverTypes: Collection): Collection = emptyList() + override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection): Collection = emptyList() } } 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 dd5888691f8..dac057257da 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 @@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromImportingScopes -import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered +import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor import org.jetbrains.kotlin.types.KotlinType @@ -162,7 +162,7 @@ public class ReferenceVariantsHelper( descriptors.processAll(implicitReceiverTypes, implicitReceiverTypes, resolutionScope, callType, kindFilter, nameFilter) // add non-instance members - descriptors.addAll(resolutionScope.getDescriptorsFromAllFiltered(kindFilter exclude DescriptorKindExclude.Extensions, nameFilter)) + descriptors.addAll(resolutionScope.collectDescriptorsFiltered(kindFilter exclude DescriptorKindExclude.Extensions, nameFilter)) } return descriptors @@ -182,7 +182,7 @@ public class ReferenceVariantsHelper( val lexicalScope = expression.getParentOfType(strict = true)?.let { context[BindingContext.LEXICAL_SCOPE, it] } ?: return emptyList() - return lexicalScope.getDescriptorsFromAllFiltered(kindFilter, nameFilter) + return lexicalScope.collectDescriptorsFiltered(kindFilter, nameFilter) } } @@ -274,7 +274,7 @@ public class ReferenceVariantsHelper( filterToUse = filterToUse.withKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK) } - for (descriptor in scope.getDescriptorsFromAllFiltered(filterToUse, nameFilter)) { + for (descriptor in scope.collectDescriptorsFiltered(filterToUse, nameFilter)) { if (descriptor is ClassDescriptor) { if (descriptor.modality == Modality.ABSTRACT || descriptor.modality == Modality.SEALED) continue if (!constructorFilter(descriptor)) continue @@ -301,19 +301,19 @@ public class ReferenceVariantsHelper( } } - for (descriptor in resolutionScope.getDescriptorsFromAllFiltered(kindFilter exclude DescriptorKindExclude.NonExtensions, nameFilter)) { + for (descriptor in resolutionScope.collectDescriptorsFiltered(kindFilter exclude DescriptorKindExclude.NonExtensions, nameFilter)) { // todo: sometimes resolution scope here is LazyJavaClassMemberScope. see ea.jetbrains.com/browser/ea_problems/72572 process(descriptor as CallableDescriptor) } if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) { - for (extension in resolutionScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(receiverTypes) }) { + for (extension in resolutionScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionProperties(receiverTypes) }) { process(extension) } } if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) { - for (extension in resolutionScope.collectAllFromImportingScopes { it.getSyntheticExtensionFunctions(receiverTypes) }) { + for (extension in resolutionScope.collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes) }) { process(extension) } } @@ -335,6 +335,6 @@ public class ReferenceVariantsHelper( nameFilter: (Name) -> Boolean ): Collection { val resolutionScope = context[BindingContext.LEXICAL_SCOPE, expression] ?: return listOf() - return resolutionScope.getDescriptorsFromAllFiltered(DescriptorKindFilter.PACKAGES, nameFilter).filter(visibilityFilter) + return resolutionScope.collectDescriptorsFiltered(DescriptorKindFilter.PACKAGES, nameFilter).filter(visibilityFilter) } } diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt index d41b277a4e9..ef6830e3833 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.platform.JavaToKotlinClassMap import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.scopes.LexicalScope -import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier +import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.* @@ -84,7 +84,7 @@ fun KotlinType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Bo if (descriptor == null || descriptor.getName().isSpecial()) return false if (!checkTypeParameters && descriptor is TypeParameterDescriptor) return true - return scope != null && scope.getClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor + return scope != null && scope.findClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor } public fun KotlinType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): KotlinType { diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/scopeUtils.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/scopeUtils.kt index cf92b5d6a65..8c4479fb53e 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/scopeUtils.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/scopeUtils.kt @@ -27,12 +27,12 @@ import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent public fun LexicalScope.getAllAccessibleVariables(name: Name): Collection { - return getVariablesFromImplicitReceivers(name) + collectAllFromMeAndParent { it.getDeclaredVariables(name, NoLookupLocation.FROM_IDE) } + return getVariablesFromImplicitReceivers(name) + collectAllFromMeAndParent { it.getContributedVariables(name, NoLookupLocation.FROM_IDE) } } public fun LexicalScope.getAllAccessibleFunctions(name: Name): Collection { return getImplicitReceiversWithInstance().flatMap { it.type.memberScope.getFunctions(name, NoLookupLocation.FROM_IDE) } + - collectAllFromMeAndParent { it.getDeclaredFunctions(name, NoLookupLocation.FROM_IDE) } + collectAllFromMeAndParent { it.getContributedFunctions(name, NoLookupLocation.FROM_IDE) } } public fun LexicalScope.getVariablesFromImplicitReceivers(name: Name): Collection = getImplicitReceiversWithInstance().flatMap { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/resolutionApi.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/resolutionApi.kt index 7db5220e72a..cb53552d68b 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/resolutionApi.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/resolutionApi.kt @@ -89,7 +89,7 @@ public fun ResolutionFacade.resolveImportReference( val importDirective = KtPsiFactory(project).createImportDirective(ImportPath(fqName, false)) val qualifiedExpressionResolver = this.getFrontendService(moduleDescriptor, QualifiedExpressionResolver::class.java) return qualifiedExpressionResolver.processImportReference( - importDirective, moduleDescriptor, BindingTraceContext(), packageFragmentForVisibilityCheck = null)?.getDescriptors() ?: emptyList() + importDirective, moduleDescriptor, BindingTraceContext(), packageFragmentForVisibilityCheck = null)?.getContributedDescriptors() ?: emptyList() } //NOTE: idea default API returns module search scope for file under module but not in source or production source (for example, test data ) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt index 90b6616c19f..924cd2b50d7 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt @@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil import org.jetbrains.kotlin.resolve.scopes.* -import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered +import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.resolve.source.PsiSourceElement @@ -86,7 +86,7 @@ public fun resolveKDocLink(resolutionFacade: ResolutionFacade, var result: Collection = listOf(fromDescriptor) qualifiedName.forEach { nameComponent -> val scope = getResolutionScope(resolutionFacade, result.singleOrNull() ?: return emptyList()) - result = scope.getDescriptorsFromAllFiltered(nameFilter = { it.asString() == nameComponent}) + result = scope.collectDescriptorsFiltered(nameFilter = { it.asString() == nameComponent}) } return result @@ -96,7 +96,7 @@ private fun resolveInLocalScope(fromDescriptor: DeclarationDescriptor, name: String, resolutionFacade: ResolutionFacade): List { val scope = getResolutionScope(resolutionFacade, fromDescriptor) - return scope.getDescriptorsFromAllFiltered(nameFilter = { it.asString() == name }).filter { + return scope.collectDescriptorsFiltered(nameFilter = { it.asString() == name }).filter { it.containingDeclaration == fromDescriptor } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt index 733d3b2f05f..be403101786 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt @@ -41,8 +41,8 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver -import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier -import org.jetbrains.kotlin.resolve.scopes.utils.getPackage +import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier +import org.jetbrains.kotlin.resolve.scopes.utils.findPackage import java.util.* public class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT }) { @@ -278,9 +278,9 @@ public class ShortenReferences(val options: (KtElement) -> Options = { Options.D val scope = bindingContext[BindingContext.LEXICAL_SCOPE, typeReference] ?: return val name = target.getName() val targetByName = if (target is ClassifierDescriptor) - scope.getClassifier(name, NoLookupLocation.FROM_IDE) + scope.findClassifier(name, NoLookupLocation.FROM_IDE) else - scope.getPackage(name) + scope.findPackage(name) val canShortenNow = targetByName?.asString() == target.asString() processQualifiedElement(type, target, canShortenNow) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt index 379f66abc37..c5746ce214a 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt @@ -38,7 +38,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered +import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy class KDocCompletionContributor(): CompletionContributor() { @@ -107,7 +107,7 @@ class KDocNameCompletionSession(parameters: CompletionParameters, return true } - scope.getDescriptorsFromAllFiltered(nameFilter = descriptorNameFilter).filter(::isApplicable).forEach { + scope.collectDescriptorsFiltered(nameFilter = descriptorNameFilter).filter(::isApplicable).forEach { val element = lookupElementFactory.createLookupElement(it, useReceiverTypes = false, parametersAndTypeGrayed = true) collector.addElement(object: LookupElementDecorator(element) { override fun handleInsert(context: InsertionContext?) { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ParameterNameAndTypeCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ParameterNameAndTypeCompletion.kt index bfaac5a744f..a71a0273de4 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ParameterNameAndTypeCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ParameterNameAndTypeCompletion.kt @@ -42,7 +42,7 @@ import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered +import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered import org.jetbrains.kotlin.types.KotlinType import java.util.* @@ -74,7 +74,7 @@ class ParameterNameAndTypeCompletion( public fun addFromImportedClasses(position: PsiElement, bindingContext: BindingContext, visibilityFilter: (DeclarationDescriptor) -> Boolean) { for ((classNameMatcher, userPrefix) in classNamePrefixMatchers.zip(userPrefixes)) { val resolutionScope = position.getResolutionScope(bindingContext, resolutionFacade) - val classifiers = resolutionScope.getDescriptorsFromAllFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS, classNameMatcher.asNameFilter()) + val classifiers = resolutionScope.collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS, classNameMatcher.asNameFilter()) for (classifier in classifiers) { if (visibilityFilter(classifier)) { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt index f11a1cfead2..492b4c24ac5 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt @@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromMeAndParent -import org.jetbrains.kotlin.resolve.scopes.utils.getLocalVariable +import org.jetbrains.kotlin.resolve.scopes.utils.findLocalVariable import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import java.util.* @@ -106,8 +106,8 @@ class MultipleArgumentsItemProvider( private fun variableInScope(parameter: ValueParameterDescriptor, scope: LexicalScope): VariableDescriptor? { val name = parameter.getName() //TODO: there can be more than one property with such name in scope and we should be able to select one (but we need API for this) - val variable = scope.getLocalVariable(name) - ?: scope.collectAllFromMeAndParent { it.getDeclaredVariables(name, NoLookupLocation.FROM_IDE) }.singleOrNull() + val variable = scope.findLocalVariable(name) + ?: scope.collectAllFromMeAndParent { it.getContributedVariables(name, NoLookupLocation.FROM_IDE) }.singleOrNull() ?: scope.getVariableFromImplicitReceivers(name) ?: return null return if (smartCastCalculator.types(variable).any { KotlinTypeChecker.DEFAULT.isSubtypeOf(it, parameter.getType()) }) variable diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt index 742a4150f5d..3ef71cb7f5e 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt @@ -43,7 +43,7 @@ class TypesWithContainsDetector( private val heuristicSignatures = resolutionFacade.ideService() private val typesWithExtensionContains: Collection = scope - .collectAllFromMeAndParent { it.getDeclaredFunctions(containsName, NoLookupLocation.FROM_IDE) } + .collectAllFromMeAndParent { it.getContributedFunctions(containsName, NoLookupLocation.FROM_IDE) } .filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) } .map { it.getExtensionReceiverParameter()!!.getType() } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/IterableTypesDetection.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/IterableTypesDetection.kt index 26773e6a22c..8e682bf2c27 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/IterableTypesDetection.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/IterableTypesDetection.kt @@ -47,7 +47,7 @@ public class IterableTypesDetection( private val cache = HashMap() private val typesWithExtensionIterator: Collection = scope - .collectAllFromMeAndParent { it.getDeclaredFunctions(iteratorName, NoLookupLocation.FROM_IDE) } + .collectAllFromMeAndParent { it.getContributedFunctions(iteratorName, NoLookupLocation.FROM_IDE) } .map { it.extensionReceiverParameter } .filterNotNull() .map { it.type } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/NameValidators.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/NameValidators.kt index d09f0021844..c02520f7689 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/NameValidators.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/NameValidators.kt @@ -33,7 +33,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.scopes.LexicalScope -import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier +import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import java.util.* @@ -100,7 +100,7 @@ public class NewDeclarationNameValidator( getAllAccessibleVariables(name).any { !it.isExtension && it.isVisible() } Target.FUNCTIONS_AND_CLASSES -> getAllAccessibleFunctions(name).any { !it.isExtension && it.isVisible() } || - getClassifier(name, NoLookupLocation.FROM_IDE)?.let { it.isVisible() } ?: false + findClassifier(name, NoLookupLocation.FROM_IDE)?.let { it.isVisible() } ?: false } } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt index 8b601bcf406..fffb64c7ff2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt @@ -231,12 +231,12 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor - scope.getDeclaredFunctions(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == originalFqName } + scope.getContributedFunctions(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == originalFqName } }) return null // already imported } else if (refData.kind == KotlinReferenceData.Kind.EXTENSION_PROPERTY) { if (fileResolutionScope.parentsWithSelf.any { scope -> - scope.getDeclaredVariables(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == originalFqName } + scope.getContributedVariables(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == originalFqName } }) return null // already imported } diff --git a/idea/src/org/jetbrains/kotlin/idea/imports/KotlinImportOptimizer.kt b/idea/src/org/jetbrains/kotlin/idea/imports/KotlinImportOptimizer.kt index bff97fc2be4..3547b77758c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/imports/KotlinImportOptimizer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/imports/KotlinImportOptimizer.kt @@ -122,13 +122,13 @@ public class KotlinImportOptimizer() : ImportOptimizer { return scope.parentsWithSelf.any { when (target) { is FunctionDescriptor -> - it.getDeclaredFunctions(target.name, NoLookupLocation.FROM_IDE).contains(target) + it.getContributedFunctions(target.name, NoLookupLocation.FROM_IDE).contains(target) is PropertyDescriptor -> - it.getDeclaredVariables(target.name, NoLookupLocation.FROM_IDE).contains(target) + it.getContributedVariables(target.name, NoLookupLocation.FROM_IDE).contains(target) is ClassDescriptor -> - it.getDeclaredClassifier(target.name, NoLookupLocation.FROM_IDE) == target + it.getContributedClassifier(target.name, NoLookupLocation.FROM_IDE) == target else -> false } @@ -221,7 +221,7 @@ public class KotlinImportOptimizer() : ImportOptimizer { val scope = fileWithImports.getResolutionFacade().getFileResolutionScope(fileWithImports) for (fqName in classNamesToCheck) { - if (scope.getClassifier(fqName.shortName(), NoLookupLocation.FROM_IDE)?.importableFqName != fqName) { + if (scope.findClassifier(fqName.shortName(), NoLookupLocation.FROM_IDE)?.importableFqName != fqName) { // add explicit import if failed to import with * (or from current package) importsToGenerate.add(ImportPath(fqName, false)) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt index 5a62e5c15d9..e892dd03584 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt @@ -90,7 +90,7 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection() private fun conflictingSyntheticExtension(descriptor: PropertyDescriptor, importingScope: ImportingScope): SyntheticJavaPropertyDescriptor? { val extensionReceiverType = descriptor.extensionReceiverParameter?.type ?: return null return importingScope.collectAllFromImportingScopes { - it.getSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE) + it.getContributedSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE) }.firstIsInstanceOrNull() } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSamConstructorInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSamConstructorInspection.kt index 675d0d2e44d..0680ed86528 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSamConstructorInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSamConstructorInspection.kt @@ -180,7 +180,7 @@ public class RedundantSamConstructorInspection : AbstractKotlinInspection() { // SAM adapters for member functions val resolutionScope = functionCall.getResolutionScope(bindingContext, functionCall.getResolutionFacade()) val syntheticExtensions = resolutionScope.collectAllFromImportingScopes { - it.getSyntheticExtensionFunctions( + it.getContributedSyntheticExtensionFunctions( containingClass.defaultType.singletonList(), functionResolvedCall.resultingDescriptor.name, NoLookupLocation.FROM_IDE) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt index 38581650267..fa867abd4fa 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt @@ -124,7 +124,7 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention getAllVariables(LexicalScope scope) { Collection result = ContainerUtil.newArrayList(); - result.addAll(ScopeUtilsKt.getDescriptorsFromAllFiltered(scope, DescriptorKindFilter.VARIABLES, KtScope.Companion.getALL_NAME_FILTER())); + result.addAll(ScopeUtilsKt.collectDescriptorsFiltered(scope, DescriptorKindFilter.VARIABLES, KtScope.Companion.getALL_NAME_FILTER())); for (ReceiverParameterDescriptor implicitReceiver : ScopeUtilsKt.getImplicitReceiversHierarchy(scope)) { result.addAll(implicitReceiver.getType().getMemberScope().getDescriptors(DescriptorKindFilter.VARIABLES, KtScope.Companion.getALL_NAME_FILTER())); } diff --git a/idea/src/org/jetbrains/kotlin/idea/liveTemplates/macro/JetAnonymousSuperMacro.kt b/idea/src/org/jetbrains/kotlin/idea/liveTemplates/macro/JetAnonymousSuperMacro.kt index 4f962cdb0cb..1d2b448018f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/liveTemplates/macro/JetAnonymousSuperMacro.kt +++ b/idea/src/org/jetbrains/kotlin/idea/liveTemplates/macro/JetAnonymousSuperMacro.kt @@ -35,7 +35,7 @@ import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered +import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered class JetAnonymousSuperMacro : Macro() { override fun getName() = "anonymousSuper" @@ -73,7 +73,7 @@ class JetAnonymousSuperMacro : Macro() { val resolutionScope = expression.getResolutionScope(bindingContext, expression.getResolutionFacade()) return resolutionScope - .getDescriptorsFromAllFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS) + .collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS) .filter { it is ClassDescriptor && it.modality.isOverridable && (it.kind == ClassKind.CLASS || it.kind == ClassKind.INTERFACE) } .map { DescriptorToSourceUtils.descriptorToDeclaration(it) as PsiNamedElement? } .filterNotNull() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index 2da089cfdec..101b0fa899a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -66,7 +66,7 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.scopes.* -import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier +import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjectionImpl @@ -399,7 +399,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { SourceElement.NO_SOURCE ) - val validator = CollectingNameValidator { scope.getClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null } + val validator = CollectingNameValidator { scope.findClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null } val parameterNames = KotlinNameSuggester.suggestNamesForTypeParameters(typeParameterCount, validator) val typeParameters = (0..typeParameterCount - 1).map { TypeParameterDescriptorImpl.createWithDefaultBound( @@ -626,7 +626,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } } - val validator = CollectingNameValidator { scope.getClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null } + val validator = CollectingNameValidator { scope.findClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null } val typeParameterNames = allTypeParametersNotInScope.map { KotlinNameSuggester.suggestNameByName(it.getName().asString(), validator) } return allTypeParametersNotInScope.zip(typeParameterNames).toMap() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt index b7d195394cd..c957c7b1460 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt @@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsStatement import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass import org.jetbrains.kotlin.resolve.scopes.LexicalScope -import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier +import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.typeUtil.makeNotNullable @@ -82,7 +82,7 @@ internal fun KotlinType.renderLong(typeParameterNameMap: Map, scope: LexicalScope): List { return typeParameters.filter { typeParameter -> - val classifier = scope.getClassifier(typeParameter.name, NoLookupLocation.FROM_IDE) + val classifier = scope.findClassifier(typeParameter.name, NoLookupLocation.FROM_IDE) classifier == null || classifier != typeParameter } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt index e784db4e971..fccebead421 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt @@ -40,7 +40,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope -import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier +import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull @@ -151,5 +151,5 @@ fun KotlinType.hasTypeParametersToAdd(functionDescriptor: FunctionDescriptor, co else -> null } ?: return true - return typeParametersToAdd.any { scope.getClassifier(it.name, NoLookupLocation.FROM_IDE) != it } + return typeParametersToAdd.any { scope.findClassifier(it.name, NoLookupLocation.FROM_IDE) != it } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/CallableUsageReplacementStrategy.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/CallableUsageReplacementStrategy.kt index d1f610dfde8..88090dc2cf1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/CallableUsageReplacementStrategy.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/CallableUsageReplacementStrategy.kt @@ -47,7 +47,7 @@ import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver -import org.jetbrains.kotlin.resolve.scopes.utils.getLocalVariable +import org.jetbrains.kotlin.resolve.scopes.utils.findLocalVariable import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.utils.addIfNotNull @@ -674,7 +674,7 @@ private class ConstructedExpressionWrapperWithIntroduceFeature( } val name = suggestName { name -> - resolutionScope.getLocalVariable(Name.identifier(name)) == null && !isNameUsed(name) + resolutionScope.findLocalVariable(Name.identifier(name)) == null && !isNameUsed(name) } var declaration = psiFactory.createDeclarationByPattern("val $0 = $1", name, value) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureData.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureData.kt index d99b2ab1e41..db85fe12218 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureData.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureData.kt @@ -82,7 +82,7 @@ public class JetChangeSignatureData( val validator = bodyScope?.let { bodyScope -> CollectingNameValidator(paramNames) { name -> val identifier = Name.identifier(name) - bodyScope.collectAllFromMeAndParent { it.getDeclaredVariables(identifier, NoLookupLocation.FROM_IDE) }.isEmpty() + bodyScope.collectAllFromMeAndParent { it.getContributedVariables(identifier, NoLookupLocation.FROM_IDE) }.isEmpty() } } ?: CollectingNameValidator(paramNames) val receiverType = baseDescriptor.getExtensionReceiverParameter()?.getType() ?: return null diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java index e58fe8626a0..133942d7d8e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java @@ -680,7 +680,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro } } else if (function instanceof KtFunction) { - VariableDescriptor variable = ScopeUtilsKt.getLocalVariable(parametersScope, Name.identifier(parameterName)); + VariableDescriptor variable = ScopeUtilsKt.findLocalVariable(parametersScope, Name.identifier(parameterName)); if (variable != null && !(variable instanceof ValueParameterDescriptor)) { PsiElement conflictElement = DescriptorToSourceUtils.descriptorToDeclaration(variable); diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpData.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpData.kt index 50f5b24e53d..98d69249abe 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpData.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpData.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.psi.KtNamedDeclaration import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter -import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFromAllFiltered +import org.jetbrains.kotlin.resolve.scopes.utils.collectDescriptorsFiltered import org.jetbrains.kotlin.types.TypeConstructor import org.jetbrains.kotlin.types.TypeProjection import org.jetbrains.kotlin.types.TypeProjectionImpl @@ -52,7 +52,7 @@ class KotlinPullUpData(val sourceClass: KtClassOrObject, val typeParametersInSourceClassContext by lazy { sourceClassDescriptor.typeConstructor.parameters + sourceClass.getResolutionScope(sourceClassContext, resolutionFacade) - .getDescriptorsFromAllFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS) + .collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS) .filterIsInstance() } diff --git a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt index a2a93646a06..ca8fbbe204a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt +++ b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt @@ -42,8 +42,8 @@ import org.jetbrains.kotlin.resolve.scopes.KtScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier -import org.jetbrains.kotlin.resolve.scopes.utils.getPackage +import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier +import org.jetbrains.kotlin.resolve.scopes.utils.findPackage import org.jetbrains.kotlin.resolve.scopes.utils.processForMeAndParent import org.jetbrains.kotlin.utils.addIfNotNull import java.util.* @@ -110,13 +110,13 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert val name = target.name when (target) { is ClassDescriptor -> { - val classifier = topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE) + val classifier = topLevelScope.findClassifier(name, NoLookupLocation.FROM_IDE) if (classifier?.importableFqName == targetFqName) return true } is FunctionDescriptor -> { topLevelScope.processForMeAndParent { - if (it.getDeclaredFunctions(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == targetFqName }) { + if (it.getContributedFunctions(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == targetFqName }) { return true } } @@ -124,7 +124,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert is PropertyDescriptor -> { topLevelScope.processForMeAndParent { - if (it.getDeclaredVariables(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == targetFqName }) { + if (it.getContributedVariables(name, NoLookupLocation.FROM_IDE).any { it.importableFqName == targetFqName }) { return true } } @@ -154,8 +154,8 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert // check there is an explicit import of a class/package with the same name already val conflict = when (target) { - is ClassDescriptor -> topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE) - is PackageViewDescriptor -> topLevelScope.getPackage(name) + is ClassDescriptor -> topLevelScope.findClassifier(name, NoLookupLocation.FROM_IDE) + is PackageViewDescriptor -> topLevelScope.findPackage(name) else -> null } if (conflict != null && imports.any { @@ -173,7 +173,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert && when (target) { // this check does not give a guarantee that import with * will import the class - for example, // there can be classes with conflicting name in more than one import with * - is ClassDescriptor -> topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE) == null + is ClassDescriptor -> topLevelScope.findClassifier(name, NoLookupLocation.FROM_IDE) == null is FunctionDescriptor, is PropertyDescriptor -> true else -> error("Unknown kind of descriptor to import:$target") } @@ -250,7 +250,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert .filter { importedClass -> isVisible(importedClass) // check that class is really imported - && topLevelScope.getClassifier(importedClass.name, NoLookupLocation.FROM_IDE) == importedClass + && topLevelScope.findClassifier(importedClass.name, NoLookupLocation.FROM_IDE) == importedClass // and not yet imported explicitly && imports.all { it.importPath != ImportPath(importedClass.importableFqName!!, false) } } @@ -292,7 +292,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert // check if there is a conflicting class imported with * import // (not with explicit import - explicit imports are checked before this method invocation) - val classifier = topLevelScope.getClassifier(name, NoLookupLocation.FROM_IDE) + val classifier = topLevelScope.findClassifier(name, NoLookupLocation.FROM_IDE) if (classifier != null && detectNeededImports(listOf(classifier)).isNotEmpty()) { return ImportDescriptorResult.FAIL } @@ -320,7 +320,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert if (importsToCheck.isNotEmpty()) { val topLevelScope = resolutionFacade.getFileResolutionScope(file) for (classFqName in importsToCheck) { - val classifier = topLevelScope.getClassifier(classFqName.shortName(), NoLookupLocation.FROM_IDE) + val classifier = topLevelScope.findClassifier(classFqName.shortName(), NoLookupLocation.FROM_IDE) if (classifier?.importableFqName != classFqName) { addImport(classFqName, false) // restore explicit import }