[workspace model] Remove old data with next generator call e.g., if data was moved from one module to another

GitOrigin-RevId: c54867c5e0f242bc637d99dd72b3119110a600ea
This commit is contained in:
Mikhail Mazurkevich
2024-03-30 00:14:39 +00:00
committed by intellij-monorepo-bot
parent c963c26c77
commit c901128352
3 changed files with 16 additions and 9 deletions
@@ -62,10 +62,10 @@ class WorkspaceModelGenerator(private val project: Project, private val coroutin
project, module, sourceRoot.file!!,
processAbstractTypes = module.withAbstractTypes,
explicitApiEnabled = module.explicitApiEnabled,
isTestModule = module.isTestModule // TODO(It doesn't work for all modules)
) {
createGeneratedSourceFolder(module, sourceRoot)
}
isTestModule = module.isTestModule, // TODO(It doesn't work for all modules)
targetFolderGenerator = { createGeneratedSourceFolder(module, sourceRoot) },
existingTargetFolder = { sourceRoot.file?.parent?.children?.find { it.name == GENERATED_FOLDER_NAME } }
)
}
}
}
@@ -46,7 +46,8 @@ object CodeWriter {
suspend fun generate(
project: Project, module: Module, sourceFolder: VirtualFile,
processAbstractTypes: Boolean, explicitApiEnabled: Boolean, isTestModule: Boolean,
targetFolderGenerator: () -> VirtualFile?
targetFolderGenerator: () -> VirtualFile?,
existingTargetFolder: () -> VirtualFile?
) {
val sourceFilePerObjModule = HashMap<String, VirtualFile>()
val ktClasses = HashMap<String, KtClass>()
@@ -91,6 +92,11 @@ object CodeWriter {
if (generatedCode.isEmpty() || problems.any { it.level == GenerationProblem.Level.ERROR }) {
LOG.info("Not found types for generation")
val genFolder = existingTargetFolder.invoke()
if (genFolder != null) {
indicator.text = DevKitWorkspaceModelBundle.message("progress.text.removing.old.code")
removeGeneratedCode(ktClasses, genFolder)
}
return@runWriteActionWithCancellableProgressInDispatchThread
}
@@ -101,8 +107,6 @@ object CodeWriter {
}
indicator.text = DevKitWorkspaceModelBundle.message("progress.text.removing.old.code")
val psiFactory = KtPsiFactory(project)
removeGeneratedCode(ktClasses, genFolder)
val topLevelDeclarations = MultiMap.create<KtFile, Pair<KtClass, List<KtDeclaration>>>()
@@ -113,6 +117,7 @@ object CodeWriter {
indicator.isIndeterminate = false
generatedCode.forEachIndexed { i, code ->
val psiFactory = KtPsiFactory(project)
indicator.fraction = 0.15 + 0.1 * i / generatedCode.size
when (code) {
is ObjModuleFileGeneratedCode ->
@@ -147,8 +147,10 @@ abstract class CodeGenerationTestBase : KotlinLightCodeInsightFixtureTestCase()
project, module, srcRoot,
processAbstractTypes = processAbstractTypes,
explicitApiEnabled = explicitApiEnabled,
isTestModule = isTestModule
) { genRoot }
isTestModule = isTestModule,
targetFolderGenerator = { genRoot },
existingTargetFolder = { genRoot }
)
FileDocumentManager.getInstance().saveAllDocuments()
}
return srcRoot to genRoot