FIR IDE: Add name filtering to scope KtScope and implementations

This commit is contained in:
Roman Golyshev
2020-09-16 13:19:50 +03:00
committed by Ilya Kirillov
parent dc600e3caf
commit 75d8710bf6
6 changed files with 29 additions and 30 deletions
@@ -27,14 +27,16 @@ interface KtScope : ValidityTokenOwner {
}
}
fun getCallableSymbols(): Sequence<KtCallableSymbol>
fun getClassifierSymbols(): Sequence<KtClassifierSymbol>
fun getCallableSymbols(nameFilter: KtScopeNameFilter = { true }): Sequence<KtCallableSymbol>
fun getClassifierSymbols(nameFilter: KtScopeNameFilter = { true }): Sequence<KtClassifierSymbol>
fun containsName(name: Name): Boolean = withValidityAssertion {
name in getCallableNames() || name in getClassifierNames()
}
}
typealias KtScopeNameFilter = (Name) -> Boolean
interface KtCompositeScope : KtScope {
val subScopes: List<KtScope>
}
@@ -9,8 +9,8 @@ import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
import org.jetbrains.kotlin.idea.frontend.api.ValidityToken
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtCompositeScope
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScope
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeNameFilter
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassifierSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
@@ -47,15 +47,15 @@ class KtFirCompositeScope(
}
}
override fun getCallableSymbols(): Sequence<KtCallableSymbol> = withValidityAssertion {
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
sequence {
subScopes.forEach { yieldAll(it.getCallableSymbols()) }
subScopes.forEach { yieldAll(it.getCallableSymbols(nameFilter)) }
}
}
override fun getClassifierSymbols(): Sequence<KtClassifierSymbol> = withValidityAssertion {
override fun getClassifierSymbols(nameFilter: KtScopeNameFilter): Sequence<KtClassifierSymbol> = withValidityAssertion {
sequence {
subScopes.forEach { yieldAll(it.getClassifierSymbols()) }
subScopes.forEach { yieldAll(it.getClassifierSymbols(nameFilter)) }
}
}
@@ -14,8 +14,8 @@ import org.jetbrains.kotlin.idea.frontend.api.ValidityToken
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.cached
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScope
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeNameFilter
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassifierSymbol
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
import org.jetbrains.kotlin.name.Name
@@ -41,12 +41,12 @@ internal abstract class KtFirDelegatingScope<S>(
firScope.getClassifierNames()
}
override fun getCallableSymbols(): Sequence<KtCallableSymbol> = withValidityAssertion {
firScope.getCallableSymbols(getCallableNames(), builder)
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
firScope.getCallableSymbols(getCallableNames().filter(nameFilter), builder)
}
override fun getClassifierSymbols(): Sequence<KtClassifierSymbol> = withValidityAssertion {
firScope.getClassifierSymbols(getClassifierNames(), builder)
override fun getClassifierSymbols(nameFilter: KtScopeNameFilter): Sequence<KtClassifierSymbol> = withValidityAssertion {
firScope.getClassifierSymbols(getClassifierNames().filter(nameFilter), builder)
}
override fun containsName(name: Name): Boolean = withValidityAssertion {
@@ -13,9 +13,9 @@ import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.cached
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.weakRef
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtNonStarImportingScope
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeNameFilter
import org.jetbrains.kotlin.idea.frontend.api.scopes.NonStarImport
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassifierSymbol
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
import org.jetbrains.kotlin.name.Name
@@ -43,12 +43,12 @@ internal class KtFirNonStarImportingScope(
}
}
override fun getCallableSymbols(): Sequence<KtCallableSymbol> = withValidityAssertion {
firScope.getCallableSymbols(getCallableNames(), builder)
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
firScope.getCallableSymbols(getCallableNames().filter(nameFilter), builder)
}
override fun getClassifierSymbols(): Sequence<KtClassifierSymbol> = withValidityAssertion {
firScope.getClassifierSymbols(getClassifierNames(), builder)
override fun getClassifierSymbols(nameFilter: KtScopeNameFilter): Sequence<KtClassifierSymbol> = withValidityAssertion {
firScope.getClassifierSymbols(getClassifierNames().filter(nameFilter), builder)
}
@@ -12,8 +12,8 @@ import org.jetbrains.kotlin.idea.frontend.api.ValidityToken
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.weakRef
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtPackageScope
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeNameFilter
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassifierSymbol
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
import org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelClassByPackageIndex
@@ -45,11 +45,11 @@ internal class KtFirPackageScope(
.mapNotNullTo(hashSetOf()) { it.nameAsName }
}
override fun getCallableSymbols(): Sequence<KtCallableSymbol> = withValidityAssertion {
firScope.getCallableSymbols(getCallableNames(), builder)
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
firScope.getCallableSymbols(getCallableNames().filter(nameFilter), builder)
}
override fun getClassifierSymbols(): Sequence<KtClassifierSymbol> = withValidityAssertion {
firScope.getClassifierSymbols(getClassifierNames(), builder)
override fun getClassifierSymbols(nameFilter: KtScopeNameFilter): Sequence<KtClassifierSymbol> = withValidityAssertion {
firScope.getClassifierSymbols(getClassifierNames().filter(nameFilter), builder)
}
}
@@ -16,11 +16,8 @@ import org.jetbrains.kotlin.idea.frontend.api.ValidityToken
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.cached
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.weakRef
import org.jetbrains.kotlin.idea.frontend.api.scopes.Import
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtStarImportingScope
import org.jetbrains.kotlin.idea.frontend.api.scopes.StarImport
import org.jetbrains.kotlin.idea.frontend.api.scopes.*
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassifierSymbol
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
import org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelClassByPackageIndex
@@ -51,12 +48,12 @@ internal class KtFirStarImportingScope(
}
}
override fun getCallableSymbols(): Sequence<KtCallableSymbol> = withValidityAssertion {
firScope.getCallableSymbols(getCallableNames(), builder)
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
firScope.getCallableSymbols(getCallableNames().filter(nameFilter), builder)
}
override fun getClassifierSymbols(): Sequence<KtClassifierSymbol> = withValidityAssertion {
firScope.getClassifierSymbols(getClassifierNames(), builder)
override fun getClassifierSymbols(nameFilter: KtScopeNameFilter): Sequence<KtClassifierSymbol> = withValidityAssertion {
firScope.getClassifierSymbols(getClassifierNames().filter(nameFilter), builder)
}
// todo cache?