Add "Replace 'associate' with 'associateBy' or 'associateWith'" inspection
#KT-26269 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
42120b93b8
commit
f1e66d0654
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
arrayOf(1).<caret>associate { getKey(it) to getValue(it) }
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
arrayOf(1).associateBy({ getKey(it) }, { getValue(it) })
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).<caret>associate { getKey(it) to getValue(it) }
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).associateBy({ getKey(it) }, { getValue(it) })
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).<caret>associate { i -> getKey(i) to getValue(i) }
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).associateBy({ i -> getKey(i) }, { i -> getValue(i) })
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).<caret>associate { Pair(getKey(it), getValue(it)) }
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).associateBy({ getKey(it) }, { getValue(it) })
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).<caret>associate({ getKey(it) to getValue(it) })
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).associateBy({ getKey(it) }, { getValue(it) })
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).<caret>associate { "$it" to "$it" }
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// HIGHLIGHT: INFORMATION
|
||||
// PROBLEM: Replace 'associate' with 'associateBy'
|
||||
// FIX: Replace with 'associateBy'
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).associateBy({ "$it" }, { "$it" })
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
fun getKey(i: Int): Long = 1L
|
||||
fun getValue(i: Int): String = ""
|
||||
|
||||
fun test() {
|
||||
listOf(1).<caret>associate {
|
||||
val key = getKey(it)
|
||||
val value = getValue(it)
|
||||
key to value
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user