[AA] Turn KtModuleWithFiles into KtTestModule (AA test framework)

- `KtModuleWithFiles` isn't actually used in a production Standalone API
  context, but it was exposed via `analysis-api-standalone-base`. In
  current production usages, the project structure is built with the
  module builder DSL.
- Hence, `KtModuleWithFiles` is only relevant for tests. This commit
  moves `KtModuleWithFiles` to the Analysis API test framework and
  renames it to `KtTestModule`. This removes any risk that an outside
  user could start using `KtModuleWithFiles` and completely uncouples
  the test project structure from production APIs.
- In addition, we can add the `TestModule` to `KtTestModule`, allowing
  tests to quickly access the original test module, for example to check
  the test module kind.
- The commit also removes the data class status of `KtTestModule` and
  `KtTestModuleProjectStructure` to avoid issues with destructuring when
  properties are added or removed.

^KT-65960
This commit is contained in:
Marco Pennekamp
2024-02-20 20:37:23 +01:00
committed by Space Team
parent 878eba7d52
commit 2060709c03
23 changed files with 128 additions and 115 deletions
@@ -1,34 +0,0 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.analysis.api.standalone.base.project.structure
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiFileSystemItem
import com.intellij.psi.PsiJavaFile
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.StandaloneProjectFactory.findJvmRootsForJavaFiles
import org.jetbrains.kotlin.analysis.project.structure.KtBinaryModule
import org.jetbrains.kotlin.analysis.project.structure.KtModule
data class KtModuleProjectStructure(
val mainModules: List<KtModuleWithFiles>,
val binaryModules: Iterable<KtBinaryModule>,
) {
fun allKtModules(): List<KtModule> = buildList {
mainModules.mapTo(this) { it.ktModule }
addAll(binaryModules)
}
fun allSourceFiles(): List<PsiFileSystemItem> = buildList {
val files = mainModules.flatMap { it.files }
addAll(files)
addAll(findJvmRootsForJavaFiles(files.filterIsInstance<PsiJavaFile>()))
}
}
data class KtModuleWithFiles(
val ktModule: KtModule,
val files: List<PsiFile>
)