Add "Suspicious collection reassignment" inspection #KT-20626 Fixed

This commit is contained in:
Mikhail Glukhikh
2018-11-29 16:23:00 +03:00
parent 3e936f64bf
commit c560aada3d
68 changed files with 1201 additions and 0 deletions
@@ -0,0 +1,15 @@
// "Replace with assignment" "false"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// ACTION: Change type to mutable
// ACTION: Replace overloaded operator with function call
// ACTION: Replace with ordinary assignment
// WITH_RUNTIME
fun test(other: Set<Int>) {
var list = emptyList<Int>()
foo()
bar()
list <caret>+= other
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = emptyList<Int>()
foo()
bar()
list <caret>+= otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = emptyList<Int>()
foo()
bar()
list = otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = listOf<Int>()
foo()
bar()
list <caret>+= otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = listOf<Int>()
foo()
bar()
list = otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherMap: Map<Int, Int>) {
var list = emptyMap<Int, Int>()
foo()
bar()
list <caret>+= otherMap
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherMap: Map<Int, Int>) {
var list = emptyMap<Int, Int>()
foo()
bar()
list = otherMap
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherMap: Map<Int, Int>) {
var list = mapOf<Int, Int>()
foo()
bar()
list <caret>+= otherMap
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherMap: Map<Int, Int>) {
var list = mapOf<Int, Int>()
foo()
bar()
list = otherMap
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: Set<Int>) {
var list = emptySet<Int>()
foo()
bar()
list <caret>+= otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: Set<Int>) {
var list = emptySet<Int>()
foo()
bar()
list = otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: Set<Int>) {
var list = setOf<Int>()
foo()
bar()
list <caret>+= otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,12 @@
// "Replace with assignment" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: Set<Int>) {
var list = setOf<Int>()
foo()
bar()
list = otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,15 @@
// "Replace with assignment" "false"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// ACTION: Change type to mutable
// ACTION: Replace overloaded operator with function call
// ACTION: Replace with ordinary assignment
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = listOf<Int>(1, 2, 3)
foo()
bar()
list <caret>+= otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,15 @@
// "Replace with assignment" "false"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// ACTION: Change type to mutable
// ACTION: Replace overloaded operator with function call
// ACTION: Replace with ordinary assignment
// WITH_RUNTIME
fun test(otherMap: Map<Int, Int>) {
var list = mapOf<Int, Int>(1 to 1, 2 to 2)
foo()
bar()
list <caret>+= otherMap
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,16 @@
// "Replace with assignment" "false"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// ACTION: Change type to mutable
// ACTION: Replace overloaded operator with function call
// ACTION: Replace with filter
// ACTION: Replace with ordinary assignment
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = emptyList<Int>()
foo()
bar()
list <caret>-= otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,9 @@
// "Replace with assignment" "false"
// ACTION: Replace overloaded operator with function call
// ACTION: Replace with ordinary assignment
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list: List<Int>
list = emptyList<Int>()
list +=<caret> otherList
}
@@ -0,0 +1,15 @@
// "Replace with assignment" "false"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// ACTION: Change type to mutable
// ACTION: Replace overloaded operator with function call
// ACTION: Replace with ordinary assignment
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = listOf(1, 2, 3)
foo()
bar()
list <caret>+= otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,10 @@
// "Replace with assignment" "false"
// ACTION: Replace overloaded operator with function call
// ACTION: Replace with ordinary assignment
// WITH_RUNTIME
class Test {
var list = emptyList<Int>()
fun test(otherList: List<Int>) {
list +=<caret> otherList
}
}
@@ -0,0 +1,15 @@
// "Replace with assignment" "false"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// ACTION: Change type to mutable
// ACTION: Replace overloaded operator with function call
// ACTION: Replace with ordinary assignment
// WITH_RUNTIME
fun test(otherList: Set<Int>) {
var list = setOf<Int>(1, 2, 3)
foo()
bar()
list <caret>+= otherList
}
fun foo() {}
fun bar() {}
@@ -0,0 +1,15 @@
// "Replace with assignment" "false"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// ACTION: Change type to mutable
// ACTION: Replace overloaded operator with function call
// ACTION: Replace with ordinary assignment
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = listOf<Int>()
foo(list)
bar()
list <caret>+= otherList
}
fun foo(list: List<Int>) {}
fun bar() {}