@@ -13,7 +13,7 @@ import com.intellij.psi.PsiFile
1313import com.intellij.psi.impl.source.PostprocessReformattingAspect
1414import com.intellij.refactoring.util.classMembers.MemberInfo
1515import com.intellij.testIntegration.createTest.CreateTestDialog
16- import com.intellij.testIntegration.createTest.JavaTestGenerator
16+ import com.intellij.testIntegration.createTest.TestGenerator
1717import com.intellij.util.concurrency.annotations.RequiresReadLock
1818import io.kotest.plugin.intellij.Constants
1919import io.kotest.plugin.intellij.KotestTestFramework
@@ -27,32 +27,28 @@ import org.jetbrains.kotlin.idea.KotlinLanguage
2727import org.jetbrains.kotlin.idea.refactoring.memberInfo.toKotlinMemberInfo
2828import org.jetbrains.kotlin.name.FqName
2929import java.util.Properties
30-
3130/* *
3231 * Used to create "Template" test class files.
3332 */
34- class KotestTestGenerator : JavaTestGenerator () {
33+ class KotestTestGenerator : TestGenerator {
3534
3635 override fun toString (): String = KotlinLanguage .INSTANCE .displayName
3736
38- override fun generateTest (project : Project , d : CreateTestDialog ): PsiElement ? {
39- // I do not currently know how to limit the test generator to only kotest, therefore we can check
40- // the framework name and delegate to the JavaTestGenerator one. But this only works while JavaTestGenerator
41- // is public, and has a zero arg constructor, so I would like to find a better long term solution:
42- // https://intellij-support.jetbrains.com/hc/en-us/community/posts/15040678418450-How-to-choose-when-to-apply-TestGenerator
43- if (d.selectedTestFrameworkDescriptor.name != Constants .FRAMEWORK_NAME )
44- return super .generateTest(project, d)
45- return PostprocessReformattingAspect .getInstance(project).postponeFormattingInside(Computable {
46- ApplicationManager .getApplication().runWriteAction(Computable <PsiElement ?> {
47- val file = generateTestFile(project, d)
48- if (file != null ) {
49- // without this the file is created but the caret stays in the original file
50- CodeInsightUtil .positionCursor(project, file, file)
51- }
52- file
37+ override fun generateTest (project : Project , d : CreateTestDialog ): PsiElement ? =
38+ if (d.selectedTestFrameworkDescriptor.name == Constants .FRAMEWORK_NAME ) {
39+ PostprocessReformattingAspect .getInstance(project).postponeFormattingInside(Computable {
40+ ApplicationManager .getApplication().runWriteAction(Computable <PsiElement ?> {
41+ val file = generateTestFile(project, d)
42+ if (file != null ) {
43+ // without this the file is created but the caret stays in the original file
44+ CodeInsightUtil .positionCursor(project, file, file)
45+ }
46+ file
47+ })
5348 })
54- })
55- }
49+ } else {
50+ null
51+ }
5652
5753 private fun styleForSuperClass (fqn : FqName ): SpecStyle =
5854 SpecStyle .Companion .styles.find { it.fqn() == fqn } ? : FunSpecStyle
0 commit comments