[AA] Simplify createProjectStructureByTestStructure with KtTestModule

^KT-65960
This commit is contained in:
Marco Pennekamp
2024-02-20 20:45:27 +01:00
committed by Space Team
parent 2060709c03
commit 6cc414bdfd
2 changed files with 12 additions and 14 deletions
@@ -5,9 +5,12 @@
package org.jetbrains.kotlin.analysis.test.framework.project.structure package org.jetbrains.kotlin.analysis.test.framework.project.structure
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.analysis.project.structure.* import org.jetbrains.kotlin.analysis.project.structure.*
abstract class KtModuleWithModifiableDependencies { abstract class KtModuleWithModifiableDependencies {
abstract val project: Project
abstract val directRegularDependencies: MutableList<KtModule> abstract val directRegularDependencies: MutableList<KtModule>
abstract val directDependsOnDependencies: MutableList<KtModule> abstract val directDependsOnDependencies: MutableList<KtModule>
abstract val directFriendDependencies: MutableList<KtModule> abstract val directFriendDependencies: MutableList<KtModule>
@@ -77,11 +77,9 @@ object TestModuleStructureFactory {
val libraryCache: LibraryCache = mutableMapOf() val libraryCache: LibraryCache = mutableMapOf()
for (testModule in moduleStructure.modules) { for (ktTestModule in modules) {
val ktModule = modulesByName.getByTestModule(testModule).ktModule ktTestModule.ktModule.addToLibraryCacheIfNeeded(libraryCache)
ktTestModule.addDependencies(testServices, modulesByName, libraryCache)
ktModule.addToLibraryCacheIfNeeded(libraryCache)
ktModule.addDependencies(testModule, testServices, modulesByName, libraryCache)
} }
return KtTestModuleProjectStructure(modules, libraryCache.values) return KtTestModuleProjectStructure(modules, libraryCache.values)
@@ -132,9 +130,6 @@ object TestModuleStructureFactory {
return result return result
} }
private fun ModulesByName.getByTestModule(testModule: TestModule): KtTestModule =
this[testModule.name] ?: this.getValue(testModule.files.single().name)
/** /**
* A main module may be a binary library module, which may be a dependency of subsequent main modules. We need to add such a module to * A main module may be a binary library module, which may be a dependency of subsequent main modules. We need to add such a module to
* the library cache before it is processed as a dependency. Otherwise, when another module's binary dependency is processed, * the library cache before it is processed as a dependency. Otherwise, when another module's binary dependency is processed,
@@ -147,12 +142,11 @@ object TestModuleStructureFactory {
} }
} }
private fun KtModule.addDependencies( private fun KtTestModule.addDependencies(
testModule: TestModule,
testServices: TestServices, testServices: TestServices,
modulesByName: ModulesByName, modulesByName: ModulesByName,
libraryCache: LibraryCache, libraryCache: LibraryCache,
) = when (this) { ) = when (ktModule) {
is KtNotUnderContentRootModule -> { is KtNotUnderContentRootModule -> {
// Not-under-content-root modules have no external dependencies on purpose // Not-under-content-root modules have no external dependencies on purpose
} }
@@ -160,8 +154,8 @@ object TestModuleStructureFactory {
// Dangling file modules get dependencies from their context // Dangling file modules get dependencies from their context
} }
is KtModuleWithModifiableDependencies -> { is KtModuleWithModifiableDependencies -> {
addModuleDependencies(testModule, modulesByName, this) addModuleDependencies(testModule, modulesByName, ktModule)
addLibraryDependencies(testModule, testServices, project, this, libraryCache::getOrPut) addLibraryDependencies(testModule, testServices, ktModule, libraryCache::getOrPut)
} }
else -> error("Unexpected module type: " + javaClass.name) else -> error("Unexpected module type: " + javaClass.name)
} }
@@ -184,10 +178,11 @@ object TestModuleStructureFactory {
private fun addLibraryDependencies( private fun addLibraryDependencies(
testModule: TestModule, testModule: TestModule,
testServices: TestServices, testServices: TestServices,
project: Project,
ktModule: KtModuleWithModifiableDependencies, ktModule: KtModuleWithModifiableDependencies,
libraryCache: (paths: Set<Path>, factory: () -> KtBinaryModule) -> KtBinaryModule libraryCache: (paths: Set<Path>, factory: () -> KtBinaryModule) -> KtBinaryModule
) { ) {
val project = ktModule.project
val compilerConfiguration = testServices.compilerConfigurationProvider.getCompilerConfiguration(testModule) val compilerConfiguration = testServices.compilerConfigurationProvider.getCompilerConfiguration(testModule)
val classpathRoots = compilerConfiguration[CLIConfigurationKeys.CONTENT_ROOTS, emptyList()] val classpathRoots = compilerConfiguration[CLIConfigurationKeys.CONTENT_ROOTS, emptyList()]