[AA] Support sealed class inheritors in dangling file tests
- In dangling file tests, the project structure's main module is a non-dangling file module. Sealed class inheritors are registered for that module. However, later when sealed class inheritors are requested, the FIR class has a dangling file module as its `KtModule`, which isn't known by the inheritors provider. We need to take the sealed inheritors of the context module instead.
This commit is contained in:
committed by
Space Team
parent
ff0224d28d
commit
51f1e31cce
+7
-2
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.services
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.services.FirSealedClassInheritorsProcessorFactory
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.services.FirSealedClassInheritorsProcessorFactory
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.llFirModuleData
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.llFirModuleData
|
||||||
|
import org.jetbrains.kotlin.analysis.project.structure.KtDanglingFileModule
|
||||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
import org.jetbrains.kotlin.fir.declarations.SealedClassInheritorsProvider
|
import org.jetbrains.kotlin.fir.declarations.SealedClassInheritorsProvider
|
||||||
@@ -33,8 +34,12 @@ private class SealedClassInheritorsProviderForTests(
|
|||||||
@OptIn(SealedClassInheritorsProviderInternals::class)
|
@OptIn(SealedClassInheritorsProviderInternals::class)
|
||||||
override fun getSealedClassInheritors(firClass: FirRegularClass): List<ClassId> {
|
override fun getSealedClassInheritors(firClass: FirRegularClass): List<ClassId> {
|
||||||
val ktModule = firClass.llFirModuleData.ktModule
|
val ktModule = firClass.llFirModuleData.ktModule
|
||||||
val inheritorsForModuleMap = inheritorsByModule.getValue(ktModule)
|
val relevantModule = when (ktModule) {
|
||||||
|
is KtDanglingFileModule -> ktModule.contextModule
|
||||||
|
else -> ktModule
|
||||||
|
}
|
||||||
|
|
||||||
|
val inheritorsForModuleMap = inheritorsByModule.getValue(relevantModule)
|
||||||
return inheritorsForModuleMap[firClass.classId] ?: firClass.sealedInheritorsAttr?.value ?: emptyList()
|
return inheritorsForModuleMap[firClass.classId] ?: firClass.sealedInheritorsAttr?.value ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user