Create Test: Postpone J2K conversion until smart mode (matters if the user decides to add library in the Create Test dialog)
This commit is contained in:
committed by
Alexey Sedunov
parent
b6c01c0f94
commit
3ba55914c1
@@ -30,4 +30,8 @@ public fun <T> Project.runWithAlternativeResolveEnabled(action: () -> T): T {
|
||||
DumbService.getInstance(this).withAlternativeResolveEnabled { result = action() }
|
||||
@Suppress("USELESS_CAST")
|
||||
return result as T
|
||||
}
|
||||
|
||||
public fun Project.runWhenSmart(action: () -> Unit) {
|
||||
DumbService.getInstance(this).runWhenSmart(action)
|
||||
}
|
||||
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
||||
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
||||
import org.jetbrains.kotlin.idea.util.runWithAlternativeResolveEnabled
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.idea.util.runWhenSmart
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtEnumEntry
|
||||
@@ -133,32 +134,32 @@ class KotlinCreateTestIntention : JetSelfTargetingRangeIntention<KtClassOrObject
|
||||
}
|
||||
} as? PsiClass ?: return
|
||||
|
||||
project.runWhenSmart {
|
||||
val generatedFile = generatedClass.containingFile as? PsiJavaFile ?: return@runWhenSmart
|
||||
|
||||
|
||||
val generatedFile = generatedClass.containingFile as? PsiJavaFile ?: return
|
||||
|
||||
if (generatedClass.language == JavaLanguage.INSTANCE) {
|
||||
project.executeCommand("Convert class '${generatedClass.name}' to Kotlin", this) {
|
||||
runWriteAction {
|
||||
generatedClass.methods.forEach { it.throwsList.referenceElements.forEach { it.delete() } }
|
||||
}
|
||||
|
||||
if (existingClass != null) {
|
||||
if (generatedClass.language == JavaLanguage.INSTANCE) {
|
||||
project.executeCommand("Convert class '${generatedClass.name}' to Kotlin", this) {
|
||||
runWriteAction {
|
||||
val existingMethodNames = existingClass
|
||||
.declarations
|
||||
.filterIsInstance<KtNamedFunction>()
|
||||
.mapTo(HashSet()) { it.name }
|
||||
generatedClass
|
||||
.methods
|
||||
.filter { it.name !in existingMethodNames }
|
||||
.forEach { it.j2k()?.let { existingClass.addDeclaration(it) } }
|
||||
generatedClass.delete()
|
||||
generatedClass.methods.forEach { it.throwsList.referenceElements.forEach { it.delete() } }
|
||||
}
|
||||
|
||||
if (existingClass != null) {
|
||||
runWriteAction {
|
||||
val existingMethodNames = existingClass
|
||||
.declarations
|
||||
.filterIsInstance<KtNamedFunction>()
|
||||
.mapTo(HashSet()) { it.name }
|
||||
generatedClass
|
||||
.methods
|
||||
.filter { it.name !in existingMethodNames }
|
||||
.forEach { it.j2k()?.let { existingClass.addDeclaration(it) } }
|
||||
generatedClass.delete()
|
||||
}
|
||||
NavigationUtil.activateFileWithPsiElement(existingClass)
|
||||
}
|
||||
else {
|
||||
JavaToKotlinAction.convertFiles(generatedFile.singletonList(), project, false).singleOrNull()
|
||||
}
|
||||
NavigationUtil.activateFileWithPsiElement(existingClass)
|
||||
}
|
||||
else {
|
||||
JavaToKotlinAction.convertFiles(generatedFile.singletonList(), project, false).singleOrNull()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user