Skip to content

Commit 07f0635

Browse files
committed
if-then --> safe access: run write action manually to avoid AWT events inside
1 parent 834c3f5 commit 07f0635

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToSafeAccessIntention.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.idea.core.replaced
2121
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
2222
import org.jetbrains.kotlin.idea.intentions.SelfTargetingOffsetIndependentIntention
2323
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
24+
import org.jetbrains.kotlin.idea.util.application.runWriteAction
2425
import org.jetbrains.kotlin.lexer.KtTokens
2526
import org.jetbrains.kotlin.psi.*
2627

@@ -50,6 +51,8 @@ class IfThenToSafeAccessIntention : SelfTargetingOffsetIndependentIntention<KtIf
5051
}
5152
}
5253

54+
override fun startInWriteAction() = false
55+
5356
override fun applyTo(element: KtIfExpression, editor: Editor?) {
5457
val condition = element.condition as KtBinaryExpression
5558
val receiverExpression = condition.expressionComparedToNull()!!
@@ -64,7 +67,9 @@ class IfThenToSafeAccessIntention : SelfTargetingOffsetIndependentIntention<KtIf
6467
}
6568

6669
val newExpr = KtPsiFactory(element).createExpressionByPattern("$0?.$1", receiverExpression, selectorExpression) as KtSafeQualifiedExpression
67-
val safeAccessExpr = element.replaced(newExpr)
70+
val safeAccessExpr = runWriteAction {
71+
element.replaced(newExpr)
72+
}
6873

6974
if (editor != null) {
7075
safeAccessExpr.inlineReceiverIfApplicableWithPrompt(editor)

0 commit comments

Comments
 (0)