[Analysis API] Allow disabling sealed class inheritor searcher in tests

Index-less implementation of sealed class inheritor searcher affects
Java caches, making laziness work quite differently, comparing to IDEs.
This commit is contained in:
Yan Zhulanow
2022-11-11 02:17:10 +09:00
committed by teamcity
parent b770e5d02f
commit 40f1bc8480
5 changed files with 17 additions and 0 deletions
@@ -41,6 +41,7 @@ object AnalysisApiFirLibrarySourceTestConfigurator : AnalysisApiTestConfigurator
) {
builder.apply {
useAdditionalServices(ServiceRegistrationData(CompiledLibraryProvider::class, ::CompiledLibraryProvider))
useDirectives(SealedClassesInheritorsCaclulatorPreAnalysisHandler.Directives)
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
}
}
@@ -24,6 +24,7 @@ object StandaloneModeConfigurator : AnalysisApiTestConfigurator() {
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
with(builder) {
useDirectives(SealedClassesInheritorsCaclulatorPreAnalysisHandler.Directives)
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
}
}
@@ -45,6 +45,7 @@ abstract class AbstractCompilerBasedTestForFir : AbstractCompilerBasedTest() {
configureTest()
defaultConfiguration(this)
registerAnalysisApiBaseTestServices(disposable, FirLowLevelCompilerBasedTestConfigurator)
useDirectives(SealedClassesInheritorsCaclulatorPreAnalysisHandler.Directives)
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
firHandlersStep {
@@ -19,6 +19,8 @@ import org.jetbrains.kotlin.fir.resolve.transformers.FirSealedClassInheritorsPro
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability
import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer
import org.jetbrains.kotlin.test.services.PreAnalysisHandler
import org.jetbrains.kotlin.test.services.TestModuleStructure
import org.jetbrains.kotlin.test.services.TestServices
@@ -35,6 +37,10 @@ class SealedClassesInheritorsCaclulatorPreAnalysisHandler(
// In the actual IDE, SealedClassInheritorsProviderIdeImpl works by finding inheritors from the index instead of do a
// preprocessing of all files. Therefore, the IDE does not rely on such a pre-analysis pass of all files in the module.
override fun prepareSealedClassInheritors(moduleStructure: TestModuleStructure) {
if (Directives.DISABLE_SEALED_INHERITOR_CALCULATOR in moduleStructure.allDirectives) {
return
}
val ktFilesByModule = moduleStructure.modules.associateWith { testModule ->
testServices.ktModuleProvider.getModuleFiles(testModule).filterIsInstance<KtFile>()
}
@@ -64,4 +70,11 @@ class SealedClassesInheritorsCaclulatorPreAnalysisHandler(
firFiles.forEach { it.accept(inheritorsCollector, sealedClassInheritorsMap) }
return sealedClassInheritorsMap.mapKeys { (firClass, _) -> firClass.symbol.classId }
}
object Directives : SimpleDirectivesContainer() {
val DISABLE_SEALED_INHERITOR_CALCULATOR by directive(
description = "Disable mock sealed class inheritor calculation",
applicability = DirectiveApplicability.Global
)
}
}
@@ -29,6 +29,7 @@ class AnalysisApiFirSourceTestConfigurator(override val analyseInDependentSessio
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
builder.apply {
useDirectives(SealedClassesInheritorsCaclulatorPreAnalysisHandler.Directives)
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
configureOptionalTestCompilerPlugin()
}