Do not run write actions from J2K #KT-16714 Fixed
Also #EA-97363 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
f950ff4b8f
commit
5e8afd26e1
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.FileModificationService
|
|||||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey
|
import com.intellij.codeInsight.daemon.HighlightDisplayKey
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import com.intellij.codeInspection.LocalInspectionEP
|
import com.intellij.codeInspection.LocalInspectionEP
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.extensions.Extensions
|
import com.intellij.openapi.extensions.Extensions
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
@@ -30,6 +31,7 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||||
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.psi.KtBlockExpression
|
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containsInside
|
import org.jetbrains.kotlin.psi.psiUtil.containsInside
|
||||||
@@ -56,6 +58,10 @@ abstract class SelfTargetingIntention<TElement : PsiElement>(
|
|||||||
|
|
||||||
abstract fun applyTo(element: TElement, editor: Editor?)
|
abstract fun applyTo(element: TElement, editor: Editor?)
|
||||||
|
|
||||||
|
protected fun <R> tryRunWriteAction(action: () -> R): R =
|
||||||
|
if (ApplicationManager.getApplication().isDispatchThread) runWriteAction(action)
|
||||||
|
else run(action)
|
||||||
|
|
||||||
private fun getTarget(editor: Editor, file: PsiFile): TElement? {
|
private fun getTarget(editor: Editor, file: PsiFile): TElement? {
|
||||||
val offset = editor.caretModel.offset
|
val offset = editor.caretModel.offset
|
||||||
val leaf1 = file.findElementAt(offset)
|
val leaf1 = file.findElementAt(offset)
|
||||||
|
|||||||
+1
-1
@@ -145,7 +145,7 @@ class IfThenToElvisIntention : SelfTargetingOffsetIndependentIntention<KtIfExpre
|
|||||||
it.typeReference!!)
|
it.typeReference!!)
|
||||||
}
|
}
|
||||||
val checkedExpression = condition.checkedExpression()!!
|
val checkedExpression = condition.checkedExpression()!!
|
||||||
val elvis = runWriteAction {
|
val elvis = tryRunWriteAction {
|
||||||
val replacedLeft = if (left.evaluatesTo(checkedExpression)) {
|
val replacedLeft = if (left.evaluatesTo(checkedExpression)) {
|
||||||
if (condition is KtIsExpression) newReceiver!! else left
|
if (condition is KtIsExpression) newReceiver!! else left
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ class IfThenToSafeAccessIntention : SelfTargetingOffsetIndependentIntention<KtIf
|
|||||||
}
|
}
|
||||||
|
|
||||||
val newExpr = KtPsiFactory(element).createExpressionByPattern("$0?.$1", receiverExpression, selectorExpression) as KtSafeQualifiedExpression
|
val newExpr = KtPsiFactory(element).createExpressionByPattern("$0?.$1", receiverExpression, selectorExpression) as KtSafeQualifiedExpression
|
||||||
val safeAccessExpr = runWriteAction {
|
val safeAccessExpr = tryRunWriteAction {
|
||||||
element.replaced(newExpr)
|
element.replaced(newExpr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user