diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/util/ImportPathComparator.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/util/ImportPathComparator.kt index a24572d30a291..0843dfb600e37 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/util/ImportPathComparator.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/util/ImportPathComparator.kt @@ -17,7 +17,10 @@ internal class ImportPathComparator(private val packageTable: KotlinPackageEntry import1, import2, { import -> bestEntryMatchIndex(import, ignoreAlias) }, - { import -> import.toString() } + { import -> + // Ignore backticks when comparing lexicographically + import.toString().replace("`", "") + } ) } diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/imports/JsOptimizeImportsTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/imports/JsOptimizeImportsTestGenerated.java index 6ec73e6cdbdf3..97b84cf435911 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/imports/JsOptimizeImportsTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/imports/JsOptimizeImportsTestGenerated.java @@ -82,6 +82,11 @@ public void testArrayAccessExpression() throws Exception { runTest("testData/editor/optimizeImports/common/ArrayAccessExpression.kt"); } + @TestMetadata("BacktickSort.kt") + public void testBacktickSort() throws Exception { + runTest("testData/editor/optimizeImports/common/BacktickSort.kt"); + } + @TestMetadata("ClassMemberImported.kt") public void testClassMemberImported() throws Exception { runTest("testData/editor/optimizeImports/common/ClassMemberImported.kt"); diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/imports/JvmOptimizeImportsTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/imports/JvmOptimizeImportsTestGenerated.java index 70ea821c994b1..23c87737270e6 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/imports/JvmOptimizeImportsTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/imports/JvmOptimizeImportsTestGenerated.java @@ -331,6 +331,11 @@ public void testArrayAccessExpression() throws Exception { runTest("testData/editor/optimizeImports/common/ArrayAccessExpression.kt"); } + @TestMetadata("BacktickSort.kt") + public void testBacktickSort() throws Exception { + runTest("testData/editor/optimizeImports/common/BacktickSort.kt"); + } + @TestMetadata("ClassMemberImported.kt") public void testClassMemberImported() throws Exception { runTest("testData/editor/optimizeImports/common/ClassMemberImported.kt"); diff --git a/plugins/kotlin/idea/tests/testData/editor/optimizeImports/common/BacktickSort.dependency.kt b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/common/BacktickSort.dependency.kt new file mode 100644 index 0000000000000..b31e749b96f5d --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/common/BacktickSort.dependency.kt @@ -0,0 +1,5 @@ +package b + +fun `fun`() {} +fun g() {} +fun `val`() {} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/editor/optimizeImports/common/BacktickSort.kt b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/common/BacktickSort.kt new file mode 100644 index 0000000000000..2917a8c14714a --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/common/BacktickSort.kt @@ -0,0 +1,14 @@ +package a + +// Should be sorted, ignoring backticks +import b.g +import b.`fun` +import b.`val` + +class Foo( + fun bar() { + g() + `fun`() + `val`() + } +) \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/editor/optimizeImports/common/BacktickSort.kt.after b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/common/BacktickSort.kt.after new file mode 100644 index 0000000000000..ff6fbe6f577e4 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/common/BacktickSort.kt.after @@ -0,0 +1,14 @@ +package a + +// Should be sorted, ignoring backticks +import b.`fun` +import b.g +import b.`val` + +class Foo( + fun bar() { + g() + `fun`() + `val`() + } +) \ No newline at end of file