Inspection to highlight usages of Collections.sort() and replace them with .sort() method from Kotlin stdlib

#KT-11023 Fixed
This commit is contained in:
Toshiaki Kameyama
2017-11-21 23:46:25 +09:00
committed by Dmitry Jemerov
parent 4ac870500f
commit 2cdc246a27
19 changed files with 280 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.JavaCollectionsStaticMethodInspection
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
<caret>Collections.fill(mutableList, 3)
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
mutableList.fill(3)
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
<caret>Collections.reverse(mutableList)
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
mutableList.reverse()
}
@@ -0,0 +1,8 @@
// RUNTIME_WITH_FULL_JDK
// PROBLEM: none
import java.util.Collections
fun test() {
val list = listOf(1, 2)
<caret>Collections.reverse(list)
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
<caret>Collections.shuffle(mutableList)
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
mutableList.shuffle()
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.*
fun test() {
val mutableList = mutableListOf(1, 2)
<caret>Collections.shuffle(mutableList, Random(1))
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.*
fun test() {
val mutableList = mutableListOf(1, 2)
mutableList.shuffle(Random(1))
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
<caret>Collections.sort(mutableList)
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
mutableList.sort()
}
@@ -0,0 +1,8 @@
// RUNTIME_WITH_FULL_JDK
// PROBLEM: none
import java.util.Collections
fun test() {
val list = listOf(1, 2)
<caret>Collections.sort(list)
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
<caret>Collections.sort(mutableList, { a, b -> a.compareTo(b) })
}
@@ -0,0 +1,7 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Collections
fun test() {
val mutableList = mutableListOf(1, 2)
mutableList.sortWith(Comparator { a, b -> a.compareTo(b) })
}