[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:
+1
@@ -41,6 +41,7 @@ object AnalysisApiFirLibrarySourceTestConfigurator : AnalysisApiTestConfigurator
|
|||||||
) {
|
) {
|
||||||
builder.apply {
|
builder.apply {
|
||||||
useAdditionalServices(ServiceRegistrationData(CompiledLibraryProvider::class, ::CompiledLibraryProvider))
|
useAdditionalServices(ServiceRegistrationData(CompiledLibraryProvider::class, ::CompiledLibraryProvider))
|
||||||
|
useDirectives(SealedClassesInheritorsCaclulatorPreAnalysisHandler.Directives)
|
||||||
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
|
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -24,6 +24,7 @@ object StandaloneModeConfigurator : AnalysisApiTestConfigurator() {
|
|||||||
|
|
||||||
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
|
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
|
||||||
with(builder) {
|
with(builder) {
|
||||||
|
useDirectives(SealedClassesInheritorsCaclulatorPreAnalysisHandler.Directives)
|
||||||
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
|
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -45,6 +45,7 @@ abstract class AbstractCompilerBasedTestForFir : AbstractCompilerBasedTest() {
|
|||||||
configureTest()
|
configureTest()
|
||||||
defaultConfiguration(this)
|
defaultConfiguration(this)
|
||||||
registerAnalysisApiBaseTestServices(disposable, FirLowLevelCompilerBasedTestConfigurator)
|
registerAnalysisApiBaseTestServices(disposable, FirLowLevelCompilerBasedTestConfigurator)
|
||||||
|
useDirectives(SealedClassesInheritorsCaclulatorPreAnalysisHandler.Directives)
|
||||||
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
|
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
|
||||||
|
|
||||||
firHandlersStep {
|
firHandlersStep {
|
||||||
|
|||||||
+13
@@ -19,6 +19,8 @@ import org.jetbrains.kotlin.fir.resolve.transformers.FirSealedClassInheritorsPro
|
|||||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
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.PreAnalysisHandler
|
||||||
import org.jetbrains.kotlin.test.services.TestModuleStructure
|
import org.jetbrains.kotlin.test.services.TestModuleStructure
|
||||||
import org.jetbrains.kotlin.test.services.TestServices
|
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
|
// 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.
|
// 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) {
|
override fun prepareSealedClassInheritors(moduleStructure: TestModuleStructure) {
|
||||||
|
if (Directives.DISABLE_SEALED_INHERITOR_CALCULATOR in moduleStructure.allDirectives) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val ktFilesByModule = moduleStructure.modules.associateWith { testModule ->
|
val ktFilesByModule = moduleStructure.modules.associateWith { testModule ->
|
||||||
testServices.ktModuleProvider.getModuleFiles(testModule).filterIsInstance<KtFile>()
|
testServices.ktModuleProvider.getModuleFiles(testModule).filterIsInstance<KtFile>()
|
||||||
}
|
}
|
||||||
@@ -64,4 +70,11 @@ class SealedClassesInheritorsCaclulatorPreAnalysisHandler(
|
|||||||
firFiles.forEach { it.accept(inheritorsCollector, sealedClassInheritorsMap) }
|
firFiles.forEach { it.accept(inheritorsCollector, sealedClassInheritorsMap) }
|
||||||
return sealedClassInheritorsMap.mapKeys { (firClass, _) -> firClass.symbol.classId }
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -29,6 +29,7 @@ class AnalysisApiFirSourceTestConfigurator(override val analyseInDependentSessio
|
|||||||
|
|
||||||
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
|
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
|
||||||
builder.apply {
|
builder.apply {
|
||||||
|
useDirectives(SealedClassesInheritorsCaclulatorPreAnalysisHandler.Directives)
|
||||||
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
|
usePreAnalysisHandlers(::SealedClassesInheritorsCaclulatorPreAnalysisHandler)
|
||||||
configureOptionalTestCompilerPlugin()
|
configureOptionalTestCompilerPlugin()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user