@@ -15,6 +15,7 @@ import com.intellij.ui.SimpleTextAttributes
1515import com.intellij.util.ArrayUtil
1616import com.intellij.util.ui.UIUtil
1717import java.io.File
18+ import java.util.Comparator
1819import javax.swing.DefaultComboBoxModel
1920import javax.swing.JList
2021import org.jetbrains.kotlin.idea.util.rootManager
@@ -66,14 +67,16 @@ class TestFolderComboWithBrowseButton(private val model: GenerateTestsModel) :
6667 }
6768 }
6869 // 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 {
7172 // 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
7475 // 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()
7780
7881 val theBest = if (testRoots.isNotEmpty()) testRoots[0 ] else null
7982
0 commit comments