Add "Replace 'associate' with 'associateBy' or 'associateWith'" inspection

#KT-26269 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-01-29 19:14:44 +09:00
committed by Mikhail Glukhikh
parent 42120b93b8
commit f1e66d0654
68 changed files with 1064 additions and 0 deletions
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
arrayOf(1).<caret>associate { it to getValue(it) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).<caret>associate { it to getValue(it) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).associateWith { getValue(it) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).associate<caret> { i -> i to getValue(i) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).associateWith { i -> getValue(i) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).<caret>associate { Pair(it, getValue(it)) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).associateWith { getValue(it) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).<caret>associate({ it to getValue(it) })
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).associateWith({ getValue(it) })
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).<caret>associate { it to "$it" }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).associateWith { "$it" }
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
intArrayOf(1).<caret>associate { it to getValue(it) }
}
@@ -0,0 +1,12 @@
// PROBLEM: none
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test(b: Boolean) {
listOf(1).<caret>associate {
if (b) {
return@associate it to ""
}
it to getValue(it)
}
}
@@ -0,0 +1,11 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).<caret>associate {
val value = getValue(it)
it to value
}
}
@@ -0,0 +1,11 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
listOf(1).associateWith {
val value = getValue(it)
value
}
}
@@ -0,0 +1,13 @@
// PROBLEM: none
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test(b: Boolean) {
listOf(1).<caret>associate {
if (b) {
it to getValue(it)
} else {
it to ""
}
}
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
sequenceOf(1).<caret>associate { it to getValue(it) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
sequenceOf(1).associateWith { getValue(it) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
setOf(1).<caret>associate { it to getValue(it) }
}
@@ -0,0 +1,8 @@
// PROBLEM: Replace 'associate' with 'associateWith'
// FIX: Replace with 'associateWith'
// WITH_RUNTIME
fun getValue(i: Int): String = ""
fun test() {
setOf(1).associateWith { getValue(it) }
}