No getFileKtScope
This commit is contained in:
@@ -43,7 +43,7 @@ public class DeclarationResolver(
|
||||
) {
|
||||
|
||||
public fun resolveAnnotationsOnFiles(c: TopDownAnalysisContext, scopeProvider: FileScopeProvider) {
|
||||
val filesToScope = c.getFiles().keysToMap { scopeProvider.getFileScopeChain(it) }
|
||||
val filesToScope = c.getFiles().keysToMap { scopeProvider.getFileResolutionScope(it) }
|
||||
for ((file, fileScope) in filesToScope) {
|
||||
annotationResolver.resolveAnnotationsWithArguments(fileScope, file.getAnnotationEntries(), trace)
|
||||
annotationResolver.resolveAnnotationsWithArguments(fileScope, file.getDanglingAnnotations(), trace)
|
||||
|
||||
@@ -27,7 +27,7 @@ class SingleImportScope(private val aliasName: Name, private val descriptors: Co
|
||||
override fun getDeclaredClassifier(name: Name, location: LookupLocation)
|
||||
= if (name == aliasName) descriptors.filterIsInstance<ClassifierDescriptor>().singleOrNull() else null
|
||||
|
||||
override fun getPackage(name: Name)
|
||||
override fun getContributedPackage(name: Name)
|
||||
= if (name == aliasName) descriptors.filterIsInstance<PackageViewDescriptor>().singleOrNull() else null
|
||||
|
||||
override fun getDeclaredVariables(name: Name, location: LookupLocation)
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class DeclarationScopeProviderImpl implements DeclarationScopeProvider {
|
||||
}
|
||||
|
||||
if (parentDeclaration == null) {
|
||||
return fileScopeProvider.getFileScopeChain((KtFile) elementOfDeclaration.getContainingFile());
|
||||
return fileScopeProvider.getFileResolutionScope((KtFile) elementOfDeclaration.getContainingFile());
|
||||
}
|
||||
|
||||
if (parentDeclaration instanceof KtClassOrObject) {
|
||||
|
||||
@@ -20,11 +20,11 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
|
||||
public interface FileScopeProvider {
|
||||
fun getFileScopeChain(file: KtFile): ImportingScope
|
||||
fun getFileResolutionScope(file: KtFile): ImportingScope
|
||||
fun getImportResolver(file: KtFile): ImportResolver
|
||||
|
||||
public object ThrowException : FileScopeProvider {
|
||||
override fun getFileScopeChain(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")
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class FileScopeProviderImpl(
|
||||
|
||||
private val cache = storageManager.createMemoizedFunction { file: KtFile -> createScopeChainAndImportResolver(file) }
|
||||
|
||||
override fun getFileScopeChain(file: KtFile) = cache(file).scopeChain
|
||||
override fun getFileResolutionScope(file: KtFile) = cache(file).scopeChain
|
||||
|
||||
override fun getImportResolver(file: KtFile) = cache(file).importResolver
|
||||
|
||||
|
||||
@@ -191,10 +191,7 @@ class LazyImportScope(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? {
|
||||
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return null
|
||||
return importResolver.selectSingleFromImports(name) { scope, name -> scope.getPackage(name) }
|
||||
}
|
||||
override fun getContributedPackage(name: Name) = null
|
||||
|
||||
override fun getDeclaredVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
|
||||
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
|
||||
|
||||
@@ -208,7 +208,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
}
|
||||
|
||||
private LazyAnnotations createAnnotations(KtFile file, List<KtAnnotationEntry> annotationEntries) {
|
||||
ImportingScope scope = fileScopeProvider.getFileScopeChain(file);
|
||||
ImportingScope scope = fileScopeProvider.getFileResolutionScope(file);
|
||||
LazyAnnotationsContextImpl lazyAnnotationContext =
|
||||
new LazyAnnotationsContextImpl(annotationResolve, storageManager, trace, scope);
|
||||
return new LazyAnnotations(lazyAnnotationContext, annotationEntries);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class LazyPackageMemberScope(
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? = null
|
||||
|
||||
override fun getScopeForMemberDeclarationResolution(declaration: KtDeclaration)
|
||||
= resolveSession.getFileScopeProvider().getFileScopeChain(declaration.getContainingJetFile())
|
||||
= resolveSession.getFileScopeProvider().getFileResolutionScope(declaration.getContainingJetFile())
|
||||
|
||||
override fun getNonDeclaredFunctions(name: Name, result: MutableSet<FunctionDescriptor>) {
|
||||
// No extra functions
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ public class LazyScriptDescriptor(
|
||||
override fun getScriptCodeDescriptor() = scriptCodeDescriptor()
|
||||
|
||||
override fun getScopeForBodyResolution(): LexicalScope {
|
||||
return LexicalScopeImpl(resolveSession.fileScopeProvider.getFileScopeChain(jetScript.getContainingJetFile()),
|
||||
return LexicalScopeImpl(resolveSession.fileScopeProvider.getFileResolutionScope(jetScript.getContainingJetFile()),
|
||||
this, false, implicitReceiver, "Scope for body resolution for " + this) {
|
||||
for (valueParameterDescriptor in getScriptCodeDescriptor().valueParameters) {
|
||||
addVariableDescriptor(valueParameterDescriptor)
|
||||
|
||||
@@ -95,6 +95,10 @@ public fun LexicalScope.getClassifier(name: Name, location: LookupLocation): Cla
|
||||
return findFirstFromMeAndParent { it.getDeclaredClassifier(name, location) }
|
||||
}
|
||||
|
||||
public fun LexicalScope.getPackage(name: Name): PackageViewDescriptor? {
|
||||
return findFirstFromImportingScopes { it.getContributedPackage(name) }
|
||||
}
|
||||
|
||||
public fun LexicalScope.takeSnapshot(): LexicalScope = if (this is LexicalWritableScope) takeSnapshot() else this
|
||||
|
||||
public fun LexicalScope.asKtScope(): KtScope {
|
||||
@@ -120,9 +124,7 @@ private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope {
|
||||
|
||||
override fun getClassifier(name: Name, location: LookupLocation) = lexicalScope.getClassifier(name, location)
|
||||
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? {
|
||||
return lexicalScope.findFirstFromImportingScopes { it.getPackage(name) }
|
||||
}
|
||||
override fun getPackage(name: Name) = lexicalScope.getPackage(name)
|
||||
|
||||
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
|
||||
return lexicalScope.collectAllFromImportingScopes { it.getDeclaredVariables(name, location) }
|
||||
@@ -179,7 +181,7 @@ private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope {
|
||||
}
|
||||
|
||||
private class MemberScopeToImportingScopeAdapter(override val parent: ImportingScope?, val memberScope: KtScope) : ImportingScope {
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name)
|
||||
override fun getContributedPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name)
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
|
||||
= memberScope.getSyntheticExtensionProperties(receiverTypes, name, location)
|
||||
|
||||
Reference in New Issue
Block a user