[Analysis API] optimize composite scope

Do not create KtCompositeScope for empty or single scopes
This commit is contained in:
Ilya Kirillov
2023-05-12 15:29:57 +02:00
committed by Space Team
parent 950a32901c
commit ee1fd9f6e9
7 changed files with 28 additions and 7 deletions
@@ -95,4 +95,5 @@ compileKotlin.dependsOn(generateCode)
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
kotlinOptions.freeCompilerArgs += "-opt-in=org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals"
}
@@ -156,7 +156,7 @@ internal class KtFirScopeProvider(
override fun getCompositeScope(subScopes: List<KtScope>): KtScope {
return KtCompositeScope(subScopes, token)
return KtCompositeScope.create(subScopes, token)
}
override fun getTypeScope(type: KtType): KtTypeScope? = getFirTypeScope(type)?.let { convertToKtTypeScope(it) }
@@ -24,7 +24,7 @@ internal class KtFirScopeSubstitution(
override fun getDeclarationScope(scope: KtTypeScope): KtScope {
return when (scope) {
is KtFirDelegatingTypeScope -> KtFirDelegatingNamesAwareScope(scope.firScope, analysisSession.firSymbolBuilder)
is KtCompositeTypeScope -> KtCompositeScope(scope.subScopes.map(::getDeclarationScope), token)
is KtCompositeTypeScope -> KtCompositeScope.create(scope.subScopes.map(::getDeclarationScope), token)
else -> unexpectedElementError<KtTypeScope>(scope)
}
}