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
@@ -3155,6 +3155,15 @@
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection"
displayName="Augmented assignment creates a new collection under the hood"
groupPath="Kotlin"
groupName="Probable bugs"
enabledByDefault="true"
level="WARNING"
language="kotlin"
/>
<referenceImporter implementation="org.jetbrains.kotlin.idea.quickfix.KotlinReferenceImporter"/>
<fileType.fileViewProviderFactory filetype="KJSM" implementationClass="com.intellij.psi.ClassFileViewProviderFactory"/>
@@ -0,0 +1,13 @@
<html>
<body>
This inspection reports non-mutable <b>Collection</b> augmented assignment creates a new <b>Collection</b> under the hood.
Example:
<br /><br />
<pre>
<b>var</b> list = listOf(1, 2, 3)
list <b>+=</b> 4 // A new list is created
</pre>
</body>
</html>
@@ -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<KtSingleValueToken> = 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<LocalQuickFix>()
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<KtSimpleNameExpression> { 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
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
@@ -0,0 +1,7 @@
// PROBLEM: none
// WITH_RUNTIME
// ERROR: Type mismatch: inferred type is List<Any> but List<String> was expected
fun test() {
var list = listOf("")
list <caret>+= 1
}
@@ -0,0 +1,5 @@
// PROBLEM: none
fun test() {
var i = 1
i <caret>+= 2
}
@@ -0,0 +1,6 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
var list = listOf(1)
list <caret>- 1
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// ERROR: Assignment operators ambiguity: <br>public operator fun <T> Collection<Int>.plus(element: Int): List<Int> defined in kotlin.collections<br>@InlineOnly public inline operator fun <T> MutableCollection<in Int>.plusAssign(element: Int): Unit defined in kotlin.collections
// WITH_RUNTIME
fun test() {
var list = mutableListOf(1)
list <caret>+= 2
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// ERROR: Assignment operators ambiguity: <br>public operator fun <K, V> Map<out Int, Int>.plus(pair: Pair<Int, Int>): Map<Int, Int> defined in kotlin.collections<br>@InlineOnly public inline operator fun <K, V> MutableMap<in Int, in Int>.plusAssign(pair: Pair<Int, Int>): Unit defined in kotlin.collections
// WITH_RUNTIME
fun test() {
var map = mutableMapOf(1 to 2)
map <caret>+= 3 to 4
}
@@ -0,0 +1,7 @@
// PROBLEM: none
// ERROR: Assignment operators ambiguity: <br>public operator fun <T> Set<Int>.plus(element: Int): Set<Int> defined in kotlin.collections<br>@InlineOnly public inline operator fun <T> MutableCollection<in Int>.plusAssign(element: Int): Unit defined in kotlin.collections
// WITH_RUNTIME
fun test() {
var set = mutableSetOf(1)
set <caret>+= 2
}
@@ -0,0 +1,6 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
var list = listOf(1)
list <caret>+ 2
}
@@ -0,0 +1,6 @@
// FIX: Change type to mutable
// WITH_RUNTIME
fun test() {
var list = listOf(1)
list +=<caret> 2
}
@@ -0,0 +1,6 @@
// FIX: Change type to mutable
// WITH_RUNTIME
fun test() {
val list = mutableListOf(1)<caret>
list += 2
}
@@ -0,0 +1,6 @@
// PROBLEM: none
// WITH_RUNTIME
fun test() {
val list = mutableListOf(1)
list <caret>+= 2
}
@@ -0,0 +1,7 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
var list: List<Int> = listOf(1)
list +=<caret> 2
}
@@ -0,0 +1,7 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
val list: MutableList<Int> = mutableListOf(1)<caret>
list += 2
}
@@ -0,0 +1,7 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
var list = listOf<Int>(1)
list +=<caret> 2
}
@@ -0,0 +1,7 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
val list = mutableListOf<Int>(1)<caret>
list += 2
}
@@ -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 +=<caret> 2
}
@@ -0,0 +1,7 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
val list = mutableListOf(1)<caret>
list += 2
}
@@ -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 +=<caret> 3 to 4
}
@@ -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)<caret>
map += 3 to 4
}
@@ -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 +=<caret> 1
}
@@ -0,0 +1,7 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
val set = mutableSetOf(1)<caret>
set += 1
}
@@ -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<Int>
list = listOf(1)
list +=<caret> 2
}
@@ -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 +=<caret> 2
}
}
@@ -0,0 +1,9 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
var list = foo()
list -=<caret> 2
}
fun foo() = listOf(1)
@@ -0,0 +1,9 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
val list = foo().toMutableList()<caret>
list -= 2
}
fun foo() = listOf(1)
@@ -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<Int>
list -=<caret> 2
}
@@ -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<Int>).toMutableList()<caret>
list -= 2
}
@@ -0,0 +1,9 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun toMutableMap() {
var map = foo()
map -=<caret> 3
}
fun foo() = mapOf(1 to 2)
@@ -0,0 +1,9 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun toMutableMap() {
val map = foo().toMutableMap()<caret>
map -= 3
}
fun foo() = mapOf(1 to 2)
@@ -0,0 +1,9 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
var set = foo()
set -=<caret> 1
}
fun foo() = setOf(1)
@@ -0,0 +1,9 @@
// "Change type to mutable" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test() {
val set = foo().toMutableSet()<caret>
set -= 1
}
fun foo() = setOf(1)
@@ -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<Int>) {
var list: List<Int>
list = createList()
list <caret>+= otherList
}
fun createList(): List<Int> = listOf(1, 2, 3)
@@ -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<Int>) {
// comment
list <caret>+= otherList
}
fun createList(): List<Int> = listOf(1, 2, 3)
}
@@ -0,0 +1,10 @@
// "Join with initializer" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = createList()
// comment
list <caret>+= otherList
}
fun createList(): List<Int> = listOf(1, 2, 3)
@@ -0,0 +1,9 @@
// "Join with initializer" "true"
// TOOL: org.jetbrains.kotlin.idea.inspections.SuspiciousCollectionReassignmentInspection
// WITH_RUNTIME
fun test(otherList: List<Int>) {
var list = createList() + otherList<caret>
// comment
}
fun createList(): List<Int> = listOf(1, 2, 3)
@@ -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<Int>) {
var list = createList()
foo(list)
list <caret>+= otherList
}
fun createList(): List<Int> = listOf(1, 2, 3)
fun foo(list: List<Int>) {}
@@ -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() {}
@@ -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 <caret>-= listOf(1)
}
@@ -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 -=<caret> listOf(2)
}
@@ -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) }
}
@@ -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 -=<caret> 2
}
@@ -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 +=<caret> listOf (4)
}
@@ -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)
@@ -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)
@@ -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)