@@ -15,6 +15,7 @@ import com.intellij.ui.SimpleTextAttributes
15
15
import com.intellij.util.ArrayUtil
16
16
import com.intellij.util.ui.UIUtil
17
17
import java.io.File
18
+ import java.util.Comparator
18
19
import javax.swing.DefaultComboBoxModel
19
20
import javax.swing.JList
20
21
import org.jetbrains.kotlin.idea.util.rootManager
@@ -66,14 +67,16 @@ class TestFolderComboWithBrowseButton(private val model: GenerateTestsModel) :
66
67
}
67
68
}
68
69
// The first sorting to obtain the best candidate
69
- val testRoots = model.getAllTestSourceRoots().distinct().sortedWith(
70
- compareByDescending< TestSourceRoot > {
70
+ val testRoots = model.getAllTestSourceRoots().distinct().sortedWith(object : Comparator < TestSourceRoot > {
71
+ override fun compare ( o1 : TestSourceRoot , o2 : TestSourceRoot ): Int {
71
72
// Heuristics: Dirs with language == codegenLanguage should go first
72
- it .expectedLanguage == model.codegenLanguage
73
- }.thenBy {
73
+ val languageOrder = (o1 .expectedLanguage == model.codegenLanguage).compareTo(o2.expectedLanguage == model.codegenLanguage)
74
+ if (languageOrder != 0 ) return - languageOrder
74
75
// Heuristics: move root that is 'closer' to module 'common' directory to the first position
75
- StringUtil .commonPrefixLength(commonModuleSourceDirectory, it.dir.toNioPath().toString())
76
- }).toMutableList()
76
+ return - StringUtil .commonPrefixLength(commonModuleSourceDirectory, o1.dir.toNioPath().toString())
77
+ .compareTo(StringUtil .commonPrefixLength(commonModuleSourceDirectory, o2.dir.toNioPath().toString()))
78
+ }
79
+ }).toMutableList()
77
80
78
81
val theBest = if (testRoots.isNotEmpty()) testRoots[0 ] else null
79
82
0 commit comments