Add "Replace 'associate' with 'associateBy' or 'associateWith'" inspection
#KT-26269 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
42120b93b8
commit
f1e66d0654
+7
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
arrayOf(1).<caret>associate { it to getValue(it) }
|
||||
}
|
||||
+8
@@ -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) }
|
||||
}
|
||||
+8
@@ -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) }
|
||||
}
|
||||
+8
@@ -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) }
|
||||
}
|
||||
+8
@@ -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) }
|
||||
}
|
||||
+8
@@ -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)) }
|
||||
}
|
||||
+8
@@ -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) }
|
||||
}
|
||||
+8
@@ -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) })
|
||||
}
|
||||
+8
@@ -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) })
|
||||
}
|
||||
+8
@@ -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" }
|
||||
}
|
||||
+8
@@ -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" }
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
intArrayOf(1).<caret>associate { it to getValue(it) }
|
||||
}
|
||||
+12
@@ -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)
|
||||
}
|
||||
}
|
||||
+11
@@ -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
|
||||
}
|
||||
}
|
||||
+11
@@ -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
|
||||
}
|
||||
}
|
||||
+13
@@ -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 ""
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -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) }
|
||||
}
|
||||
+8
@@ -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) }
|
||||
}
|
||||
+8
@@ -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) }
|
||||
}
|
||||
Reference in New Issue
Block a user