diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 9c134916323..faf3afb0acf 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -3313,6 +3313,15 @@ language="kotlin" /> + + diff --git a/idea/resources/inspectionDescriptions/ReplaceAssociateFunction.html b/idea/resources/inspectionDescriptions/ReplaceAssociateFunction.html new file mode 100644 index 00000000000..e8cb4b2cb4a --- /dev/null +++ b/idea/resources/inspectionDescriptions/ReplaceAssociateFunction.html @@ -0,0 +1,5 @@ + + +This inspection reports associate calls that can be replaced with associateBy or associateWith. + + \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceAssociateFunctionInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceAssociateFunctionInspection.kt new file mode 100644 index 00000000000..d0479d08b67 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceAssociateFunctionInspection.kt @@ -0,0 +1,194 @@ +/* + * Copyright 2010-2019 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.GENERIC_ERROR_OR_WARNING +import com.intellij.codeInspection.ProblemHighlightType.INFORMATION +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.config.LanguageVersion +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor +import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.core.getLastLambdaExpression +import org.jetbrains.kotlin.idea.inspections.AssociateFunction.* +import org.jetbrains.kotlin.idea.intentions.callExpression +import org.jetbrains.kotlin.idea.project.languageVersionSettings +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe +import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode + +class ReplaceAssociateFunctionInspection : AbstractKotlinInspection() { + companion object { + private val associateFunctionNames = listOf("associate", "associateTo") + private val associateFqNames = listOf(FqName("kotlin.collections.associate"), FqName("kotlin.sequences.associate")) + private val associateToFqNames = listOf(FqName("kotlin.collections.associateTo"), FqName("kotlin.sequences.associateTo")) + } + + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = dotQualifiedExpressionVisitor(fun(dotQualifiedExpression) { + if (dotQualifiedExpression.languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_3) return + val callExpression = dotQualifiedExpression.callExpression ?: return + val calleeExpression = callExpression.calleeExpression ?: return + if (calleeExpression.text !in associateFunctionNames) return + + val context = dotQualifiedExpression.analyze(BodyResolveMode.PARTIAL) + val fqName = callExpression.getResolvedCall(context)?.resultingDescriptor?.fqNameSafe ?: return + val isAssociate = fqName in associateFqNames + val isAssociateTo = fqName in associateToFqNames + if (!isAssociate && !isAssociateTo) return + + val lambda = callExpression.lambda() ?: return + if (lambda.valueParameters.size > 1) return + val functionLiteral = lambda.functionLiteral + if (functionLiteral.anyDescendantOfType { it.labelQualifier != null }) return + val lastStatement = functionLiteral.lastStatement() ?: return + val (keySelector, valueTransform) = lastStatement.pair(context) ?: return + val lambdaParameter = context[BindingContext.FUNCTION, functionLiteral]?.valueParameters?.singleOrNull() ?: return + + val (associateFunction, highlightType) = when { + keySelector.isReferenceTo(lambdaParameter, context) -> { + val receiver = dotQualifiedExpression.receiverExpression.getResolvedCall(context)?.resultingDescriptor?.returnType ?: return + if (KotlinBuiltIns.isArray(receiver) || KotlinBuiltIns.isPrimitiveArray(receiver)) return + ASSOCIATE_WITH to GENERIC_ERROR_OR_WARNING + } + valueTransform.isReferenceTo(lambdaParameter, context) -> + ASSOCIATE_BY to GENERIC_ERROR_OR_WARNING + else -> { + if (functionLiteral.bodyExpression?.statements?.size != 1) return + ASSOCIATE_BY_KEY_AND_VALUE to INFORMATION + } + } + holder.registerProblemWithoutOfflineInformation( + calleeExpression, + "Replace '${calleeExpression.text}' with '${associateFunction.name(isAssociateTo)}'", + isOnTheFly, + highlightType, + ReplaceAssociateFunctionFix(associateFunction, isAssociateTo) + ) + }) + + private fun KtExpression.isReferenceTo(descriptor: ValueParameterDescriptor, context: BindingContext): Boolean { + return (this as? KtNameReferenceExpression)?.getResolvedCall(context)?.resultingDescriptor == descriptor + } +} + +private class ReplaceAssociateFunctionFix(private val function: AssociateFunction, private val hasDestination: Boolean) : LocalQuickFix { + private val functionName = function.name(hasDestination) + + override fun getName() = "Replace with '$functionName'" + + override fun getFamilyName() = name + + override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + val dotQualifiedExpression = descriptor.psiElement.getStrictParentOfType() ?: return + val receiverExpression = dotQualifiedExpression.receiverExpression + val callExpression = dotQualifiedExpression.callExpression ?: return + val lambda = callExpression.lambda() ?: return + val lastStatement = lambda.functionLiteral.lastStatement() ?: return + val (keySelector, valueTransform) = lastStatement.pair() ?: return + + val psiFactory = KtPsiFactory(dotQualifiedExpression) + if (function == ASSOCIATE_BY_KEY_AND_VALUE) { + val destination = if (hasDestination) { + callExpression.valueArguments.firstOrNull()?.getArgumentExpression() ?: return + } else { + null + } + val newExpression = psiFactory.buildExpression { + appendExpression(receiverExpression) + appendFixedText(".") + appendFixedText(functionName) + appendFixedText("(") + if (destination != null) { + appendExpression(destination) + appendFixedText(",") + } + appendLambda(lambda, keySelector) + appendFixedText(",") + appendLambda(lambda, valueTransform) + appendFixedText(")") + } + dotQualifiedExpression.replace(newExpression) + } else { + lastStatement.replace(if (function == ASSOCIATE_WITH) valueTransform else keySelector) + val newExpression = psiFactory.buildExpression { + appendExpression(receiverExpression) + appendFixedText(".") + appendFixedText(functionName) + val valueArgumentList = callExpression.valueArgumentList + if (valueArgumentList != null) { + appendValueArgumentList(valueArgumentList) + } + if (callExpression.lambdaArguments.isNotEmpty()) { + appendLambda(lambda) + } + } + dotQualifiedExpression.replace(newExpression) + } + } + + private fun BuilderByPattern.appendLambda(lambda: KtLambdaExpression, body: KtExpression? = lambda.bodyExpression) { + appendFixedText("{") + lambda.valueParameters.firstOrNull()?.nameAsName?.also { + appendName(it) + appendFixedText("->") + } + appendExpression(body) + appendFixedText("}") + } + + private fun BuilderByPattern.appendValueArgumentList(valueArgumentList: KtValueArgumentList) { + appendFixedText("(") + valueArgumentList.arguments.forEachIndexed { index, argument -> + if (index > 0) appendFixedText(",") + appendExpression(argument.getArgumentExpression()) + } + appendFixedText(")") + } +} + +private enum class AssociateFunction(private val functionName: String) { + ASSOCIATE_WITH("associateWith"), ASSOCIATE_BY("associateBy"), ASSOCIATE_BY_KEY_AND_VALUE("associateBy"); + + fun name(hasDestination: Boolean): String { + return if (hasDestination) "${functionName}To" else functionName + } +} + +private fun KtCallExpression.lambda(): KtLambdaExpression? { + return lambdaArguments.singleOrNull()?.getArgumentExpression() as? KtLambdaExpression ?: getLastLambdaExpression() +} + +private fun KtFunctionLiteral.lastStatement(): KtExpression? { + return bodyExpression?.statements?.lastOrNull() +} + +private fun KtExpression.pair(context: BindingContext = analyze(BodyResolveMode.PARTIAL)): Pair? { + return when (this) { + is KtBinaryExpression -> { + if (operationReference.text != "to") return null + val left = left ?: return null + val right = right ?: return null + left to right + } + is KtCallExpression -> { + if (calleeExpression?.text != "Pair") return null + if (valueArguments.size != 2) return null + if (getResolvedCall(context)?.resultingDescriptor?.containingDeclaration?.fqNameSafe != FqName("kotlin.Pair")) return null + val first = valueArguments[0]?.getArgumentExpression() ?: return null + val second = valueArguments[1]?.getArgumentExpression() ?: return null + first to second + } + else -> return null + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/.inspection b/idea/testData/inspectionsLocal/replaceAssociateFunction/.inspection new file mode 100644 index 00000000000..ab9225fc8a7 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.ReplaceAssociateFunctionInspection \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/array.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/array.kt new file mode 100644 index 00000000000..c67c67ff238 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/array.kt @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L + +fun test() { + arrayOf(1).associate { getKey(it) to it } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/array.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/array.kt.after new file mode 100644 index 00000000000..41533c79a78 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/array.kt.after @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L + +fun test() { + arrayOf(1).associateBy { getKey(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/basic.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/basic.kt new file mode 100644 index 00000000000..9224b945bfe --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/basic.kt @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L + +fun test() { + listOf(1).associate { getKey(it) to it } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/basic.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/basic.kt.after new file mode 100644 index 00000000000..06577003382 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/basic.kt.after @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L + +fun test() { + listOf(1).associateBy { getKey(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/array.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/array.kt new file mode 100644 index 00000000000..fec3ac94f9c --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/array.kt @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + arrayOf(1).associate { getKey(it) to getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/array.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/array.kt.after new file mode 100644 index 00000000000..4b12eaeca36 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/array.kt.after @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + arrayOf(1).associateBy({ getKey(it) }, { getValue(it) }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic.kt new file mode 100644 index 00000000000..0b13336e36c --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic.kt @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { getKey(it) to getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic.kt.after new file mode 100644 index 00000000000..b7836c846cb --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic.kt.after @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateBy({ getKey(it) }, { getValue(it) }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic2.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic2.kt new file mode 100644 index 00000000000..2a8c874e942 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic2.kt @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { i -> getKey(i) to getValue(i) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic2.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic2.kt.after new file mode 100644 index 00000000000..4b1c2f40d0b --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic2.kt.after @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateBy({ i -> getKey(i) }, { i -> getValue(i) }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic3.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic3.kt new file mode 100644 index 00000000000..ce0ef7b00b7 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic3.kt @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { Pair(getKey(it), getValue(it)) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic3.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic3.kt.after new file mode 100644 index 00000000000..b7836c846cb --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic3.kt.after @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateBy({ getKey(it) }, { getValue(it) }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic4.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic4.kt new file mode 100644 index 00000000000..609c18461f2 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic4.kt @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate({ getKey(it) to getValue(it) }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic4.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic4.kt.after new file mode 100644 index 00000000000..b7836c846cb --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic4.kt.after @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateBy({ getKey(it) }, { getValue(it) }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic5.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic5.kt new file mode 100644 index 00000000000..8a42feb0ebc --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic5.kt @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { "$it" to "$it" } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic5.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic5.kt.after new file mode 100644 index 00000000000..51e2fa82f97 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic5.kt.after @@ -0,0 +1,10 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associate' with 'associateBy' +// FIX: Replace with 'associateBy' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateBy({ "$it" }, { "$it" }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/notSingle.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/notSingle.kt new file mode 100644 index 00000000000..b4ce8b24622 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/notSingle.kt @@ -0,0 +1,12 @@ +// PROBLEM: none +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { + val key = getKey(it) + val value = getValue(it) + key to value + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/array.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/array.kt new file mode 100644 index 00000000000..4c8e17b315e --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/array.kt @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L + +fun test() { + val destination = mutableMapOf() + arrayOf(1).associateTo(destination) { getKey(it) to it } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/array.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/array.kt.after new file mode 100644 index 00000000000..72698f580dc --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/array.kt.after @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L + +fun test() { + val destination = mutableMapOf() + arrayOf(1).associateByTo(destination) { getKey(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/basic.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/basic.kt new file mode 100644 index 00000000000..f31c6c45f41 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/basic.kt @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L + +fun test() { + val destination = mutableMapOf() + listOf(1).associateTo(destination) { getKey(it) to it } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/basic.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/basic.kt.after new file mode 100644 index 00000000000..90de09705e5 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/basic.kt.after @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L + +fun test() { + val destination = mutableMapOf() + listOf(1).associateByTo(destination) { getKey(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/array.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/array.kt new file mode 100644 index 00000000000..e3705a31272 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/array.kt @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + arrayOf(1).associateTo(destination) { getKey(it) to getValue(it) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/array.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/array.kt.after new file mode 100644 index 00000000000..ec5802cd178 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/array.kt.after @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + arrayOf(1).associateByTo(destination, { getKey(it) }, { getValue(it) }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic.kt new file mode 100644 index 00000000000..8bb10283417 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic.kt @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + listOf(1).associateTo(destination) { getKey(it) to getValue(it) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic.kt.after new file mode 100644 index 00000000000..31e2ac816c3 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic.kt.after @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + listOf(1).associateByTo(destination, { getKey(it) }, { getValue(it) }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic2.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic2.kt new file mode 100644 index 00000000000..cca6ab618d2 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic2.kt @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + listOf(1).associateTo(destination) { i -> getKey(i) to getValue(i) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic2.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic2.kt.after new file mode 100644 index 00000000000..ca7353967fd --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic2.kt.after @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + listOf(1).associateByTo(destination, { i -> getKey(i) }, { i -> getValue(i) }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic3.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic3.kt new file mode 100644 index 00000000000..3836f9fae18 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic3.kt @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + listOf(1).associateTo(destination) { Pair(getKey(it), getValue(it)) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic3.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic3.kt.after new file mode 100644 index 00000000000..31e2ac816c3 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic3.kt.after @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + listOf(1).associateByTo(destination, { getKey(it) }, { getValue(it) }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic4.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic4.kt new file mode 100644 index 00000000000..911fbe3c116 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic4.kt @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + listOf(1).associateTo(destination, { getKey(it) to getValue(it) }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic4.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic4.kt.after new file mode 100644 index 00000000000..31e2ac816c3 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic4.kt.after @@ -0,0 +1,11 @@ +// HIGHLIGHT: INFORMATION +// PROBLEM: Replace 'associateTo' with 'associateByTo' +// FIX: Replace with 'associateByTo' +// WITH_RUNTIME +fun getKey(i: Int): Long = 1L +fun getValue(i: Int): String = "" + +fun test() { + val destination = mutableMapOf() + listOf(1).associateByTo(destination, { getKey(it) }, { getValue(it) }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/array.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/array.kt new file mode 100644 index 00000000000..15ad76ce38f --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/array.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + arrayOf(1).associate { it to getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic.kt new file mode 100644 index 00000000000..dafd0bc0524 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic.kt @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { it to getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic.kt.after new file mode 100644 index 00000000000..e2da412e7e4 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic.kt.after @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateWith { getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic2.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic2.kt new file mode 100644 index 00000000000..b040f299cd5 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic2.kt @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { i -> i to getValue(i) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic2.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic2.kt.after new file mode 100644 index 00000000000..533175ae427 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic2.kt.after @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateWith { i -> getValue(i) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic3.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic3.kt new file mode 100644 index 00000000000..30d14bec9b2 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic3.kt @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { Pair(it, getValue(it)) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic3.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic3.kt.after new file mode 100644 index 00000000000..e2da412e7e4 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic3.kt.after @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateWith { getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic4.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic4.kt new file mode 100644 index 00000000000..0fae60bbf4f --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic4.kt @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate({ it to getValue(it) }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic4.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic4.kt.after new file mode 100644 index 00000000000..df52eb9a0b9 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic4.kt.after @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateWith({ getValue(it) }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic5.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic5.kt new file mode 100644 index 00000000000..27de6e5f4df --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic5.kt @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { it to "$it" } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic5.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic5.kt.after new file mode 100644 index 00000000000..d2f39d51903 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic5.kt.after @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateWith { "$it" } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/intArray.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/intArray.kt new file mode 100644 index 00000000000..7338daebde0 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/intArray.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + intArrayOf(1).associate { it to getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/labeledReturn.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/labeledReturn.kt new file mode 100644 index 00000000000..dd6678f7d07 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/labeledReturn.kt @@ -0,0 +1,12 @@ +// PROBLEM: none +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test(b: Boolean) { + listOf(1).associate { + if (b) { + return@associate it to "" + } + it to getValue(it) + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/multiLine.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/multiLine.kt new file mode 100644 index 00000000000..992dfab5c44 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/multiLine.kt @@ -0,0 +1,11 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { + val value = getValue(it) + it to value + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/multiLine.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/multiLine.kt.after new file mode 100644 index 00000000000..682ff174aac --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/multiLine.kt.after @@ -0,0 +1,11 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associateWith { + val value = getValue(it) + value + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/notPair.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/notPair.kt new file mode 100644 index 00000000000..a553a0e8606 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/notPair.kt @@ -0,0 +1,13 @@ +// PROBLEM: none +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test(b: Boolean) { + listOf(1).associate { + if (b) { + it to getValue(it) + } else { + it to "" + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/sequence.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/sequence.kt new file mode 100644 index 00000000000..e19fbfdaafb --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/sequence.kt @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + sequenceOf(1).associate { it to getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/sequence.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/sequence.kt.after new file mode 100644 index 00000000000..05126cbb81e --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/sequence.kt.after @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + sequenceOf(1).associateWith { getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/set.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/set.kt new file mode 100644 index 00000000000..ec06e2f0868 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/set.kt @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + setOf(1).associate { it to getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/set.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/set.kt.after new file mode 100644 index 00000000000..6385330eb1a --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/set.kt.after @@ -0,0 +1,8 @@ +// PROBLEM: Replace 'associate' with 'associateWith' +// FIX: Replace with 'associateWith' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + setOf(1).associateWith { getValue(it) } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/array.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/array.kt new file mode 100644 index 00000000000..394d216f283 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/array.kt @@ -0,0 +1,8 @@ +// PROBLEM: none +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + arrayOf(1).associateTo(destination) { it to getValue(it) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic.kt new file mode 100644 index 00000000000..f18bb093801 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic.kt @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateTo(destination) { it to getValue(it) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic.kt.after new file mode 100644 index 00000000000..461a3ca66f1 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic.kt.after @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateWithTo(destination) { getValue(it) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic2.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic2.kt new file mode 100644 index 00000000000..32b3da17407 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic2.kt @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateTo(destination) { i -> i to getValue(i) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic2.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic2.kt.after new file mode 100644 index 00000000000..fe7f9fd585c --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic2.kt.after @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateWithTo(destination) { i -> getValue(i) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic3.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic3.kt new file mode 100644 index 00000000000..59b9fe6c2d7 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic3.kt @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateTo(destination) { Pair(it, getValue(it)) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic3.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic3.kt.after new file mode 100644 index 00000000000..461a3ca66f1 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic3.kt.after @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateWithTo(destination) { getValue(it) } +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic4.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic4.kt new file mode 100644 index 00000000000..7bbc63ff5a4 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic4.kt @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateTo(destination, { it to getValue(it) }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic4.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic4.kt.after new file mode 100644 index 00000000000..0185cceda15 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic4.kt.after @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateWithTo(destination, { getValue(it) }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic5.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic5.kt new file mode 100644 index 00000000000..4abf4db9185 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic5.kt @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateTo(destination, { it to "$it" }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic5.kt.after b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic5.kt.after new file mode 100644 index 00000000000..050d35719da --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic5.kt.after @@ -0,0 +1,9 @@ +// PROBLEM: Replace 'associateTo' with 'associateWithTo' +// FIX: Replace with 'associateWithTo' +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun associateWithTo() { + val destination = mutableMapOf() + listOf(1).associateWithTo(destination, { "$it" }) +} diff --git a/idea/testData/inspectionsLocal/replaceAssociateFunction/version1_2.kt b/idea/testData/inspectionsLocal/replaceAssociateFunction/version1_2.kt new file mode 100644 index 00000000000..6ad9e2fe8ab --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceAssociateFunction/version1_2.kt @@ -0,0 +1,8 @@ +// LANGUAGE_VERSION: 1.2 +// PROBLEM: none +// WITH_RUNTIME +fun getValue(i: Int): String = "" + +fun test() { + listOf(1).associate { it to getValue(it) } +} \ 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 b93783810b7..5fc3c135d75 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -6602,6 +6602,272 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { } } + @TestMetadata("idea/testData/inspectionsLocal/replaceAssociateFunction") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ReplaceAssociateFunction extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInReplaceAssociateFunction() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceAssociateFunction"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("version1_2.kt") + public void testVersion1_2() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/version1_2.kt"); + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AssociateBy extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssociateBy() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/array.kt"); + } + + @TestMetadata("basic.kt") + public void testBasic() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateBy/basic.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AssociateByKeyAndValue extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssociateByKeyAndValue() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/array.kt"); + } + + @TestMetadata("basic.kt") + public void testBasic() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic.kt"); + } + + @TestMetadata("basic2.kt") + public void testBasic2() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic2.kt"); + } + + @TestMetadata("basic3.kt") + public void testBasic3() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic3.kt"); + } + + @TestMetadata("basic4.kt") + public void testBasic4() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic4.kt"); + } + + @TestMetadata("basic5.kt") + public void testBasic5() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/basic5.kt"); + } + + @TestMetadata("notSingle.kt") + public void testNotSingle() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByKeyAndValue/notSingle.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AssociateByTo extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssociateByTo() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/array.kt"); + } + + @TestMetadata("basic.kt") + public void testBasic() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByTo/basic.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AssociateByToKeyAndValue extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssociateByToKeyAndValue() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/array.kt"); + } + + @TestMetadata("basic.kt") + public void testBasic() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic.kt"); + } + + @TestMetadata("basic2.kt") + public void testBasic2() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic2.kt"); + } + + @TestMetadata("basic3.kt") + public void testBasic3() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic3.kt"); + } + + @TestMetadata("basic4.kt") + public void testBasic4() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateByToKeyAndValue/basic4.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AssociateWith extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssociateWith() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/array.kt"); + } + + @TestMetadata("basic.kt") + public void testBasic() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic.kt"); + } + + @TestMetadata("basic2.kt") + public void testBasic2() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic2.kt"); + } + + @TestMetadata("basic3.kt") + public void testBasic3() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic3.kt"); + } + + @TestMetadata("basic4.kt") + public void testBasic4() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic4.kt"); + } + + @TestMetadata("basic5.kt") + public void testBasic5() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/basic5.kt"); + } + + @TestMetadata("intArray.kt") + public void testIntArray() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/intArray.kt"); + } + + @TestMetadata("labeledReturn.kt") + public void testLabeledReturn() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/labeledReturn.kt"); + } + + @TestMetadata("multiLine.kt") + public void testMultiLine() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/multiLine.kt"); + } + + @TestMetadata("notPair.kt") + public void testNotPair() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/notPair.kt"); + } + + @TestMetadata("sequence.kt") + public void testSequence() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/sequence.kt"); + } + + @TestMetadata("set.kt") + public void testSet() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWith/set.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AssociateWithTo extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssociateWithTo() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/array.kt"); + } + + @TestMetadata("basic.kt") + public void testBasic() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic.kt"); + } + + @TestMetadata("basic2.kt") + public void testBasic2() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic2.kt"); + } + + @TestMetadata("basic3.kt") + public void testBasic3() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic3.kt"); + } + + @TestMetadata("basic4.kt") + public void testBasic4() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic4.kt"); + } + + @TestMetadata("basic5.kt") + public void testBasic5() throws Exception { + runTest("idea/testData/inspectionsLocal/replaceAssociateFunction/associateWithTo/basic5.kt"); + } + } + } + @TestMetadata("idea/testData/inspectionsLocal/replaceNegatedIsEmptyWithIsNotEmpty") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)