diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/JetWholeProjectModalAction.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/JetWholeProjectModalAction.kt index 9bb81ffe73f..13fc7a39090 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/JetWholeProjectModalAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/JetWholeProjectModalAction.kt @@ -52,23 +52,25 @@ public abstract class JetWholeProjectModalAction(val title: String) : In object : Task.Modal(project, title, true) { override fun run(indicator: ProgressIndicator) { val filesToData = HashMap() - val files = runReadAction { PluginJetFilesProvider.allFilesInProject(project) } + runReadAction (fun() { + val files = PluginJetFilesProvider.allFilesInProject(project) - for ((i, currentFile) in files.withIndex()) { - indicator.setText("Checking file $i of ${files.size()}...") - indicator.setText2(currentFile.getVirtualFile().getPath()) - indicator.setFraction((i + 1) / files.size().toDouble()) - try { - val data = runReadAction { collectDataForFile(project, currentFile) } - if (data != null) filesToData[currentFile] = data + for ((i, currentFile) in files.withIndex()) { + indicator.setText("Checking file $i of ${files.size()}...") + indicator.setText2(currentFile.getVirtualFile().getPath()) + indicator.setFraction((i + 1) / files.size().toDouble()) + try { + val data = collectDataForFile(project, currentFile) + if (data != null) filesToData[currentFile] = data + } + catch (e: ProcessCanceledException) { + return + } + catch (e: Throwable) { + LOG.error(e) + } } - catch (e: ProcessCanceledException) { - return - } - catch (e: Throwable) { - LOG.error(e) - } - } + }) applyAll(project, filesToData) } }) @@ -76,12 +78,14 @@ public abstract class JetWholeProjectModalAction(val title: String) : In private fun applyAll(project: Project, filesToData: Map) { UIUtil.invokeLaterIfNeeded { project.executeCommand(getText()) { - filesToData.forEach { - try { - runWriteAction { applyChangesForFile(project, it.getKey(), it.getValue()) } - } - catch (e: Throwable) { - LOG.error(e) + runWriteAction { + filesToData.forEach { + try { + applyChangesForFile(project, it.getKey(), it.getValue()) + } + catch (e: Throwable) { + LOG.error(e) + } } } } @@ -104,7 +108,7 @@ public abstract class JetWholeProjectModalByCollectionAction(modalTitle override fun collectDataForFile(project: Project, file: JetFile): Collection? { val accumulator = arrayListOf() collectTasksForFile(project, file, accumulator) - return accumulator + return if (!accumulator.isEmpty()) return accumulator else null } abstract fun collectTasksForFile(project: Project, file: JetFile, accumulator: MutableCollection)