New J2K: Fix running some post processings in incorrect thread
#KT-31234 fixed
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.nj2k
|
|||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.application.ModalityState
|
import com.intellij.openapi.application.ModalityState
|
||||||
|
import com.intellij.openapi.command.CommandProcessor
|
||||||
import com.intellij.openapi.editor.RangeMarker
|
import com.intellij.openapi.editor.RangeMarker
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
@@ -73,21 +74,22 @@ class NewJ2kPostProcessor(private val formatCode: Boolean) : PostProcessor {
|
|||||||
collectAvailableActions(this, file, converterContext, rangeMarker)
|
collectAvailableActions(this, file, converterContext, rangeMarker)
|
||||||
}
|
}
|
||||||
withContext(EDT) {
|
withContext(EDT) {
|
||||||
for ((element, action, _, writeActionNeeded) in elementToActions) {
|
CommandProcessor.getInstance().runUndoTransparentAction {
|
||||||
if (element.isValid) {
|
for ((element, action, _, writeActionNeeded) in elementToActions) {
|
||||||
if (writeActionNeeded) {
|
if (element.isValid) {
|
||||||
runWriteAction {
|
if (writeActionNeeded) {
|
||||||
|
runWriteAction {
|
||||||
|
runAction(action, element)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
runAction(action, element)
|
runAction(action, element)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
runAction(action, element)
|
modificationStamp = null
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
modificationStamp = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return modificationStamp != file.modificationStamp && elementToActions.isNotEmpty()
|
return modificationStamp != file.modificationStamp && elementToActions.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,31 +127,38 @@ class NewJ2kPostProcessor(private val formatCode: Boolean) : PostProcessor {
|
|||||||
).fixNullability(AnalysisScope(file, rangeMarker))
|
).fixNullability(AnalysisScope(file, rangeMarker))
|
||||||
}
|
}
|
||||||
withContext(EDT) {
|
withContext(EDT) {
|
||||||
runWriteAction {
|
CommandProcessor.getInstance().runUndoTransparentAction {
|
||||||
if (rangeMarker != null) {
|
runWriteAction {
|
||||||
ShortenReferences.DEFAULT.process(file, rangeMarker.startOffset, rangeMarker.endOffset)
|
if (rangeMarker != null) {
|
||||||
} else {
|
ShortenReferences.DEFAULT.process(file, rangeMarker.startOffset, rangeMarker.endOffset)
|
||||||
ShortenReferences.DEFAULT.process(file)
|
} else {
|
||||||
|
ShortenReferences.DEFAULT.process(file)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NewJ2KPostProcessingRegistrar.mainProcessings.runProcessings(file, converterContext as NewJ2kConverterContext, rangeMarker)
|
NewJ2KPostProcessingRegistrar.mainProcessings.runProcessings(file, converterContext as NewJ2kConverterContext, rangeMarker)
|
||||||
withContext(EDT) {
|
withContext(EDT) {
|
||||||
runWriteAction {
|
CommandProcessor.getInstance().runUndoTransparentAction {
|
||||||
file.commitAndUnblockDocument()
|
runWriteAction {
|
||||||
|
file.commitAndUnblockDocument()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
withContext(EDT) {
|
withContext(EDT) {
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
val codeStyleManager = CodeStyleManager.getInstance(file.project)
|
CommandProcessor.getInstance().runUndoTransparentAction {
|
||||||
if (rangeMarker != null) {
|
val codeStyleManager = CodeStyleManager.getInstance(file.project)
|
||||||
if (rangeMarker.isValid) {
|
if (rangeMarker != null) {
|
||||||
codeStyleManager.reformatRange(file, rangeMarker.startOffset, rangeMarker.endOffset)
|
if (rangeMarker.isValid) {
|
||||||
|
codeStyleManager.reformatRange(file, rangeMarker.startOffset, rangeMarker.endOffset)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
codeStyleManager.reformat(file)
|
||||||
}
|
}
|
||||||
} else {
|
Unit
|
||||||
codeStyleManager.reformat(file)
|
|
||||||
}
|
}
|
||||||
Unit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,9 +72,7 @@ class NewJavaToKotlinConverter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandProcessor.getInstance().runUndoTransparentAction {
|
AfterConversionPass(project, postProcessor).run(kotlinFile, context, range = null)
|
||||||
AfterConversionPass(project, postProcessor).run(kotlinFile, context, range = null)
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlinFile.text
|
kotlinFile.text
|
||||||
} catch (e: ProcessCanceledException) {
|
} catch (e: ProcessCanceledException) {
|
||||||
|
|||||||
Reference in New Issue
Block a user