Skip to content

Commit 3de723b

Browse files
t-kameyamamglukhikh
authored andcommitted
SimplifiableCallChainInspection: replace .sorted().firstOrNull() with .min()
#KT-30725 Fixed
1 parent bdac473 commit 3de723b

18 files changed

+80
-0
lines changed

idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifiableCallChainInspection.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ class SimplifiableCallChainInspection : AbstractCallChainChecker() {
7272
Conversion("kotlin.collections.filter", "kotlin.collections.singleOrNull", "singleOrNull"),
7373
Conversion("kotlin.collections.filter", "kotlin.collections.isNotEmpty", "any"),
7474
Conversion("kotlin.collections.filter", "kotlin.collections.List.isEmpty", "none"),
75+
Conversion("kotlin.collections.sorted", "kotlin.collections.firstOrNull", "min"),
76+
Conversion("kotlin.collections.sorted", "kotlin.collections.lastOrNull", "max"),
77+
Conversion("kotlin.collections.sortedDescending", "kotlin.collections.firstOrNull", "max"),
78+
Conversion("kotlin.collections.sortedDescending", "kotlin.collections.lastOrNull", "min"),
79+
Conversion("kotlin.collections.sortedBy", "kotlin.collections.firstOrNull", "minBy"),
80+
Conversion("kotlin.collections.sortedBy", "kotlin.collections.lastOrNull", "maxBy"),
81+
Conversion("kotlin.collections.sortedByDescending", "kotlin.collections.firstOrNull", "maxBy"),
82+
Conversion("kotlin.collections.sortedByDescending", "kotlin.collections.lastOrNull", "minBy"),
7583

7684
Conversion("kotlin.text.filter", "kotlin.text.first", "first"),
7785
Conversion("kotlin.text.filter", "kotlin.text.firstOrNull", "firstOrNull"),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).<caret>sortedByDescending { it.second }.firstOrNull()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).maxBy { it.second }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).<caret>sortedByDescending { it.second }.lastOrNull()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).minBy { it.second }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).<caret>sortedBy { it.second }.firstOrNull()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).minBy { it.second }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).<caret>sortedBy { it.second }.lastOrNull()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).maxBy { it.second }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf(1, 3, 2).<caret>sortedDescending().firstOrNull()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf(1, 3, 2).max()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf(1, 3, 2).<caret>sortedDescending().lastOrNull()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf(1, 3, 2).min()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf(1, 3, 2).<caret>sorted().firstOrNull()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf(1, 3, 2).min()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf(1, 3, 2).<caret>sorted().lastOrNull()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// WITH_RUNTIME
2+
val x = listOf(1, 3, 2).max()

idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)