Redundant async inspection: run "optimize imports" after quick-fix

This commit is contained in:
Mikhail Glukhikh
2018-11-30 12:53:11 +03:00
parent fd3c6496fb
commit 3d15cbcced
3 changed files with 8 additions and 3 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.idea.inspections.collections
import com.intellij.codeInsight.actions.OptimizeImportsProcessor
import com.intellij.codeInspection.LocalQuickFix
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.openapi.project.Project
@@ -27,6 +28,7 @@ import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange
class SimplifyCallChainFix(
private val conversion: AbstractCallChainChecker.Conversion,
private val removeReceiverOfFirstCall: Boolean = false,
private val runOptimizeImports: Boolean = false,
private val modifyArguments: KtPsiFactory.(KtCallExpression) -> Unit = {}
) : LocalQuickFix {
private val shortenedText = conversion.replacement.substringAfterLast(".")
@@ -96,8 +98,13 @@ class SimplifyCallChainFix(
argumentsText
)
val project = qualifiedExpression.project
val file = qualifiedExpression.containingKtFile
val result = qualifiedExpression.replaced(newQualifiedExpression)
ShortenReferences.DEFAULT.process(result)
if (runOptimizeImports) {
OptimizeImportsProcessor(project, file).run()
}
}
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
@@ -73,7 +73,7 @@ class RedundantAsyncInspection : AbstractCallChainChecker() {
"Redundant 'async' call may be reduced to '${conversion.replacement}'",
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
isOnTheFly,
SimplifyCallChainFix(conversion, removeReceiverOfFirstCall = true) { callExpression ->
SimplifyCallChainFix(conversion, removeReceiverOfFirstCall = true, runOptimizeImports = true) { callExpression ->
if (contextArgument != null) {
val call = callExpression.resolveToCall()
if (call != null) {
@@ -1,8 +1,6 @@
// WITH_RUNTIME
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.withContext
suspend fun test() {