if-then --> safe access: run write action manually to avoid AWT events inside

This commit is contained in:
Mikhail Glukhikh
2017-01-31 20:37:49 +03:00
parent 834c3f5d62
commit 07f06352d7
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.idea.intentions.SelfTargetingOffsetIndependentIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
@@ -50,6 +51,8 @@ class IfThenToSafeAccessIntention : SelfTargetingOffsetIndependentIntention<KtIf
}
}
override fun startInWriteAction() = false
override fun applyTo(element: KtIfExpression, editor: Editor?) {
val condition = element.condition as KtBinaryExpression
val receiverExpression = condition.expressionComparedToNull()!!
@@ -64,7 +67,9 @@ class IfThenToSafeAccessIntention : SelfTargetingOffsetIndependentIntention<KtIf
}
val newExpr = KtPsiFactory(element).createExpressionByPattern("$0?.$1", receiverExpression, selectorExpression) as KtSafeQualifiedExpression
val safeAccessExpr = element.replaced(newExpr)
val safeAccessExpr = runWriteAction {
element.replaced(newExpr)
}
if (editor != null) {
safeAccessExpr.inlineReceiverIfApplicableWithPrompt(editor)