Skip to content

Commit

Permalink
[kotlin] Ignore backticks when comparing imports
Browse files Browse the repository at this point in the history
This helps preserve their ordering when sorted lexicographically

^KTIJ-19394 Fixed

closes #1879

GitOrigin-RevId: ebc5922726a030aff75903fe130a06791166b18c
  • Loading branch information
nbadal authored and intellij-monorepo-bot committed Dec 20, 2021
1 parent 89db917 commit ce851ed
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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("`", "")
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package b

fun `fun`() {}
fun g() {}
fun `val`() {}
Original file line number Diff line number Diff line change
@@ -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`()
}
)
Original file line number Diff line number Diff line change
@@ -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`()
}
)

0 comments on commit ce851ed

Please sign in to comment.