Add inspection to replace Java Map.forEach with Kotlin's forEach

#KT-17278 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-02-01 06:37:54 +03:00
committed by Mikhail Glukhikh
parent 9c674cb7c3
commit 1a818970c3
19 changed files with 214 additions and 2 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.JavaMapForEachInspection
+8
View File
@@ -0,0 +1,8 @@
// RUNTIME_WITH_FULL_JDK
fun test(map: Map<Int, String>) {
map.<caret>forEach { key, value ->
foo(key, value)
}
}
fun foo(i: Int, s: String) {}
@@ -0,0 +1,8 @@
// RUNTIME_WITH_FULL_JDK
fun test(map: Map<Int, String>) {
map.forEach { (key, value) ->
foo(key, value)
}
}
fun foo(i: Int, s: String) {}
@@ -0,0 +1,8 @@
// RUNTIME_WITH_FULL_JDK
fun test(hashMap: HashMap<Int, String>) {
hashMap.<caret>forEach { key, value ->
foo(key, value)
}
}
fun foo(i: Int, s: String) {}
@@ -0,0 +1,8 @@
// RUNTIME_WITH_FULL_JDK
fun test(hashMap: HashMap<Int, String>) {
hashMap.forEach { (key, value) ->
foo(key, value)
}
}
fun foo(i: Int, s: String) {}
@@ -0,0 +1,6 @@
// RUNTIME_WITH_FULL_JDK
fun test(map: Map<Int, String>) {
map.forEach<caret>({ key, value -> foo(key, value) })
}
fun foo(i: Int, s: String) {}
@@ -0,0 +1,6 @@
// RUNTIME_WITH_FULL_JDK
fun test(map: Map<Int, String>) {
map.forEach({ (key, value) -> foo(key, value) })
}
fun foo(i: Int, s: String) {}
@@ -0,0 +1,9 @@
// PROBLEM: none
// WITH_RUNTIME
fun test(map: Map<Int, String>) {
map.<caret>forEach { (key, value) ->
foo(key, value)
}
}
fun foo(i: Int, s: String) {}
@@ -0,0 +1,8 @@
// PROBLEM: none
// WITH_RUNTIME
fun test(map: Map<Int, String>) {
map.<caret>forEach {
foo(it)
}
}
fun foo(it: Map.Entry<Int, String>) {}