[AA] Add synthetic properties scopes to scope context for position
This commit is contained in:
committed by
teamcity
parent
5d8e23e971
commit
116de97f54
+65
-15
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.fir.scopes.impl.*
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhaseWithCallableMembers
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
@@ -160,16 +161,17 @@ internal class KtFirScopeProvider(
|
||||
return KtCompositeScope.create(subScopes, token)
|
||||
}
|
||||
|
||||
override fun getTypeScope(type: KtType): KtTypeScope? = getFirTypeScope(type)?.let { convertToKtTypeScope(it) }
|
||||
override fun getTypeScope(type: KtType): KtTypeScope? {
|
||||
check(type is KtFirType) { "KtFirScopeProvider can only work with KtFirType, but ${type::class} was provided" }
|
||||
return getFirTypeScope(type)
|
||||
?.withSyntheticPropertiesScopeOrSelf(type.coneType)
|
||||
?.let { convertToKtTypeScope(it) }
|
||||
}
|
||||
|
||||
override fun getSyntheticJavaPropertiesScope(type: KtType): KtTypeScope? {
|
||||
check(type is KtFirType) { "KtFirScopeProvider can only work with KtFirType, but ${type::class} was provided" }
|
||||
val firTypeScope = getFirTypeScope(type) ?: return null
|
||||
return FirSyntheticPropertiesScope.createIfSyntheticNamesProviderIsDefined(
|
||||
firResolveSession.useSiteFirSession,
|
||||
type.coneType,
|
||||
firTypeScope
|
||||
)?.let { convertToKtTypeScope(it) }
|
||||
val typeScope = getFirTypeScope(type) ?: return null
|
||||
return getFirSyntheticPropertiesScope(type.coneType, typeScope)?.let { convertToKtTypeScope(it) }
|
||||
}
|
||||
|
||||
override fun getImportingScopeContext(file: KtFile): KtScopeContext {
|
||||
@@ -209,7 +211,9 @@ internal class KtFirScopeProvider(
|
||||
}
|
||||
|
||||
val firScopes = towerDataElementsIndexed.flatMap { (index, towerDataElement) ->
|
||||
val availableScopes = towerDataElement.getAvailableScopes().flatMap { flattenFirScope(it) }
|
||||
val availableScopes = towerDataElement
|
||||
.getAvailableScopes { coneType -> withSyntheticPropertiesScopeOrSelf(coneType) }
|
||||
.flatMap { flattenFirScope(it) }
|
||||
availableScopes.map { IndexedValue(index, it) }
|
||||
}
|
||||
val ktScopesWithKinds = createScopesWithKind(firScopes)
|
||||
@@ -245,7 +249,7 @@ internal class KtFirScopeProvider(
|
||||
is FirNameAwareOnlyClassifiersScope -> getScopeKind(firScope.delegate, indexInTower)
|
||||
|
||||
is FirLocalScope -> KtScopeKind.LocalScope(indexInTower)
|
||||
is FirTypeScope -> KtScopeKind.SimpleTypeScope(indexInTower)
|
||||
is FirTypeScope -> KtScopeKind.TypeScope(indexInTower)
|
||||
is FirTypeParameterScope -> KtScopeKind.TypeParameterScope(indexInTower)
|
||||
is FirPackageMemberScope -> KtScopeKind.PackageMemberScope(indexInTower)
|
||||
|
||||
@@ -275,14 +279,23 @@ internal class KtFirScopeProvider(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFirTypeScope(type: KtType): FirTypeScope? {
|
||||
check(type is KtFirType) { "KtFirScopeProvider can only work with KtFirType, but ${type::class} was provided" }
|
||||
return type.coneType.scope(
|
||||
private fun getFirTypeScope(type: KtFirType): FirTypeScope? = type.coneType.scope(
|
||||
firResolveSession.useSiteFirSession,
|
||||
getScopeSession(),
|
||||
FakeOverrideTypeCalculator.Forced,
|
||||
requiredMembersPhase = FirResolvePhase.STATUS,
|
||||
)
|
||||
|
||||
private fun getFirSyntheticPropertiesScope(coneType: ConeKotlinType, typeScope: FirTypeScope): FirSyntheticPropertiesScope? =
|
||||
FirSyntheticPropertiesScope.createIfSyntheticNamesProviderIsDefined(
|
||||
firResolveSession.useSiteFirSession,
|
||||
getScopeSession(),
|
||||
FakeOverrideTypeCalculator.Forced,
|
||||
requiredMembersPhase = FirResolvePhase.STATUS,
|
||||
coneType,
|
||||
typeScope
|
||||
)
|
||||
|
||||
private fun FirTypeScope.withSyntheticPropertiesScopeOrSelf(coneType: ConeKotlinType): FirTypeScope {
|
||||
val syntheticPropertiesScope = getFirSyntheticPropertiesScope(coneType, this) ?: return this
|
||||
return FirTypeScopeWithSyntheticProperties(typeScope = this, syntheticPropertiesScope)
|
||||
}
|
||||
|
||||
private fun buildJavaEnhancementDeclaredMemberScope(
|
||||
@@ -310,6 +323,43 @@ internal class KtFirScopeProvider(
|
||||
}
|
||||
}
|
||||
|
||||
private class FirTypeScopeWithSyntheticProperties(
|
||||
val typeScope: FirTypeScope,
|
||||
val syntheticPropertiesScope: FirSyntheticPropertiesScope,
|
||||
) : FirTypeScope() {
|
||||
override fun getCallableNames(): Set<Name> = typeScope.getCallableNames() + syntheticPropertiesScope.getCallableNames()
|
||||
override fun getClassifierNames(): Set<Name> = typeScope.getClassifierNames()
|
||||
override fun mayContainName(name: Name): Boolean = typeScope.mayContainName(name) || syntheticPropertiesScope.mayContainName(name)
|
||||
override val scopeOwnerLookupNames: List<String> get() = typeScope.scopeOwnerLookupNames
|
||||
|
||||
override fun processDirectOverriddenFunctionsWithBaseScope(
|
||||
functionSymbol: FirNamedFunctionSymbol,
|
||||
processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction,
|
||||
): ProcessorAction = typeScope.processDirectOverriddenFunctionsWithBaseScope(functionSymbol, processor)
|
||||
|
||||
override fun processDirectOverriddenPropertiesWithBaseScope(
|
||||
propertySymbol: FirPropertySymbol,
|
||||
processor: (FirPropertySymbol, FirTypeScope) -> ProcessorAction,
|
||||
): ProcessorAction = typeScope.processDirectOverriddenPropertiesWithBaseScope(propertySymbol, processor)
|
||||
|
||||
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
||||
typeScope.processClassifiersByNameWithSubstitution(name, processor)
|
||||
}
|
||||
|
||||
override fun processFunctionsByName(name: Name, processor: (FirNamedFunctionSymbol) -> Unit) {
|
||||
typeScope.processFunctionsByName(name, processor)
|
||||
}
|
||||
|
||||
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
|
||||
typeScope.processPropertiesByName(name, processor)
|
||||
syntheticPropertiesScope.processPropertiesByName(name, processor)
|
||||
}
|
||||
|
||||
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
|
||||
typeScope.processDeclaredConstructors(processor)
|
||||
}
|
||||
}
|
||||
|
||||
private class EnumEntryContainingNamesAwareScope(private val originalScope: FirContainingNamesAwareScope) : FirContainingNamesAwareScope() {
|
||||
override fun getCallableNames(): Set<Name> = originalScope.getCallableNames()
|
||||
override fun getClassifierNames(): Set<Name> = originalScope.getClassifierNames()
|
||||
|
||||
+6
@@ -75,4 +75,10 @@ public class FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGener
|
||||
public void testSimpleScopeContextForPosition() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropertiesScope.kt")
|
||||
public void testSyntheticPropertiesScope() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/syntheticPropertiesScope.kt");
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -81,4 +81,10 @@ public class FirIdeDependentAnalysisSourceModuleTypeScopeTestGenerated extends A
|
||||
public void testTypeParamList() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeParamList.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeWithSyntheticProperties.kt")
|
||||
public void testTypeWithSyntheticProperties() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeWithSyntheticProperties.kt");
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -75,4 +75,10 @@ public class FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerate
|
||||
public void testSimpleScopeContextForPosition() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropertiesScope.kt")
|
||||
public void testSyntheticPropertiesScope() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/syntheticPropertiesScope.kt");
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -81,4 +81,10 @@ public class FirIdeNormalAnalysisSourceModuleTypeScopeTestGenerated extends Abst
|
||||
public void testTypeParamList() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeParamList.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeWithSyntheticProperties.kt")
|
||||
public void testTypeWithSyntheticProperties() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeWithSyntheticProperties.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user