[Analysis API FIR] refactoring, remove duplicated code from KtFir(Non)StarImporting scope
use base class implementation instead.
This commit is contained in:
committed by
Space Team
parent
55bbc5eb02
commit
950a32901c
+1
-1
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal abstract class KtFirBasedScope<S : FirScope>(
|
||||
protected val firScope: S,
|
||||
internal val firScope: S,
|
||||
protected val builder: KtSymbolByFirBuilder,
|
||||
) : KtScope {
|
||||
final override val token: KtLifetimeToken get() = builder.token
|
||||
|
||||
+3
-24
@@ -7,12 +7,8 @@ package org.jetbrains.kotlin.analysis.api.fir.scopes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScope
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScopeNameFilter
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
@@ -21,10 +17,9 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal class KtFirNonStarImportingScope(
|
||||
private val firScope: FirAbstractSimpleImportingScope,
|
||||
private val builder: KtSymbolByFirBuilder,
|
||||
) : KtScope {
|
||||
override val token: KtLifetimeToken get() = builder.token
|
||||
firScope: FirAbstractSimpleImportingScope,
|
||||
builder: KtSymbolByFirBuilder,
|
||||
) : KtFirBasedScope<FirAbstractSimpleImportingScope>(firScope, builder) {
|
||||
|
||||
private val imports: List<NonStarImport> by cached {
|
||||
buildList {
|
||||
@@ -47,22 +42,6 @@ internal class KtFirNonStarImportingScope(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
|
||||
firScope.getCallableSymbols(getPossibleCallableNames().filter(nameFilter), builder)
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(names: Collection<Name>): Sequence<KtCallableSymbol> = withValidityAssertion {
|
||||
firScope.getCallableSymbols(names, builder)
|
||||
}
|
||||
|
||||
override fun getClassifierSymbols(nameFilter: KtScopeNameFilter): Sequence<KtClassifierSymbol> = withValidityAssertion {
|
||||
firScope.getClassifierSymbols(getPossibleClassifierNames().filter(nameFilter), builder)
|
||||
}
|
||||
|
||||
override fun getClassifierSymbols(names: Collection<Name>): Sequence<KtClassifierSymbol> = withValidityAssertion {
|
||||
firScope.getClassifierSymbols(names, builder)
|
||||
}
|
||||
|
||||
override fun getPackageSymbols(nameFilter: KtScopeNameFilter): Sequence<KtPackageSymbol> = withValidityAssertion {
|
||||
emptySequence()
|
||||
}
|
||||
|
||||
+3
-27
@@ -7,12 +7,8 @@ package org.jetbrains.kotlin.analysis.api.fir.scopes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScope
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScopeNameFilter
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.providers.KotlinDeclarationProvider
|
||||
@@ -20,11 +16,10 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirAbstractStarImportingScope
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal class KtFirStarImportingScope(
|
||||
private val firScope: FirAbstractStarImportingScope,
|
||||
private val builder: KtSymbolByFirBuilder,
|
||||
firScope: FirAbstractStarImportingScope,
|
||||
builder: KtSymbolByFirBuilder,
|
||||
private val declarationProvider: KotlinDeclarationProvider,
|
||||
) : KtScope {
|
||||
override val token: KtLifetimeToken get() = builder.token
|
||||
) : KtFirBasedScope<FirAbstractStarImportingScope>(firScope, builder) {
|
||||
|
||||
private val imports: List<StarImport> by cached {
|
||||
firScope.starImports.map { import ->
|
||||
@@ -36,22 +31,6 @@ internal class KtFirStarImportingScope(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
|
||||
firScope.getCallableSymbols(getPossibleCallableNames().filter(nameFilter), builder)
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(names: Collection<Name>): Sequence<KtCallableSymbol> = withValidityAssertion {
|
||||
firScope.getCallableSymbols(names, builder)
|
||||
}
|
||||
|
||||
override fun getClassifierSymbols(nameFilter: KtScopeNameFilter): Sequence<KtClassifierSymbol> = withValidityAssertion {
|
||||
firScope.getClassifierSymbols(getPossibleClassifierNames().filter(nameFilter), builder)
|
||||
}
|
||||
|
||||
override fun getClassifierSymbols(names: Collection<Name>): Sequence<KtClassifierSymbol> = withValidityAssertion {
|
||||
firScope.getClassifierSymbols(names, builder)
|
||||
}
|
||||
|
||||
override fun getConstructors(): Sequence<KtConstructorSymbol> = withValidityAssertion { emptySequence() }
|
||||
|
||||
// todo cache?
|
||||
@@ -66,12 +45,10 @@ internal class KtFirStarImportingScope(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun getPackageSymbols(nameFilter: KtScopeNameFilter): Sequence<KtPackageSymbol> = withValidityAssertion {
|
||||
emptySequence()
|
||||
}
|
||||
|
||||
|
||||
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
||||
imports.flatMapTo(hashSetOf()) { import ->
|
||||
if (import.relativeClassName == null) {
|
||||
@@ -82,5 +59,4 @@ internal class KtFirStarImportingScope(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user