diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml
index 1f00996d0f1..503b5dbda6c 100644
--- a/idea/resources/META-INF/plugin-common.xml
+++ b/idea/resources/META-INF/plugin-common.xml
@@ -3155,6 +3155,15 @@
language="kotlin"
/>
+
+
diff --git a/idea/resources/inspectionDescriptions/SuspiciousCollectionReassignment.html b/idea/resources/inspectionDescriptions/SuspiciousCollectionReassignment.html
new file mode 100644
index 00000000000..52fb972da5a
--- /dev/null
+++ b/idea/resources/inspectionDescriptions/SuspiciousCollectionReassignment.html
@@ -0,0 +1,13 @@
+
+
+This inspection reports non-mutable Collection augmented assignment creates a new Collection under the hood.
+Example:
+
+
+
+var list = listOf(1, 2, 3)
+list += 4 // A new list is created
+
+
+
+
diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/SuspiciousCollectionReassignmentInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/SuspiciousCollectionReassignmentInspection.kt
new file mode 100644
index 00000000000..c69b5da4c37
--- /dev/null
+++ b/idea/src/org/jetbrains/kotlin/idea/inspections/SuspiciousCollectionReassignmentInspection.kt
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
+ * that can be found in the license/LICENSE.txt file.
+ */
+
+package org.jetbrains.kotlin.idea.inspections
+
+import com.intellij.codeInspection.LocalQuickFix
+import com.intellij.codeInspection.ProblemDescriptor
+import com.intellij.codeInspection.ProblemHighlightType
+import com.intellij.codeInspection.ProblemsHolder
+import com.intellij.openapi.project.Project
+import com.intellij.psi.PsiElementVisitor
+import org.jetbrains.kotlin.descriptors.ClassDescriptor
+import org.jetbrains.kotlin.diagnostics.Severity
+import org.jetbrains.kotlin.idea.caches.resolve.analyze
+import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
+import org.jetbrains.kotlin.idea.core.replaced
+import org.jetbrains.kotlin.idea.project.builtIns
+import org.jetbrains.kotlin.idea.references.mainReference
+import org.jetbrains.kotlin.lexer.KtSingleValueToken
+import org.jetbrains.kotlin.lexer.KtTokens
+import org.jetbrains.kotlin.psi.*
+import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType
+import org.jetbrains.kotlin.psi.psiUtil.endOffset
+import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespaceAndComments
+import org.jetbrains.kotlin.psi.psiUtil.siblings
+import org.jetbrains.kotlin.resolve.BindingContext
+import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
+import org.jetbrains.kotlin.resolve.calls.callUtil.getType
+import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
+import org.jetbrains.kotlin.resolve.descriptorUtil.isSubclassOf
+import org.jetbrains.kotlin.types.KotlinType
+import org.jetbrains.kotlin.types.SimpleType
+
+class SuspiciousCollectionReassignmentInspection : AbstractKotlinInspection() {
+
+ private val targetOperations: List = listOf(KtTokens.PLUSEQ, KtTokens.MINUSEQ)
+
+ override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor =
+ binaryExpressionVisitor(fun(binaryExpression) {
+ if (binaryExpression.right == null) return
+ val operationToken = binaryExpression.operationToken as? KtSingleValueToken ?: return
+ if (operationToken !in targetOperations) return
+ val left = binaryExpression.left ?: return
+ val property = left.mainReference?.resolve() as? KtProperty ?: return
+ if (!property.isVar) return
+
+ val context = binaryExpression.analyze()
+ val leftType = left.getType(context) ?: return
+ val leftDefaultType = leftType.constructor.declarationDescriptor?.defaultType ?: return
+ val builtIns = binaryExpression.builtIns
+ if (leftDefaultType !in listOf(builtIns.list.defaultType, builtIns.set.defaultType, builtIns.map.defaultType)) return
+ if (context.diagnostics.forElement(binaryExpression).any { it.severity == Severity.ERROR }) return
+
+ val fixes = mutableListOf()
+ if (ChangeTypeToMutableFix.isApplicable(property)) {
+ fixes.add(ChangeTypeToMutableFix(leftType))
+ }
+ if (ReplaceWithFilterFix.isApplicable(binaryExpression, leftDefaultType, context)) {
+ fixes.add(ReplaceWithFilterFix())
+ }
+ if (ReplaceWithAssignmentFix.isApplicable(binaryExpression, property, context)) {
+ fixes.add(ReplaceWithAssignmentFix())
+ }
+ if (JoinWithInitializerFix.isApplicable(binaryExpression, property)) {
+ fixes.add(JoinWithInitializerFix(operationToken))
+ }
+
+ val typeText = leftDefaultType.toString().takeWhile { it != '<' }.toLowerCase()
+ val operationReference = binaryExpression.operationReference
+ holder.registerProblem(
+ operationReference,
+ "'${operationReference.text}' create new $typeText under the hood",
+ ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
+ *fixes.toTypedArray()
+ )
+ })
+
+ private class ChangeTypeToMutableFix(private val type: KotlinType) : LocalQuickFix {
+ override fun getName() = "Change type to mutable"
+
+ override fun getFamilyName() = name
+
+ override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
+ val operationReference = descriptor.psiElement as? KtOperationReferenceExpression ?: return
+ val binaryExpression = operationReference.parent as? KtBinaryExpression ?: return
+ val left = binaryExpression.left ?: return
+ val property = left.mainReference?.resolve() as? KtProperty ?: return
+ val initializer = property.initializer ?: return
+ val fqName = initializer.resolveToCall()?.resultingDescriptor?.fqNameOrNull()?.asString()
+ val psiFactory = KtPsiFactory(binaryExpression)
+ val mutableOf = when (fqName) {
+ "kotlin.collections.listOf" -> "mutableListOf"
+ "kotlin.collections.setOf" -> "mutableSetOf"
+ "kotlin.collections.mapOf" -> "mutableMapOf"
+ else -> null
+ }
+ if (mutableOf != null) {
+ (initializer as? KtCallExpression)?.calleeExpression?.replaced(psiFactory.createExpression(mutableOf)) ?: return
+ } else {
+ val builtIns = binaryExpression.builtIns
+ val toMutable = when (type.constructor) {
+ builtIns.list.defaultType.constructor -> "toMutableList"
+ builtIns.set.defaultType.constructor -> "toMutableSet"
+ builtIns.map.defaultType.constructor -> "toMutableMap"
+ else -> null
+ } ?: return
+ val dotQualifiedExpression = initializer.replaced(
+ psiFactory.createExpressionByPattern("($0).$1()", initializer, toMutable)
+ ) as KtDotQualifiedExpression
+ val receiver = dotQualifiedExpression.receiverExpression
+ val deparenthesize = KtPsiUtil.deparenthesize(dotQualifiedExpression.receiverExpression)
+ if (deparenthesize != null && receiver != deparenthesize) receiver.replace(deparenthesize)
+ }
+ property.typeReference?.also { it.replace(psiFactory.createType("Mutable${it.text}")) }
+ property.valOrVarKeyword.replace(psiFactory.createValKeyword())
+ binaryExpression.findExistingEditor()?.caretModel?.moveToOffset(property.endOffset)
+ }
+
+ companion object {
+ fun isApplicable(property: KtProperty): Boolean {
+ return property.isLocal && property.initializer != null
+ }
+ }
+ }
+
+ private class ReplaceWithFilterFix : LocalQuickFix {
+ override fun getName() = "Replace with filter"
+
+ override fun getFamilyName() = name
+
+ override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
+ val operationReference = descriptor.psiElement as? KtOperationReferenceExpression ?: return
+ val binaryExpression = operationReference.parent as? KtBinaryExpression ?: return
+ val left = binaryExpression.left ?: return
+ val right = binaryExpression.right ?: return
+ val psiFactory = KtPsiFactory(operationReference)
+ operationReference.replace(psiFactory.createOperationName(KtTokens.EQ.value))
+ right.replace(psiFactory.createExpressionByPattern("$0.filter { it !in $1 }", left, right))
+ }
+
+ companion object {
+ fun isApplicable(binaryExpression: KtBinaryExpression, leftType: SimpleType, context: BindingContext): Boolean {
+ if (binaryExpression.operationToken != KtTokens.MINUSEQ) return false
+ if (leftType == binaryExpression.builtIns.map.defaultType) return false
+ return binaryExpression.right?.getType(context)?.classDescriptor()?.isSubclassOf(binaryExpression.builtIns.iterable) == true
+ }
+ }
+ }
+
+ private class ReplaceWithAssignmentFix : LocalQuickFix {
+ override fun getName() = "Replace with assignment"
+
+ override fun getFamilyName() = name
+
+ override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
+ val operationReference = descriptor.psiElement as? KtOperationReferenceExpression ?: return
+ val psiFactory = KtPsiFactory(operationReference)
+ operationReference.replace(psiFactory.createOperationName(KtTokens.EQ.value))
+ }
+
+ companion object {
+ val emptyCollectionFactoryMethods =
+ listOf("emptyList", "emptySet", "emptyMap", "listOf", "setOf", "mapOf").map { "kotlin.collections.$it" }
+
+ fun isApplicable(binaryExpression: KtBinaryExpression, property: KtProperty, context: BindingContext): Boolean {
+ if (binaryExpression.operationToken != KtTokens.PLUSEQ) return false
+
+ if (!property.isLocal) return false
+ val initializer = property.initializer as? KtCallExpression ?: return false
+
+ if (initializer.valueArguments.isNotEmpty()) return false
+ val initializerResultingDescriptor = initializer.getResolvedCall(context)?.resultingDescriptor
+ val fqName = initializerResultingDescriptor?.fqNameOrNull()?.asString()
+ if (fqName !in emptyCollectionFactoryMethods) return false
+
+ val rightClassDescriptor = binaryExpression.right?.getType(context)?.classDescriptor() ?: return false
+ val initializerClassDescriptor = initializerResultingDescriptor?.returnType?.classDescriptor() ?: return false
+ if (!rightClassDescriptor.isSubclassOf(initializerClassDescriptor)) return false
+
+ if (binaryExpression.siblings(forward = false, withItself = false)
+ .filter { it != property }
+ .any { sibling -> sibling.anyDescendantOfType { it.mainReference.resolve() == property } }
+ ) return false
+
+ return true
+ }
+ }
+ }
+
+ private class JoinWithInitializerFix(private val op: KtSingleValueToken) : LocalQuickFix {
+ override fun getName() = "Join with initializer"
+
+ override fun getFamilyName() = name
+
+ override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
+ val operationReference = descriptor.psiElement as? KtOperationReferenceExpression ?: return
+ val binaryExpression = operationReference.parent as? KtBinaryExpression ?: return
+ val left = binaryExpression.left ?: return
+ val right = binaryExpression.right ?: return
+ val property = left.mainReference?.resolve() as? KtProperty ?: return
+ val initializer = property.initializer ?: return
+
+ val psiFactory = KtPsiFactory(operationReference)
+ val newOp = if (op == KtTokens.PLUSEQ) KtTokens.PLUS else KtTokens.MINUS
+ val replaced = initializer.replaced(psiFactory.createExpressionByPattern("$0 $1 $2", initializer, newOp.value, right))
+ binaryExpression.delete()
+ property.findExistingEditor()?.caretModel?.moveToOffset(replaced.endOffset)
+ }
+
+ companion object {
+ fun isApplicable(binaryExpression: KtBinaryExpression, property: KtProperty): Boolean {
+ if (!property.isLocal || property.initializer == null) return false
+ return binaryExpression.getPrevSiblingIgnoringWhitespaceAndComments() == property
+ }
+ }
+ }
+}
+
+private fun KotlinType.classDescriptor() = constructor.declarationDescriptor as? ClassDescriptor
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/.inspection b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/.inspection
new file mode 100644
index 00000000000..73a644a99df
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/.inspection
@@ -0,0 +1 @@
+org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/hasError.kt b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/hasError.kt
new file mode 100644
index 00000000000..dc178c211b6
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/hasError.kt
@@ -0,0 +1,7 @@
+// PROBLEM: none
+// WITH_RUNTIME
+// ERROR: Type mismatch: inferred type is List but List was expected
+fun test() {
+ var list = listOf("")
+ list += 1
+}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/int.kt b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/int.kt
new file mode 100644
index 00000000000..6362abf2d92
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/int.kt
@@ -0,0 +1,5 @@
+// PROBLEM: none
+fun test() {
+ var i = 1
+ i += 2
+}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/minus.kt b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/minus.kt
new file mode 100644
index 00000000000..63cf4f7d0e5
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/minus.kt
@@ -0,0 +1,6 @@
+// PROBLEM: none
+// WITH_RUNTIME
+fun test() {
+ var list = listOf(1)
+ list - 1
+}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableList.kt b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableList.kt
new file mode 100644
index 00000000000..a0c0ca000f3
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableList.kt
@@ -0,0 +1,7 @@
+// PROBLEM: none
+// ERROR: Assignment operators ambiguity:
public operator fun Collection.plus(element: Int): List defined in kotlin.collections
@InlineOnly public inline operator fun MutableCollection.plusAssign(element: Int): Unit defined in kotlin.collections
+// WITH_RUNTIME
+fun test() {
+ var list = mutableListOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableMap.kt b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableMap.kt
new file mode 100644
index 00000000000..be3dfd1da1c
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableMap.kt
@@ -0,0 +1,7 @@
+// PROBLEM: none
+// ERROR: Assignment operators ambiguity:
public operator fun Map.plus(pair: Pair): Map defined in kotlin.collections
@InlineOnly public inline operator fun MutableMap.plusAssign(pair: Pair): Unit defined in kotlin.collections
+// WITH_RUNTIME
+fun test() {
+ var map = mutableMapOf(1 to 2)
+ map += 3 to 4
+}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableSet.kt b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableSet.kt
new file mode 100644
index 00000000000..601d370092f
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableSet.kt
@@ -0,0 +1,7 @@
+// PROBLEM: none
+// ERROR: Assignment operators ambiguity:
public operator fun Set.plus(element: Int): Set defined in kotlin.collections
@InlineOnly public inline operator fun MutableCollection.plusAssign(element: Int): Unit defined in kotlin.collections
+// WITH_RUNTIME
+fun test() {
+ var set = mutableSetOf(1)
+ set += 2
+}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/plus.kt b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/plus.kt
new file mode 100644
index 00000000000..7b51c431aa7
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/plus.kt
@@ -0,0 +1,6 @@
+// PROBLEM: none
+// WITH_RUNTIME
+fun test() {
+ var list = listOf(1)
+ list + 2
+}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/simple.kt b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/simple.kt
new file mode 100644
index 00000000000..dbcb6027117
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/simple.kt
@@ -0,0 +1,6 @@
+// FIX: Change type to mutable
+// WITH_RUNTIME
+fun test() {
+ var list = listOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/simple.kt.after b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/simple.kt.after
new file mode 100644
index 00000000000..24c3ed9c3f8
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/simple.kt.after
@@ -0,0 +1,6 @@
+// FIX: Change type to mutable
+// WITH_RUNTIME
+fun test() {
+ val list = mutableListOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/val.kt b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/val.kt
new file mode 100644
index 00000000000..e98acc11cbb
--- /dev/null
+++ b/idea/testData/inspectionsLocal/suspiciousCollectionReassignment/val.kt
@@ -0,0 +1,6 @@
+// PROBLEM: none
+// WITH_RUNTIME
+fun test() {
+ val list = mutableListOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType.kt
new file mode 100644
index 00000000000..a05aecd9f3f
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType.kt
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ var list: List = listOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType.kt.after
new file mode 100644
index 00000000000..77e607b17ea
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType.kt.after
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ val list: MutableList = mutableListOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType2.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType2.kt
new file mode 100644
index 00000000000..1fe276d534e
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType2.kt
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ var list = listOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType2.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType2.kt.after
new file mode 100644
index 00000000000..6b186a81291
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType2.kt.after
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ val list = mutableListOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableListOf.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableListOf.kt
new file mode 100644
index 00000000000..8e08bd2554e
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableListOf.kt
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ var list = listOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableListOf.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableListOf.kt.after
new file mode 100644
index 00000000000..5a47190908c
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableListOf.kt.after
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ val list = mutableListOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableMapOf.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableMapOf.kt
new file mode 100644
index 00000000000..b9f8b026451
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableMapOf.kt
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ var map = mapOf(1 to 2)
+ map += 3 to 4
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableMapOf.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableMapOf.kt.after
new file mode 100644
index 00000000000..056d821ac8d
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableMapOf.kt.after
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ val map = mutableMapOf(1 to 2)
+ map += 3 to 4
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableSetOf.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableSetOf.kt
new file mode 100644
index 00000000000..d53a1f2f64a
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableSetOf.kt
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ var set = setOf(1)
+ set += 1
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableSetOf.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableSetOf.kt.after
new file mode 100644
index 00000000000..fba1980c76e
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableSetOf.kt.after
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ val set = mutableSetOf(1)
+ set += 1
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/noInitializer.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/noInitializer.kt
new file mode 100644
index 00000000000..88d17b51ed7
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/noInitializer.kt
@@ -0,0 +1,10 @@
+// "Change type to mutable" "false"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// ACTION: Replace overloaded operator with function call
+// ACTION: Replace with ordinary assignment
+// WITH_RUNTIME
+fun test() {
+ var list: List
+ list = listOf(1)
+ list += 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/notLocal.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/notLocal.kt
new file mode 100644
index 00000000000..ceb37149d75
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/notLocal.kt
@@ -0,0 +1,11 @@
+// "Change type to mutable" "false"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// ACTION: Replace overloaded operator with function call
+// ACTION: Replace with ordinary assignment
+// WITH_RUNTIME
+class Test {
+ var list = listOf(1)
+ fun test() {
+ list += 2
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList.kt
new file mode 100644
index 00000000000..c8b94b6b880
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList.kt
@@ -0,0 +1,9 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ var list = foo()
+ list -= 2
+}
+
+fun foo() = listOf(1)
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList.kt.after
new file mode 100644
index 00000000000..8c626e7d65f
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList.kt.after
@@ -0,0 +1,9 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ val list = foo().toMutableList()
+ list -= 2
+}
+
+fun foo() = listOf(1)
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList2.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList2.kt
new file mode 100644
index 00000000000..3bca0cfc240
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList2.kt
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(a: Any) {
+ var list = a as List
+ list -= 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList2.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList2.kt.after
new file mode 100644
index 00000000000..d8c70709827
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList2.kt.after
@@ -0,0 +1,7 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(a: Any) {
+ val list = (a as List).toMutableList()
+ list -= 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableMap.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableMap.kt
new file mode 100644
index 00000000000..7a49959e3ce
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableMap.kt
@@ -0,0 +1,9 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun toMutableMap() {
+ var map = foo()
+ map -= 3
+}
+
+fun foo() = mapOf(1 to 2)
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableMap.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableMap.kt.after
new file mode 100644
index 00000000000..b6f675e9323
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableMap.kt.after
@@ -0,0 +1,9 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun toMutableMap() {
+ val map = foo().toMutableMap()
+ map -= 3
+}
+
+fun foo() = mapOf(1 to 2)
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableSet.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableSet.kt
new file mode 100644
index 00000000000..9ba43cd2333
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableSet.kt
@@ -0,0 +1,9 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ var set = foo()
+ set -= 1
+}
+
+fun foo() = setOf(1)
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableSet.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableSet.kt.after
new file mode 100644
index 00000000000..5b9a4a67dbe
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableSet.kt.after
@@ -0,0 +1,9 @@
+// "Change type to mutable" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ val set = foo().toMutableSet()
+ set -= 1
+}
+
+fun foo() = setOf(1)
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/noInitializer.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/noInitializer.kt
new file mode 100644
index 00000000000..7770cdeed4a
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/noInitializer.kt
@@ -0,0 +1,12 @@
+// "Join with initializer" "false"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// ACTION: Replace overloaded operator with function call
+// ACTION: Replace with ordinary assignment
+// WITH_RUNTIME
+fun test(otherList: List) {
+ var list: List
+ list = createList()
+ list += otherList
+}
+
+fun createList(): List = listOf(1, 2, 3)
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/notLocal.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/notLocal.kt
new file mode 100644
index 00000000000..8d2c92b58e1
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/notLocal.kt
@@ -0,0 +1,15 @@
+// "Join with initializer" "false"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// ACTION: Replace overloaded operator with function call
+// ACTION: Replace with ordinary assignment
+// WITH_RUNTIME
+class Test {
+ var list = createList()
+
+ fun test(otherList: List) {
+ // comment
+ list += otherList
+ }
+
+ fun createList(): List = listOf(1, 2, 3)
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/simple.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/simple.kt
new file mode 100644
index 00000000000..01f1f5693af
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/simple.kt
@@ -0,0 +1,10 @@
+// "Join with initializer" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: List) {
+ var list = createList()
+ // comment
+ list += otherList
+}
+
+fun createList(): List = listOf(1, 2, 3)
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/simple.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/simple.kt.after
new file mode 100644
index 00000000000..553e3d93eee
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/simple.kt.after
@@ -0,0 +1,9 @@
+// "Join with initializer" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: List) {
+ var list = createList() + otherList
+ // comment
+}
+
+fun createList(): List = listOf(1, 2, 3)
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/used.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/used.kt
new file mode 100644
index 00000000000..25a1d50b883
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/used.kt
@@ -0,0 +1,15 @@
+// "Join with initializer" "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) {
+ var list = createList()
+ foo(list)
+ list += otherList
+}
+
+fun createList(): List = listOf(1, 2, 3)
+
+fun foo(list: List) {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/differentType.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/differentType.kt
new file mode 100644
index 00000000000..74835ceb3ef
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/differentType.kt
@@ -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) {
+ var list = emptyList()
+ foo()
+ bar()
+ list += other
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyList.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyList.kt
new file mode 100644
index 00000000000..cd6ebc2e1ba
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyList.kt
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: List) {
+ var list = emptyList()
+ foo()
+ bar()
+ list += otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyList.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyList.kt.after
new file mode 100644
index 00000000000..d526253267a
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyList.kt.after
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: List) {
+ var list = emptyList()
+ foo()
+ bar()
+ list = otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyListOf.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyListOf.kt
new file mode 100644
index 00000000000..9457af4c8b1
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyListOf.kt
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: List) {
+ var list = listOf()
+ foo()
+ bar()
+ list += otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyListOf.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyListOf.kt.after
new file mode 100644
index 00000000000..f7c9c84b10d
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyListOf.kt.after
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: List) {
+ var list = listOf()
+ foo()
+ bar()
+ list = otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMap.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMap.kt
new file mode 100644
index 00000000000..7cb0cfb4882
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMap.kt
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherMap: Map) {
+ var list = emptyMap()
+ foo()
+ bar()
+ list += otherMap
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMap.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMap.kt.after
new file mode 100644
index 00000000000..e1c693f6d19
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMap.kt.after
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherMap: Map) {
+ var list = emptyMap()
+ foo()
+ bar()
+ list = otherMap
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMapOf.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMapOf.kt
new file mode 100644
index 00000000000..91392f9d0c5
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMapOf.kt
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherMap: Map) {
+ var list = mapOf()
+ foo()
+ bar()
+ list += otherMap
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMapOf.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMapOf.kt.after
new file mode 100644
index 00000000000..48ebed29761
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMapOf.kt.after
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherMap: Map) {
+ var list = mapOf()
+ foo()
+ bar()
+ list = otherMap
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySet.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySet.kt
new file mode 100644
index 00000000000..13768310144
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySet.kt
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: Set) {
+ var list = emptySet()
+ foo()
+ bar()
+ list += otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySet.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySet.kt.after
new file mode 100644
index 00000000000..8f55796d01a
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySet.kt.after
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: Set) {
+ var list = emptySet()
+ foo()
+ bar()
+ list = otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySetOf.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySetOf.kt
new file mode 100644
index 00000000000..4893b5d36e5
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySetOf.kt
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: Set) {
+ var list = setOf()
+ foo()
+ bar()
+ list += otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySetOf.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySetOf.kt.after
new file mode 100644
index 00000000000..b91d4b8d3d3
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySetOf.kt.after
@@ -0,0 +1,12 @@
+// "Replace with assignment" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test(otherList: Set) {
+ var list = setOf()
+ foo()
+ bar()
+ list = otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/listOf.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/listOf.kt
new file mode 100644
index 00000000000..474b403794d
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/listOf.kt
@@ -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) {
+ var list = listOf(1, 2, 3)
+ foo()
+ bar()
+ list += otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/mapOf.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/mapOf.kt
new file mode 100644
index 00000000000..2eb68706a66
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/mapOf.kt
@@ -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) {
+ var list = mapOf(1 to 1, 2 to 2)
+ foo()
+ bar()
+ list += otherMap
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/minusEq.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/minusEq.kt
new file mode 100644
index 00000000000..d8746ea6556
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/minusEq.kt
@@ -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) {
+ var list = emptyList()
+ foo()
+ bar()
+ list -= otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/noInitializer.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/noInitializer.kt
new file mode 100644
index 00000000000..475cb273378
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/noInitializer.kt
@@ -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) {
+ var list: List
+ list = emptyList()
+ list += otherList
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/notEmpty.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/notEmpty.kt
new file mode 100644
index 00000000000..168bfe48370
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/notEmpty.kt
@@ -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) {
+ var list = listOf(1, 2, 3)
+ foo()
+ bar()
+ list += otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/notLocal.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/notLocal.kt
new file mode 100644
index 00000000000..31a7a311926
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/notLocal.kt
@@ -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()
+ fun test(otherList: List) {
+ list += otherList
+ }
+}
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/setOf.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/setOf.kt
new file mode 100644
index 00000000000..b8975468f68
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/setOf.kt
@@ -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) {
+ var list = setOf(1, 2, 3)
+ foo()
+ bar()
+ list += otherList
+}
+
+fun foo() {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/used.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/used.kt
new file mode 100644
index 00000000000..eb0619daa4c
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/used.kt
@@ -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) {
+ var list = listOf()
+ foo(list)
+ bar()
+ list += otherList
+}
+
+fun foo(list: List) {}
+fun bar() {}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/map.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/map.kt
new file mode 100644
index 00000000000..7c2f09f134a
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/map.kt
@@ -0,0 +1,11 @@
+// "Replace with filter" "false"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// ACTION: Change type to mutable
+// ACTION: Join with initializer
+// ACTION: Replace overloaded operator with function call
+// ACTION: Replace with ordinary assignment
+// WITH_RUNTIME
+fun test() {
+ var map = mapOf(1 to 10)
+ map -= listOf(1)
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/minusEq.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/minusEq.kt
new file mode 100644
index 00000000000..92f368c31eb
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/minusEq.kt
@@ -0,0 +1,7 @@
+// "Replace with filter" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ var list = listOf(1, 2, 3)
+ list -= listOf(2)
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/minusEq.kt.after b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/minusEq.kt.after
new file mode 100644
index 00000000000..a003c1b487b
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/minusEq.kt.after
@@ -0,0 +1,7 @@
+// "Replace with filter" "true"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// WITH_RUNTIME
+fun test() {
+ var list = listOf(1, 2, 3)
+ list = list.filter { it !in listOf(2) }
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/notIterable.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/notIterable.kt
new file mode 100644
index 00000000000..9f6f307e0fb
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/notIterable.kt
@@ -0,0 +1,11 @@
+// "Replace with filter" "false"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// ACTION: Change type to mutable
+// ACTION: Join with initializer
+// ACTION: Replace overloaded operator with function call
+// ACTION: Replace with ordinary assignment
+// WITH_RUNTIME
+fun test() {
+ var list = listOf(1, 2, 3)
+ list -= 2
+}
\ No newline at end of file
diff --git a/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/plusEq.kt b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/plusEq.kt
new file mode 100644
index 00000000000..a26247845e0
--- /dev/null
+++ b/idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/plusEq.kt
@@ -0,0 +1,11 @@
+// "Replace with filter" "false"
+// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
+// ACTION: Change type to mutable
+// ACTION: Join with initializer
+// ACTION: Replace overloaded operator with function call
+// ACTION: Replace with ordinary assignment
+// WITH_RUNTIME
+fun test() {
+ var list = listOf(1, 2, 3)
+ list += listOf (4)
+}
\ No newline at end of file
diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java
index 00f94bff841..daaf4d77314 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java
@@ -6708,6 +6708,64 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
+ @TestMetadata("idea/testData/inspectionsLocal/suspiciousCollectionReassignment")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class SuspiciousCollectionReassignment extends AbstractLocalInspectionTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInSuspiciousCollectionReassignment() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/suspiciousCollectionReassignment"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("hasError.kt")
+ public void testHasError() throws Exception {
+ runTest("idea/testData/inspectionsLocal/suspiciousCollectionReassignment/hasError.kt");
+ }
+
+ @TestMetadata("int.kt")
+ public void testInt() throws Exception {
+ runTest("idea/testData/inspectionsLocal/suspiciousCollectionReassignment/int.kt");
+ }
+
+ @TestMetadata("minus.kt")
+ public void testMinus() throws Exception {
+ runTest("idea/testData/inspectionsLocal/suspiciousCollectionReassignment/minus.kt");
+ }
+
+ @TestMetadata("mutableList.kt")
+ public void testMutableList() throws Exception {
+ runTest("idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableList.kt");
+ }
+
+ @TestMetadata("mutableMap.kt")
+ public void testMutableMap() throws Exception {
+ runTest("idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableMap.kt");
+ }
+
+ @TestMetadata("mutableSet.kt")
+ public void testMutableSet() throws Exception {
+ runTest("idea/testData/inspectionsLocal/suspiciousCollectionReassignment/mutableSet.kt");
+ }
+
+ @TestMetadata("plus.kt")
+ public void testPlus() throws Exception {
+ runTest("idea/testData/inspectionsLocal/suspiciousCollectionReassignment/plus.kt");
+ }
+
+ @TestMetadata("simple.kt")
+ public void testSimple() throws Exception {
+ runTest("idea/testData/inspectionsLocal/suspiciousCollectionReassignment/simple.kt");
+ }
+
+ @TestMetadata("val.kt")
+ public void testVal() throws Exception {
+ runTest("idea/testData/inspectionsLocal/suspiciousCollectionReassignment/val.kt");
+ }
+ }
+
@TestMetadata("idea/testData/inspectionsLocal/suspiciousVarProperty")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java
index a82ad65fead..10ecc4ad322 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java
@@ -3959,6 +3959,71 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
}
}
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class SuspiciousCollectionReassignment extends AbstractQuickFixMultiFileTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInSuspiciousCollectionReassignment() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class ChangeTypeToMutable extends AbstractQuickFixMultiFileTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInChangeTypeToMutable() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
+ }
+ }
+
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class JoinWithInitializer extends AbstractQuickFixMultiFileTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInJoinWithInitializer() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
+ }
+ }
+
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class ReplaceWithAssignment extends AbstractQuickFixMultiFileTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInReplaceWithAssignment() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
+ }
+ }
+
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class ReplaceWithFilter extends AbstractQuickFixMultiFileTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInReplaceWithFilter() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
+ }
+ }
+ }
+
@TestMetadata("idea/testData/quickfix/toString")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java
index f91ee3d70a1..2f060211ce8 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java
@@ -11349,6 +11349,241 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
}
}
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class SuspiciousCollectionReassignment extends AbstractQuickFixTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInSuspiciousCollectionReassignment() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class ChangeTypeToMutable extends AbstractQuickFixTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInChangeTypeToMutable() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("hasType.kt")
+ public void testHasType() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType.kt");
+ }
+
+ @TestMetadata("hasType2.kt")
+ public void testHasType2() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/hasType2.kt");
+ }
+
+ @TestMetadata("mutableListOf.kt")
+ public void testMutableListOf() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableListOf.kt");
+ }
+
+ @TestMetadata("mutableMapOf.kt")
+ public void testMutableMapOf() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableMapOf.kt");
+ }
+
+ @TestMetadata("mutableSetOf.kt")
+ public void testMutableSetOf() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/mutableSetOf.kt");
+ }
+
+ @TestMetadata("noInitializer.kt")
+ public void testNoInitializer() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/noInitializer.kt");
+ }
+
+ @TestMetadata("notLocal.kt")
+ public void testNotLocal() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/notLocal.kt");
+ }
+
+ @TestMetadata("toMutableList.kt")
+ public void testToMutableList() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList.kt");
+ }
+
+ @TestMetadata("toMutableList2.kt")
+ public void testToMutableList2() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableList2.kt");
+ }
+
+ @TestMetadata("toMutableMap.kt")
+ public void testToMutableMap() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableMap.kt");
+ }
+
+ @TestMetadata("toMutableSet.kt")
+ public void testToMutableSet() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/changeTypeToMutable/toMutableSet.kt");
+ }
+ }
+
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class JoinWithInitializer extends AbstractQuickFixTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInJoinWithInitializer() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("noInitializer.kt")
+ public void testNoInitializer() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/noInitializer.kt");
+ }
+
+ @TestMetadata("notLocal.kt")
+ public void testNotLocal() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/notLocal.kt");
+ }
+
+ @TestMetadata("simple.kt")
+ public void testSimple() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/simple.kt");
+ }
+
+ @TestMetadata("used.kt")
+ public void testUsed() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/joinWithInitializer/used.kt");
+ }
+ }
+
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class ReplaceWithAssignment extends AbstractQuickFixTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInReplaceWithAssignment() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("differentType.kt")
+ public void testDifferentType() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/differentType.kt");
+ }
+
+ @TestMetadata("emptyList.kt")
+ public void testEmptyList() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyList.kt");
+ }
+
+ @TestMetadata("emptyListOf.kt")
+ public void testEmptyListOf() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyListOf.kt");
+ }
+
+ @TestMetadata("emptyMap.kt")
+ public void testEmptyMap() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMap.kt");
+ }
+
+ @TestMetadata("emptyMapOf.kt")
+ public void testEmptyMapOf() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptyMapOf.kt");
+ }
+
+ @TestMetadata("emptySet.kt")
+ public void testEmptySet() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySet.kt");
+ }
+
+ @TestMetadata("emptySetOf.kt")
+ public void testEmptySetOf() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/emptySetOf.kt");
+ }
+
+ @TestMetadata("listOf.kt")
+ public void testListOf() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/listOf.kt");
+ }
+
+ @TestMetadata("mapOf.kt")
+ public void testMapOf() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/mapOf.kt");
+ }
+
+ @TestMetadata("minusEq.kt")
+ public void testMinusEq() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/minusEq.kt");
+ }
+
+ @TestMetadata("noInitializer.kt")
+ public void testNoInitializer() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/noInitializer.kt");
+ }
+
+ @TestMetadata("notEmpty.kt")
+ public void testNotEmpty() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/notEmpty.kt");
+ }
+
+ @TestMetadata("notLocal.kt")
+ public void testNotLocal() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/notLocal.kt");
+ }
+
+ @TestMetadata("setOf.kt")
+ public void testSetOf() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/setOf.kt");
+ }
+
+ @TestMetadata("used.kt")
+ public void testUsed() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithAssignment/used.kt");
+ }
+ }
+
+ @TestMetadata("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class ReplaceWithFilter extends AbstractQuickFixTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
+ }
+
+ public void testAllFilesPresentInReplaceWithFilter() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("map.kt")
+ public void testMap() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/map.kt");
+ }
+
+ @TestMetadata("minusEq.kt")
+ public void testMinusEq() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/minusEq.kt");
+ }
+
+ @TestMetadata("notIterable.kt")
+ public void testNotIterable() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/notIterable.kt");
+ }
+
+ @TestMetadata("plusEq.kt")
+ public void testPlusEq() throws Exception {
+ runTest("idea/testData/quickfix/suspiciousCollectionReassignment/replaceWithFilter/plusEq.kt");
+ }
+ }
+ }
+
@TestMetadata("idea/testData/quickfix/toString")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)