[AA] Tests: Remove decompiled files from LibraryBinary and add LibraryBinaryDecompiled

- `LibraryBinary` should not contain any decompiled files, as we want
  FIR symbols in tests to be provided from indexed stubs or class files,
  but definitely not from decompiled PSI. This brings `LibraryBinary`
  much closer to the behavior of binary libraries in the IDE.
- Some tests may still require access to a decompiled file, for example
  when trying to test `getOrBuildFir` for some `KtElement` coming from a
  library. This commit introduces `LibraryBinaryDecompiled`, which
  does contain decompiled files.
- We don't really need `LibraryBinary` as a main test module kind
  anymore, since tests generally want to access some main `KtFile`.
  Hence, test configurators for `LibraryBinary` have been turned into
  configurators for `LibraryBinaryDecompiled`.
- An alternative would be decompiling files on demand, but this is not
  currently feasible because the Standalone API doesn't reconcile stubs
  with decompiled PSI, like the IDE does automatically. (For the same
  declaration, the stub and the PSI will have a different identity.) As
  long as there is no support for this, we'll have to rely on a separate
  test module kind.

^KT-65960
This commit is contained in:
Marco Pennekamp
2024-02-20 22:41:10 +01:00
committed by Space Team
parent 7baaa38b8a
commit 78ef58bef4
21 changed files with 126 additions and 180 deletions
@@ -27,14 +27,14 @@ import java.util.regex.Pattern;
@SuppressWarnings("all")
@TestMetadata("analysis/analysis-api/testData/standalone/binary")
@TestDataPath("$PROJECT_ROOT")
public class FirStandaloneNormalAnalysisLibraryBinaryModulePsiDeclarationProviderTestGenerated extends AbstractPsiDeclarationProviderTest {
public class FirStandaloneNormalAnalysisLibraryBinaryDecompiledModulePsiDeclarationProviderTestGenerated extends AbstractPsiDeclarationProviderTest {
@NotNull
@Override
public AnalysisApiTestConfigurator getConfigurator() {
return AnalysisApiFirStandaloneModeTestConfiguratorFactory.INSTANCE.createConfigurator(
new AnalysisApiTestConfiguratorFactoryData(
FrontendKind.Fir,
TestModuleKind.LibraryBinary,
TestModuleKind.LibraryBinaryDecompiled,
AnalysisSessionMode.Normal,
AnalysisApiMode.Standalone
)
@@ -17,8 +17,8 @@ object AnalysisApiFirStandaloneModeTestConfiguratorFactory : AnalysisApiTestConf
AnalysisSessionMode.Dependent -> unsupportedModeError(data)
}
TestModuleKind.LibraryBinary -> when (data.analysisSessionMode) {
AnalysisSessionMode.Normal -> StandaloneModeLibraryBinaryTestConfigurator
TestModuleKind.LibraryBinaryDecompiled -> when (data.analysisSessionMode) {
AnalysisSessionMode.Normal -> StandaloneModeLibraryBinaryDecompiledTestConfigurator
AnalysisSessionMode.Dependent -> unsupportedModeError(data)
}
@@ -35,12 +35,13 @@ object AnalysisApiFirStandaloneModeTestConfiguratorFactory : AnalysisApiTestConf
data.analysisApiMode != AnalysisApiMode.Standalone -> false
else -> when (data.moduleKind) {
TestModuleKind.Source,
TestModuleKind.LibraryBinary,
TestModuleKind.LibraryBinaryDecompiled,
TestModuleKind.CodeFragment -> {
true
}
TestModuleKind.ScriptSource,
TestModuleKind.LibraryBinary,
TestModuleKind.LibrarySource,
TestModuleKind.NotUnderContentRoot -> {
false
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.analysis.api.impl.base.test.configurators.AnalysisAp
import org.jetbrains.kotlin.analysis.api.impl.base.test.configurators.AnalysisApiLibraryBaseTestServiceRegistrar
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AnalysisApiFirTestServiceRegistrar
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.configureOptionalTestCompilerPlugin
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtLibraryBinaryModuleFactory
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtLibraryBinaryDecompiledModuleFactory
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtModuleFactory
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtTestModuleProjectStructure
import org.jetbrains.kotlin.analysis.test.framework.project.structure.TestModuleStructureFactory
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.test.services.TestModuleStructure
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.configuration.ExternalAnnotationsEnvironmentConfigurator
object StandaloneModeLibraryBinaryTestConfigurator : StandaloneModeConfiguratorBase() {
object StandaloneModeLibraryBinaryDecompiledTestConfigurator : StandaloneModeConfiguratorBase() {
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
super.configureTest(builder, disposable)
@@ -38,7 +38,7 @@ object StandaloneModeLibraryBinaryTestConfigurator : StandaloneModeConfiguratorB
useConfigurators(::ExternalAnnotationsEnvironmentConfigurator)
useSourcePreprocessor(::ExternalAnnotationsSourcePreprocessor)
useAdditionalService<KtModuleFactory> { KtLibraryBinaryModuleFactory }
useAdditionalService<KtModuleFactory> { KtLibraryBinaryDecompiledModuleFactory }
useAdditionalService<TestModuleCompiler> { DispatchingTestModuleCompiler() }
useAdditionalService<TestModuleDecompiler> { TestModuleDecompilerJar() }