From 29479603e3f5486926b49347f46f5507b435c78c Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 31 Aug 2015 19:12:08 +0300 Subject: [PATCH] Minor --- .../DeprecatedSymbolUsageInWholeProjectFix.kt | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageInWholeProjectFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageInWholeProjectFix.kt index 8f59e837c57..0afa6f2dde6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageInWholeProjectFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageInWholeProjectFix.kt @@ -35,9 +35,8 @@ import org.jetbrains.kotlin.idea.core.targetDescriptors import org.jetbrains.kotlin.idea.references.JetSimpleNameReference import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.stubindex.JetSourceFilterScope -import org.jetbrains.kotlin.idea.util.application.executeCommand +import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.idea.util.application.runReadAction -import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.psi.JetImportDirective import org.jetbrains.kotlin.psi.JetNamedFunction import org.jetbrains.kotlin.psi.JetProperty @@ -96,36 +95,34 @@ public class DeprecatedSymbolUsageInWholeProjectFix( private fun replaceUsages(project: Project, usages: Collection, replacement: ReplaceWithAnnotationAnalyzer.ReplacementExpression) { UIUtil.invokeLaterIfNeeded { - project.executeCommand(getText()) { - runWriteAction { - // we should delete imports later to not affect other usages - val importsToDelete = arrayListOf() + project.executeWriteCommand(text) { + // we should delete imports later to not affect other usages + val importsToDelete = arrayListOf() - for (usage in usages) { - try { - if (!usage.isValid()) continue // TODO: nested calls + for (usage in usages) { + try { + if (!usage.isValid()) continue // TODO: nested calls - val importDirective = usage.getStrictParentOfType() - if (importDirective != null) { - if (!importDirective.isAllUnder && importDirective.targetDescriptors().size() == 1) { - importsToDelete.add(importDirective) - } - continue + val importDirective = usage.getStrictParentOfType() + if (importDirective != null) { + if (!importDirective.isAllUnder && importDirective.targetDescriptors().size() == 1) { + importsToDelete.add(importDirective) } + continue + } - val bindingContext = usage.analyze(BodyResolveMode.PARTIAL) - val resolvedCall = usage.getResolvedCall(bindingContext) ?: continue - if (!resolvedCall.getStatus().isSuccess()) continue - // copy replacement expression because it is modified by performReplacement - DeprecatedSymbolUsageFixBase.performReplacement(usage, bindingContext, resolvedCall, replacement.copy()) - } - catch (e: Throwable) { - LOG.error(e) - } + val bindingContext = usage.analyze(BodyResolveMode.PARTIAL) + val resolvedCall = usage.getResolvedCall(bindingContext) ?: continue + if (!resolvedCall.getStatus().isSuccess()) continue + // copy replacement expression because it is modified by performReplacement + DeprecatedSymbolUsageFixBase.performReplacement(usage, bindingContext, resolvedCall, replacement.copy()) + } + catch (e: Throwable) { + LOG.error(e) } - - importsToDelete.forEach { it.delete() } } + + importsToDelete.forEach { it.delete() } } } }