Generate test support: error hints moved out of write action
This commit is contained in:
+8
-6
@@ -164,15 +164,16 @@ abstract class KotlinGenerateTestSupportActionBase(
|
|||||||
templateText = fileTemplate.text.replace(NAME_VAR, DUMMY_NAME)
|
templateText = fileTemplate.text.replace(NAME_VAR, DUMMY_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
project.executeWriteCommand(commandName) {
|
try {
|
||||||
try {
|
var errorHint: String? = null
|
||||||
|
project.executeWriteCommand(commandName) {
|
||||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||||
|
|
||||||
val factory = PsiElementFactory.SERVICE.getInstance(project)
|
val factory = PsiElementFactory.SERVICE.getInstance(project)
|
||||||
val psiMethod = factory.createMethodFromText(templateText, null)
|
val psiMethod = factory.createMethodFromText(templateText, null)
|
||||||
psiMethod.throwsList.referenceElements.forEach { it.delete() }
|
psiMethod.throwsList.referenceElements.forEach { it.delete() }
|
||||||
var function = psiMethod.j2k() as? KtNamedFunction ?: run {
|
var function = psiMethod.j2k() as? KtNamedFunction ?: run {
|
||||||
HintManager.getInstance().showErrorHint(editor, "Couldn't convert Java template to Kotlin")
|
errorHint = "Couldn't convert Java template to Kotlin"
|
||||||
return@executeWriteCommand
|
return@executeWriteCommand
|
||||||
}
|
}
|
||||||
name?.let {
|
name?.let {
|
||||||
@@ -196,9 +197,10 @@ abstract class KotlinGenerateTestSupportActionBase(
|
|||||||
|
|
||||||
setupEditorSelection(editor, functionInPlace)
|
setupEditorSelection(editor, functionInPlace)
|
||||||
}
|
}
|
||||||
catch (e: IncorrectOperationException) {
|
errorHint?.let { HintManager.getInstance().showErrorHint(editor, it) }
|
||||||
HintManager.getInstance().showErrorHint(editor, "Cannot generate method: " + e.message)
|
}
|
||||||
}
|
catch (e: IncorrectOperationException) {
|
||||||
|
HintManager.getInstance().showErrorHint(editor, "Cannot generate method: " + e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user