Introduce inspection "replace map.put with assignment" #KT-21502 Fixed

This commit is contained in:
Dereck Bridie
2017-12-04 18:02:45 +03:00
committed by Mikhail Glukhikh
parent ab28bdf32f
commit 8c305a137f
15 changed files with 211 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.ReplacePutWithAssignmentInspection
@@ -0,0 +1,10 @@
// PROBLEM: none
class A {
fun put(x: Int, y: String) {
}
}
fun foo() {
A().put<caret>(1, "foo")
}
@@ -0,0 +1,6 @@
// PROBLEM: none
// WITH_RUNTIME
val map = mutableMapOf(42 to "foo")
fun foo() = map.put<caret>(60, "bar")
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo(map: MutableMap<Int, String>) {
map.put<caret>(42, "foo")
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun foo(map: MutableMap<Int, String>) {
map[42] = "foo"
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class MyMap() : HashMap<String, String>() {
init {
this.put<caret>("foo", "bar")
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class MyMap() : HashMap<String, String>() {
init {
this["foo"] = "bar"
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
val map = mutableMapOf(42 to "foo")
map.put<caret>(60, "bar")
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
val map = mutableMapOf(42 to "foo")
map[60] = "bar"
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
var map = mutableMapOf(42 to "foo")
map.put<caret>(60, "bar")
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun foo() {
var map = mutableMapOf(42 to "foo")
map[60] = "bar"
}