Introduced LexicalScope for file top-level to obtain ownerDescriptor
This commit is contained in:
@@ -18,9 +18,10 @@ package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
|
||||
public interface FileScopeProvider {
|
||||
fun getFileResolutionScope(file: KtFile): ImportingScope
|
||||
fun getFileResolutionScope(file: KtFile): LexicalScope
|
||||
fun getImportResolver(file: KtFile): ImportResolver
|
||||
|
||||
public object ThrowException : FileScopeProvider {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.SubpackagesScope
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver
|
||||
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.withParent
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
@@ -49,11 +51,11 @@ public class FileScopeProviderImpl(
|
||||
ktImportsFactory.createImportDirectives(moduleDescriptor.defaultImports)
|
||||
}
|
||||
|
||||
private data class FileData(val scopeChain: ImportingScope, val importResolver: ImportResolver)
|
||||
private class FileData(val scope: LexicalScope, val importResolver: ImportResolver)
|
||||
|
||||
private val cache = storageManager.createMemoizedFunction { file: KtFile -> createScopeChainAndImportResolver(file) }
|
||||
|
||||
override fun getFileResolutionScope(file: KtFile) = cache(file).scopeChain
|
||||
override fun getFileResolutionScope(file: KtFile) = cache(file).scope
|
||||
|
||||
override fun getImportResolver(file: KtFile) = cache(file).importResolver
|
||||
|
||||
@@ -106,7 +108,15 @@ public class FileScopeProviderImpl(
|
||||
|
||||
scope = LazyImportScope(scope, packageFragment, aliasImportResolver, LazyImportScope.FilteringKind.ALL, "Alias imports in $debugName")
|
||||
|
||||
bindingTrace.recordScope(scope, file)
|
||||
val lexicalScope = object : LexicalScope by LexicalScope.Empty {
|
||||
override val parent: LexicalScope?
|
||||
get() = scope
|
||||
|
||||
override val ownerDescriptor: DeclarationDescriptor
|
||||
get() = packageFragment
|
||||
}
|
||||
|
||||
bindingTrace.recordScope(lexicalScope, file)
|
||||
|
||||
val importResolver = object : ImportResolver {
|
||||
override fun forceResolveAllImports() {
|
||||
@@ -124,6 +134,6 @@ public class FileScopeProviderImpl(
|
||||
}
|
||||
}
|
||||
|
||||
return FileData(scope, importResolver)
|
||||
return FileData(lexicalScope, importResolver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotations;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationsContextImpl;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyScriptDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.storage.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -208,7 +208,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
}
|
||||
|
||||
private LazyAnnotations createAnnotations(KtFile file, List<KtAnnotationEntry> annotationEntries) {
|
||||
ImportingScope scope = fileScopeProvider.getFileResolutionScope(file);
|
||||
LexicalScope scope = fileScopeProvider.getFileResolutionScope(file);
|
||||
LazyAnnotationsContextImpl lazyAnnotationContext =
|
||||
new LazyAnnotationsContextImpl(annotationResolve, storageManager, trace, scope);
|
||||
return new LazyAnnotations(lazyAnnotationContext, annotationEntries);
|
||||
|
||||
@@ -22,10 +22,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
|
||||
public class ExplicitImportsScope(
|
||||
private val descriptors: Collection<DeclarationDescriptor>,
|
||||
override val ownerDescriptor: DeclarationDescriptor //TODO: temporary?
|
||||
) : ImportingScope by ImportingScope.Empty {
|
||||
public class ExplicitImportsScope(private val descriptors: Collection<DeclarationDescriptor>) : ImportingScope by ImportingScope.Empty {
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation)
|
||||
= descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<ClassifierDescriptor>()
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ public class ShadowedDeclarationsFilter private constructor(
|
||||
var scope = context.getResolutionScope(bindingContext, resolutionFacade)
|
||||
|
||||
if (descriptorsToImport.isNotEmpty()) {
|
||||
scope = scope.addImportScope(ExplicitImportsScope(descriptorsToImport, scope.ownerDescriptor))
|
||||
scope = scope.addImportScope(ExplicitImportsScope(descriptorsToImport))
|
||||
}
|
||||
|
||||
val dataFlowInfo = bindingContext.getDataFlowInfo(context)
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.collectFunctions
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.collectVariables
|
||||
@@ -79,6 +78,6 @@ public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolut
|
||||
error("Not in KtFile")
|
||||
}
|
||||
|
||||
public fun ResolutionFacade.getFileResolutionScope(file: KtFile): ImportingScope {
|
||||
public fun ResolutionFacade.getFileResolutionScope(file: KtFile): LexicalScope {
|
||||
return frontendService<FileScopeProvider>().getFileResolutionScope(file)
|
||||
}
|
||||
+4
-4
@@ -31,7 +31,6 @@ import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.util.getFileResolutionScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.targetDescriptors
|
||||
@@ -41,6 +40,7 @@ import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetSourceFilterScope
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.getFileResolutionScope
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -49,7 +49,7 @@ import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||
import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.collectSyntheticExtensionProperties
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
@@ -87,9 +87,9 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection()
|
||||
}
|
||||
}
|
||||
|
||||
private fun conflictingSyntheticExtension(descriptor: PropertyDescriptor, importingScope: ImportingScope): SyntheticJavaPropertyDescriptor? {
|
||||
private fun conflictingSyntheticExtension(descriptor: PropertyDescriptor, scope: LexicalScope): SyntheticJavaPropertyDescriptor? {
|
||||
val extensionReceiverType = descriptor.extensionReceiverParameter?.type ?: return null
|
||||
return importingScope.collectSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE)
|
||||
return scope.collectSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE)
|
||||
.firstIsInstanceOrNull<SyntheticJavaPropertyDescriptor>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -207,7 +207,7 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
private fun buildExplicitImportsScope(annotation: ReplaceWith, resolutionFacade: ResolutionFacade, module: ModuleDescriptor): ExplicitImportsScope {
|
||||
val importedSymbols = importFqNames(annotation)
|
||||
.flatMap { resolutionFacade.resolveImportReference(module, it) }
|
||||
return ExplicitImportsScope(importedSymbols, module)
|
||||
return ExplicitImportsScope(importedSymbols)
|
||||
}
|
||||
|
||||
private fun importFqNames(annotation: ReplaceWith): List<FqName> {
|
||||
|
||||
Reference in New Issue
Block a user