Removed methods about synthetic from ImportingScope.

This commit is contained in:
Stanislav Erokhin
2015-12-17 02:47:12 +03:00
parent fe9cbd982d
commit e8a697cb6d
11 changed files with 21 additions and 137 deletions
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver
import org.jetbrains.kotlin.resolve.jvm.JavaClassFinderPostConstruct import org.jetbrains.kotlin.resolve.jvm.JavaClassFinderPostConstruct
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl
import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.TopLevelDescriptorProvider import org.jetbrains.kotlin.resolve.lazy.TopLevelDescriptorProvider
@@ -54,9 +53,8 @@ class ReplFileScopeProvider(
moduleDescriptor: ModuleDescriptor, moduleDescriptor: ModuleDescriptor,
qualifiedExpressionResolver: QualifiedExpressionResolver, qualifiedExpressionResolver: QualifiedExpressionResolver,
bindingTrace: BindingTrace, bindingTrace: BindingTrace,
ktImportsFactory: KtImportsFactory, ktImportsFactory: KtImportsFactory
additionalScopes: Iterable<FileScopeProvider.AdditionalScopes> ) : FileScopeProviderImpl(topLevelDescriptorProvider, storageManager, moduleDescriptor, qualifiedExpressionResolver, bindingTrace, ktImportsFactory) {
) : FileScopeProviderImpl(topLevelDescriptorProvider, storageManager, moduleDescriptor, qualifiedExpressionResolver, bindingTrace, ktImportsFactory, additionalScopes) {
override fun getFileResolutionScope(file: KtFile): LexicalScope override fun getFileResolutionScope(file: KtFile): LexicalScope
= lastLineScopeProvider.lastLineScope ?: super.getFileResolutionScope(file) = lastLineScopeProvider.lastLineScope ?: super.getFileResolutionScope(file)
@@ -21,13 +21,13 @@ import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.container.* import org.jetbrains.kotlin.container.*
import org.jetbrains.kotlin.context.LazyResolveToken import org.jetbrains.kotlin.context.LazyResolveToken
import org.jetbrains.kotlin.context.ModuleContext import org.jetbrains.kotlin.context.ModuleContext
import org.jetbrains.kotlin.descriptors.PackagePartProvider
import org.jetbrains.kotlin.frontend.di.configureModule import org.jetbrains.kotlin.frontend.di.configureModule
import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.load.java.JavaClassFinderImpl import org.jetbrains.kotlin.load.java.JavaClassFinderImpl
import org.jetbrains.kotlin.load.java.JavaFlexibleTypeCapabilitiesProvider import org.jetbrains.kotlin.load.java.JavaFlexibleTypeCapabilitiesProvider
import org.jetbrains.kotlin.load.java.components.* import org.jetbrains.kotlin.load.java.components.*
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver
import org.jetbrains.kotlin.descriptors.PackagePartProvider
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
import org.jetbrains.kotlin.load.java.sam.SamConversionResolverImpl import org.jetbrains.kotlin.load.java.sam.SamConversionResolverImpl
import org.jetbrains.kotlin.load.java.structure.impl.JavaPropertyInitializerEvaluatorImpl import org.jetbrains.kotlin.load.java.structure.impl.JavaPropertyInitializerEvaluatorImpl
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl
import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.synthetic.AdditionalScopesWithJavaSyntheticExtensions
public fun StorageComponentContainer.configureJavaTopDownAnalysis(moduleContentScope: GlobalSearchScope, project: Project, lookupTracker: LookupTracker) { public fun StorageComponentContainer.configureJavaTopDownAnalysis(moduleContentScope: GlobalSearchScope, project: Project, lookupTracker: LookupTracker) {
useInstance(moduleContentScope) useInstance(moduleContentScope)
@@ -65,7 +64,6 @@ public fun StorageComponentContainer.configureJavaTopDownAnalysis(moduleContentS
useImpl<JavaSourceElementFactoryImpl>() useImpl<JavaSourceElementFactoryImpl>()
useImpl<JavaLazyAnalyzerPostConstruct>() useImpl<JavaLazyAnalyzerPostConstruct>()
useImpl<JavaFlexibleTypeCapabilitiesProvider>() useImpl<JavaFlexibleTypeCapabilitiesProvider>()
useImpl<AdditionalScopesWithJavaSyntheticExtensions>()
} }
public fun createContainerForLazyResolveWithJava( public fun createContainerForLazyResolveWithJava(
@@ -1,25 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.synthetic
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
import org.jetbrains.kotlin.storage.StorageManager
class AdditionalScopesWithJavaSyntheticExtensions(storageManager: StorageManager, lookupTracker: LookupTracker) : FileScopeProvider.AdditionalScopes {
override val scopes = listOf(JavaSyntheticPropertiesScope(storageManager, lookupTracker), SamAdapterFunctionsScope(storageManager))
}
@@ -29,14 +29,16 @@ import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.scopes.* import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.SyntheticScope
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
import org.jetbrains.kotlin.resolve.scopes.collectSyntheticExtensionProperties
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
import org.jetbrains.kotlin.types.typeUtil.isUnit import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeFirstWord import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeFirstWord
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addIfNotNull
import java.util.* import java.util.*
import kotlin.properties.Delegates import kotlin.properties.Delegates
@@ -73,7 +75,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
} }
} }
class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val lookupTracker: LookupTracker) : BaseImportingScope(null), SyntheticScope { class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val lookupTracker: LookupTracker) : SyntheticScope {
private val syntheticPropertyInClass = storageManager.createMemoizedFunction<Pair<ClassDescriptor, Name>, SyntheticPropertyHolder> { pair -> private val syntheticPropertyInClass = storageManager.createMemoizedFunction<Pair<ClassDescriptor, Name>, SyntheticPropertyHolder> { pair ->
syntheticPropertyInClassNotCached(pair.first, pair.second) syntheticPropertyInClassNotCached(pair.first, pair.second)
} }
@@ -165,7 +167,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return null return null
} }
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> { override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
var result: SmartList<PropertyDescriptor>? = null var result: SmartList<PropertyDescriptor>? = null
val processedTypes: MutableSet<TypeConstructor>? = if (receiverTypes.size() > 1) HashSet<TypeConstructor>() else null val processedTypes: MutableSet<TypeConstructor>? = if (receiverTypes.size() > 1) HashSet<TypeConstructor>() else null
for (type in receiverTypes) { for (type in receiverTypes) {
@@ -195,7 +197,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return result return result
} }
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> { override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
val result = ArrayList<PropertyDescriptor>() val result = ArrayList<PropertyDescriptor>()
val processedTypes = HashSet<TypeConstructor>() val processedTypes = HashSet<TypeConstructor>()
receiverTypes.forEach { result.collectSyntheticProperties(it.constructor, processedTypes) } receiverTypes.forEach { result.collectSyntheticProperties(it.constructor, processedTypes) }
@@ -257,9 +259,8 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return Name.identifier("set" + identifier.removePrefix(prefix)) return Name.identifier("set" + identifier.removePrefix(prefix))
} }
override fun printStructure(p: Printer) { override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
p.println(javaClass.simpleName) override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> = emptyList()
}
private data class SyntheticPropertyHolder(val descriptor: PropertyDescriptor?, val lookedNames: List<Name>) { private data class SyntheticPropertyHolder(val descriptor: PropertyDescriptor?, val lookedNames: List<Name>) {
companion object { companion object {
@@ -26,12 +26,10 @@ import org.jetbrains.kotlin.load.java.typeEnhacement.enhanceSignature
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
import org.jetbrains.kotlin.resolve.scopes.BaseImportingScope
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.SyntheticScope import org.jetbrains.kotlin.resolve.scopes.SyntheticScope
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.Printer
import java.util.* import java.util.*
import kotlin.properties.Delegates import kotlin.properties.Delegates
@@ -39,7 +37,7 @@ interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor {
val sourceFunction: FunctionDescriptor val sourceFunction: FunctionDescriptor
} }
class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingScope(null), SyntheticScope { class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope {
private val extensionForFunction = storageManager.createMemoizedFunctionWithNullableValues<FunctionDescriptor, FunctionDescriptor> { function -> private val extensionForFunction = storageManager.createMemoizedFunctionWithNullableValues<FunctionDescriptor, FunctionDescriptor> { function ->
extensionForFunctionNotCached(function) extensionForFunctionNotCached(function)
} }
@@ -54,7 +52,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc
return MyFunctionDescriptor.create(enhancedFunction) return MyFunctionDescriptor.create(enhancedFunction)
} }
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> { override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
var result: SmartList<FunctionDescriptor>? = null var result: SmartList<FunctionDescriptor>? = null
for (type in receiverTypes) { for (type in receiverTypes) {
for (function in type.memberScope.getContributedFunctions(name, location)) { for (function in type.memberScope.getContributedFunctions(name, location)) {
@@ -74,7 +72,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc
} }
} }
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> { override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
return receiverTypes.flatMapTo(LinkedHashSet<FunctionDescriptor>()) { type -> return receiverTypes.flatMapTo(LinkedHashSet<FunctionDescriptor>()) { type ->
type.memberScope.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS) type.memberScope.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS)
.filterIsInstance<FunctionDescriptor>() .filterIsInstance<FunctionDescriptor>()
@@ -82,9 +80,9 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc
} }
} }
override fun printStructure(p: Printer) { override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> = emptyList()
p.println(javaClass.simpleName)
} override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> = emptyList()
private class MyFunctionDescriptor( private class MyFunctionDescriptor(
containingDeclaration: DeclarationDescriptor, containingDeclaration: DeclarationDescriptor,
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.resolve.lazy package org.jetbrains.kotlin.resolve.lazy
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope
public interface FileScopeProvider { public interface FileScopeProvider {
@@ -28,10 +27,6 @@ public interface FileScopeProvider {
override fun getFileResolutionScope(file: KtFile) = throw UnsupportedOperationException("Should not be called") override fun getFileResolutionScope(file: KtFile) = throw UnsupportedOperationException("Should not be called")
override fun getImportResolver(file: KtFile) = throw UnsupportedOperationException("Should not be called") override fun getImportResolver(file: KtFile) = throw UnsupportedOperationException("Should not be called")
} }
public interface AdditionalScopes {
public val scopes: List<ImportingScope>
}
} }
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.SubpackagesImportingScope import org.jetbrains.kotlin.resolve.scopes.SubpackagesImportingScope
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
import org.jetbrains.kotlin.resolve.scopes.utils.withParent
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.utils.sure import org.jetbrains.kotlin.utils.sure
@@ -40,8 +39,7 @@ public open class FileScopeProviderImpl(
private val moduleDescriptor: ModuleDescriptor, private val moduleDescriptor: ModuleDescriptor,
private val qualifiedExpressionResolver: QualifiedExpressionResolver, private val qualifiedExpressionResolver: QualifiedExpressionResolver,
private val bindingTrace: BindingTrace, private val bindingTrace: BindingTrace,
private val ktImportsFactory: KtImportsFactory, private val ktImportsFactory: KtImportsFactory
private val additionalScopes: Iterable<FileScopeProvider.AdditionalScopes>
) : FileScopeProvider { ) : FileScopeProvider {
private val defaultImports by storageManager.createLazyValue { private val defaultImports by storageManager.createLazyValue {
@@ -82,11 +80,6 @@ public open class FileScopeProviderImpl(
scope = LazyImportScope(scope, allUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES, scope = LazyImportScope(scope, allUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES,
"All under imports in $debugName (invisible classes only)") "All under imports in $debugName (invisible classes only)")
for (additionalScope in additionalScopes.flatMap { it.scopes }) {
assert(additionalScope.parent == null)
scope = additionalScope.withParent(scope)
}
scope = LazyImportScope(scope, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.VISIBLE_CLASSES, scope = LazyImportScope(scope, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.VISIBLE_CLASSES,
"Default all under imports in $debugName (visible classes)") "Default all under imports in $debugName (visible classes)")
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.util.collectionUtils.concat import org.jetbrains.kotlin.util.collectionUtils.concat
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import java.util.* import java.util.*
@@ -201,38 +200,6 @@ class LazyImportScope(
return importResolver.collectFromImports(name) { scope, name -> scope.getContributedFunctions(name, location) } return importResolver.collectFromImports(name) { scope, name -> scope.getContributedFunctions(name, location) }
} }
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name) { scope, name -> scope.getContributedSyntheticExtensionProperties(receiverTypes, name, location) }
}
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name) { scope, name -> scope.getContributedSyntheticExtensionFunctions(receiverTypes, name, location) }
}
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
// 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<PropertyDescriptor>()) { import ->
importResolver.getImportScope(import).getContributedSyntheticExtensionProperties(receiverTypes)
}
}
}
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
// 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<FunctionDescriptor>()) { import ->
importResolver.getImportScope(import).getContributedSyntheticExtensionFunctions(receiverTypes)
}
}
}
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> { override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
// we do not perform any filtering by visibility here because all descriptors from both visible/invisible filter scopes are to be added anyway // 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() if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
// see utils/ScopeUtils.kt // see utils/ScopeUtils.kt
@@ -98,12 +97,6 @@ interface ImportingScope : HierarchicalScope {
fun getContributedPackage(name: Name): PackageViewDescriptor? fun getContributedPackage(name: Name): PackageViewDescriptor?
fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor>
fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor>
fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor>
fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor>
object Empty : BaseImportingScope(null) { object Empty : BaseImportingScope(null) {
override fun printStructure(p: Printer) { override fun printStructure(p: Printer) {
p.println("ImportingScope.Empty") p.println("ImportingScope.Empty")
@@ -135,30 +128,9 @@ abstract class BaseLexicalScope(
get() = null get() = null
} }
abstract class BaseImportingScope(parent: ImportingScope?) : BaseHierarchicalScope(parent), ImportingScope, SyntheticScope { abstract class BaseImportingScope(parent: ImportingScope?) : BaseHierarchicalScope(parent), ImportingScope {
override val parent: ImportingScope? override val parent: ImportingScope?
get() = super.parent as ImportingScope? get() = super.parent as ImportingScope?
override fun getContributedPackage(name: Name): PackageViewDescriptor? = null override fun getContributedPackage(name: Name): PackageViewDescriptor? = null
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> = emptyList()
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> = emptyList()
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> = emptyList()
// temporary
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= getContributedSyntheticExtensionProperties(receiverTypes, name, location)
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= getContributedSyntheticExtensionFunctions(receiverTypes, name, location)
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
= getContributedSyntheticExtensionProperties(receiverTypes)
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
= getContributedSyntheticExtensionFunctions(receiverTypes)
} }
@@ -106,18 +106,6 @@ public fun MemberScope.memberScopeAsImportingScope(parentScope: ImportingScope?
private class MemberScopeToImportingScopeAdapter(override val parent: ImportingScope?, val memberScope: MemberScope) : ImportingScope { private class MemberScopeToImportingScopeAdapter(override val parent: ImportingScope?, val memberScope: MemberScope) : ImportingScope {
override fun getContributedPackage(name: Name): PackageViewDescriptor? = null override fun getContributedPackage(name: Name): PackageViewDescriptor? = null
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= emptyList<PropertyDescriptor>()
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= emptyList<FunctionDescriptor>()
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
= emptyList<PropertyDescriptor>()
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
= emptyList<FunctionDescriptor>()
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= memberScope.getContributedDescriptors(kindFilter, nameFilter) = memberScope.getContributedDescriptors(kindFilter, nameFilter)
@@ -94,9 +94,8 @@ object ReplaceWithAnnotationAnalyzer {
val module = symbolDescriptor.module val module = symbolDescriptor.module
val explicitImportsScope = buildExplicitImportsScope(annotation, resolutionFacade, module) val explicitImportsScope = buildExplicitImportsScope(annotation, resolutionFacade, module)
val defaultImportsScopes = buildDefaultImportsScopes(resolutionFacade, module) val defaultImportsScopes = buildDefaultImportsScopes(resolutionFacade, module)
val additionalScopes = resolutionFacade.getFrontendService(FileScopeProvider.AdditionalScopes::class.java)
val scope = getResolutionScope(symbolDescriptor, symbolDescriptor, val scope = getResolutionScope(symbolDescriptor, symbolDescriptor,
listOf(explicitImportsScope) + defaultImportsScopes + additionalScopes.scopes) ?: return null listOf(explicitImportsScope) + defaultImportsScopes) ?: return null
var bindingContext = analyzeInContext(expression, module, scope, resolutionFacade) var bindingContext = analyzeInContext(expression, module, scope, resolutionFacade)