From 8bdca1716f816d19857323ff423e18da7ab365e8 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 14 Jan 2026 21:44:12 +0100 Subject: [PATCH] [kotlin] KTIJ-36920 Convert RemoveRedundantCallsOfConversionMethodsInspection into a quickfix As it is reported as compiler diagnostic GitOrigin-RevId: 0898acef4c4b2aab0bf39899427985da534265a6 --- .../fixes/KotlinK2QuickFixRegistrar.kt | 1 + .../fixes/ReplaceCallFixFactories.kt | 7 ++ .../fixes/HighLevelQuickFixTestGenerated.java | 116 +++++++++++++++++- ...ntellij.kotlin.codeInsight.inspections.xml | 10 -- ...ndantCallsOfConversionMethodsInspection.kt | 68 ---------- .../tests/K2LocalInspectionTestGenerated.java | 112 ----------------- .../kotlin/idea/quickfix/ReplaceCallFix.kt | 11 ++ .../.k2Inspection | 1 - .../booleanToInt.kt | 6 + .../byte.kt | 4 + .../byte.kt.after | 4 + .../char.kt | 4 + .../char.kt.after | 4 + .../double.kt | 4 + .../double.kt.after | 4 + .../float.kt | 4 + .../float.kt.after | 4 + .../int.kt | 4 + .../int.kt.after | 4 + .../long.kt | 4 + .../long.kt.after | 4 + .../nullable.kt | 5 + .../nullable2.kt | 7 ++ .../safeString.kt | 9 ++ .../safeString.kt.after | 9 ++ .../safeString2.kt | 9 ++ .../safeString2.kt.after | 9 ++ .../short.kt | 4 + .../short.kt.after | 4 + .../string.kt | 4 + .../string.kt.after | 4 + .../toOtherType.kt | 4 + .../typealias.kt | 8 ++ .../typealias.kt.after | 8 ++ .../uByte.kt | 7 ++ .../uByte.kt.after | 7 ++ .../uInt.kt | 7 ++ .../uInt.kt.after | 7 ++ .../uLong.kt | 7 ++ .../uLong.kt.after | 7 ++ .../uShort.kt | 7 ++ .../uShort.kt.after | 7 ++ .../variable.kt | 5 + .../variable.kt.after | 5 + .../fe10/testGenerator/Fe10GenerateTests.kt | 7 +- .../codeinsight/GenerateK2InspectionTests.kt | 5 +- .../codeinsight/GenerateK2QuickFixTests.kt | 7 +- 47 files changed, 348 insertions(+), 201 deletions(-) delete mode 100644 plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/diagnosticBased/RemoveRedundantCallsOfConversionMethodsInspection.kt delete mode 100644 plugins/kotlin/idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/.k2Inspection create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/booleanToInt.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/byte.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/byte.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/char.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/char.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/double.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/double.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/float.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/float.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/int.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/int.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/long.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/long.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable2.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString2.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString2.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/short.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/short.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/string.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/string.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/toOtherType.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/typealias.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/typealias.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uByte.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uByte.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uInt.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uInt.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uLong.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uLong.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uShort.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uShort.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/variable.kt create mode 100644 plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/variable.kt.after diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt index 975b968481c0..3063c530e6c8 100644 --- a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt @@ -373,6 +373,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() { registerFactory(UselessIsCheckFactories.uselessWhenCheckFactory) registerFactory(UselessIsCheckFactories.impossibleWhenCheckWarningFactory) registerFactory(UselessIsCheckFactories.impossibleWhenCheckErrorFactory) + registerFactory(ReplaceCallFixFactories.redundantCallsOfConversionMethods) registerFactory(ReplaceCallFixFactories.unsafeCallFactory) registerFactory(ReplaceCallFixFactories.unsafeInfixCallFactory) registerFactory(ReplaceCallFixFactories.unsafeOperatorCallFactory) diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/ReplaceCallFixFactories.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/ReplaceCallFixFactories.kt index b1d7c617035d..8893e27dd25f 100644 --- a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/ReplaceCallFixFactories.kt +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/ReplaceCallFixFactories.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.analysis.api.types.KaClassType import org.jetbrains.kotlin.analysis.api.types.KaType import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory +import org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix import org.jetbrains.kotlin.idea.quickfix.ReplaceImplicitReceiverCallFix import org.jetbrains.kotlin.idea.quickfix.ReplaceInfixOrOperatorCallFix import org.jetbrains.kotlin.idea.quickfix.ReplaceWithSafeCallFix @@ -22,6 +23,12 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.utils.addToStdlib.safeAs object ReplaceCallFixFactories { + val redundantCallsOfConversionMethods: KotlinQuickFixFactory.ModCommandBased = + KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.RedundantCallOfConversionMethod -> + val element = diagnostic.psi as? KtQualifiedExpression ?: return@ModCommandBased emptyList() + listOf(RemoveRedundantCallsOfConversionMethodsFix(element)) + } + val unsafeCallFactory: KotlinQuickFixFactory.ModCommandBased = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.UnsafeCall -> val psi = diagnostic.psi diff --git a/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java b/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java index d724ba440923..ff65a8c6d98f 100644 --- a/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java +++ b/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java @@ -1,4 +1,4 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.k2.codeinsight.fixes; @@ -11462,6 +11462,120 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu } } + @RunWith(JUnit3RunnerWithInners.class) + @TestMetadata("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods") + public static class RemoveRedundantCallsOfConversionMethods extends AbstractHighLevelQuickFixTest { + @java.lang.Override + @org.jetbrains.annotations.NotNull + public final KotlinPluginMode getPluginMode() { + return KotlinPluginMode.K2; + } + + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + @TestMetadata("booleanToInt.kt") + public void testBooleanToInt() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/booleanToInt.kt"); + } + + @TestMetadata("byte.kt") + public void testByte() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/byte.kt"); + } + + @TestMetadata("char.kt") + public void testChar() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/char.kt"); + } + + @TestMetadata("double.kt") + public void testDouble() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/double.kt"); + } + + @TestMetadata("float.kt") + public void testFloat() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/float.kt"); + } + + @TestMetadata("int.kt") + public void testInt() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/int.kt"); + } + + @TestMetadata("long.kt") + public void testLong() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/long.kt"); + } + + @TestMetadata("nullable.kt") + public void testNullable() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable.kt"); + } + + @TestMetadata("nullable2.kt") + public void testNullable2() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable2.kt"); + } + + @TestMetadata("safeString.kt") + public void testSafeString() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString.kt"); + } + + @TestMetadata("safeString2.kt") + public void testSafeString2() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString2.kt"); + } + + @TestMetadata("short.kt") + public void testShort() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/short.kt"); + } + + @TestMetadata("string.kt") + public void testString() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/string.kt"); + } + + @TestMetadata("toOtherType.kt") + public void testToOtherType() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/toOtherType.kt"); + } + + @TestMetadata("typealias.kt") + public void testTypealias() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/typealias.kt"); + } + + @TestMetadata("uByte.kt") + public void testUByte() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uByte.kt"); + } + + @TestMetadata("uInt.kt") + public void testUInt() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uInt.kt"); + } + + @TestMetadata("uLong.kt") + public void testULong() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uLong.kt"); + } + + @TestMetadata("uShort.kt") + public void testUShort() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uShort.kt"); + } + + @TestMetadata("variable.kt") + public void testVariable() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/variable.kt"); + } + } + @RunWith(JUnit3RunnerWithInners.class) @TestMetadata("../../../idea/tests/testData/quickfix/removeRedundantReturn") public static class RemoveRedundantReturn extends AbstractHighLevelQuickFixTest { diff --git a/plugins/kotlin/code-insight/inspections-k2/resources/intellij.kotlin.codeInsight.inspections.xml b/plugins/kotlin/code-insight/inspections-k2/resources/intellij.kotlin.codeInsight.inspections.xml index c7414975d1a7..3adb08712c2b 100644 --- a/plugins/kotlin/code-insight/inspections-k2/resources/intellij.kotlin.codeInsight.inspections.xml +++ b/plugins/kotlin/code-insight/inspections-k2/resources/intellij.kotlin.codeInsight.inspections.xml @@ -950,16 +950,6 @@ language="kotlin" key="inspection.unnecessary.variable.display.name" bundle="messages.KotlinBundle"/> - - - () { - - override val diagnosticFilter: KaDiagnosticCheckerFilter = KaDiagnosticCheckerFilter.ONLY_COMMON_CHECKERS - - override val diagnosticType: KClass - get() = KaFirDiagnostic.RedundantCallOfConversionMethod::class - - override fun KaSession.prepareContextByDiagnostic( - element: KtQualifiedExpression, - diagnostic: KaFirDiagnostic.RedundantCallOfConversionMethod - ): Unit = Unit - - override fun getApplicableRanges(element: KtQualifiedExpression): List { - return ApplicabilityRange.single(element) { - it.selectorExpression - } - } - - override fun buildVisitor( - holder: ProblemsHolder, - isOnTheFly: Boolean - ): KtVisitor<*, *> = qualifiedExpressionVisitor { - visitTargetElement(it, holder, isOnTheFly) - } - - override fun getProblemDescription( - element: KtQualifiedExpression, - context: Unit - ): @InspectionMessage String = KotlinBundle.message("redundant.call.of.the.conversion.method") - - override fun createQuickFix( - element: KtQualifiedExpression, - context: Unit - ): KotlinModCommandQuickFix = object : KotlinModCommandQuickFix() { - - override fun getFamilyName(): @IntentionFamilyName String = KotlinBundle.message("remove.redundant.calls.of.the.conversion.method") - - override fun applyFix( - project: Project, - element: KtQualifiedExpression, - updater: ModPsiUpdater - ) { - element.replace(element.receiverExpression) - } - } -} \ No newline at end of file diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/inspections/tests/K2LocalInspectionTestGenerated.java b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/inspections/tests/K2LocalInspectionTestGenerated.java index 301059454b28..026d71880b04 100644 --- a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/inspections/tests/K2LocalInspectionTestGenerated.java +++ b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/inspections/tests/K2LocalInspectionTestGenerated.java @@ -17525,119 +17525,7 @@ public abstract class K2LocalInspectionTestGenerated extends AbstractK2LocalInsp } } - @RunWith(JUnit3RunnerWithInners.class) - @TestMetadata("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods") - public static class RemoveRedundantCallsOfConversionMethods extends AbstractK2LocalInspectionTest { - @java.lang.Override - @org.jetbrains.annotations.NotNull - public final KotlinPluginMode getPluginMode() { - return KotlinPluginMode.K2; - } - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - @TestMetadata("booleanToInt.kt") - public void testBooleanToInt() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/booleanToInt.kt"); - } - - @TestMetadata("byte.kt") - public void testByte() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/byte.kt"); - } - - @TestMetadata("char.kt") - public void testChar() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/char.kt"); - } - - @TestMetadata("double.kt") - public void testDouble() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/double.kt"); - } - - @TestMetadata("float.kt") - public void testFloat() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/float.kt"); - } - - @TestMetadata("int.kt") - public void testInt() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/int.kt"); - } - - @TestMetadata("long.kt") - public void testLong() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/long.kt"); - } - - @TestMetadata("nullable.kt") - public void testNullable() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/nullable.kt"); - } - - @TestMetadata("nullable2.kt") - public void testNullable2() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/nullable2.kt"); - } - - @TestMetadata("safeString.kt") - public void testSafeString() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/safeString.kt"); - } - - @TestMetadata("safeString2.kt") - public void testSafeString2() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/safeString2.kt"); - } - - @TestMetadata("short.kt") - public void testShort() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/short.kt"); - } - - @TestMetadata("string.kt") - public void testString() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/string.kt"); - } - - @TestMetadata("toOtherType.kt") - public void testToOtherType() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/toOtherType.kt"); - } - - @TestMetadata("typealias.kt") - public void testTypealias() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/typealias.kt"); - } - - @TestMetadata("uByte.kt") - public void testUByte() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/uByte.kt"); - } - - @TestMetadata("uInt.kt") - public void testUInt() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/uInt.kt"); - } - - @TestMetadata("uLong.kt") - public void testULong() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/uLong.kt"); - } - - @TestMetadata("uShort.kt") - public void testUShort() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/uShort.kt"); - } - - @TestMetadata("variable.kt") - public void testVariable() throws Exception { - runTest("../../../idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/variable.kt"); - } - } @RunWith(JUnit3RunnerWithInners.class) @TestMetadata("../../../idea/tests/testData/inspectionsLocal/removeExplicitTypeArguments") diff --git a/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/ReplaceCallFix.kt b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/ReplaceCallFix.kt index f1ee2e5f41fb..12d57901939a 100644 --- a/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/ReplaceCallFix.kt +++ b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/ReplaceCallFix.kt @@ -76,6 +76,17 @@ class ReplaceImplicitReceiverCallFix( } } +class RemoveRedundantCallsOfConversionMethodsFix( + element: KtQualifiedExpression +) : PsiUpdateModCommandAction(element) { + + override fun getFamilyName(): @IntentionFamilyName String = KotlinBundle.message("remove.redundant.calls.of.the.conversion.method") + + override fun invoke(context: ActionContext, element: KtQualifiedExpression, updater: ModPsiUpdater) { + element.replace(element.receiverExpression) + } +} + class ReplaceWithSafeCallFix( element: KtDotQualifiedExpression, notNullNeeded: Boolean diff --git a/plugins/kotlin/idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/.k2Inspection b/plugins/kotlin/idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/.k2Inspection deleted file mode 100644 index 79e6c4f2f810..000000000000 --- a/plugins/kotlin/idea/tests/testData/inspectionsLocal/removeRedundantCallsOfConversionMethods/.k2Inspection +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.idea.k2.codeinsight.inspections.diagnosticBased.RemoveRedundantCallsOfConversionMethodsInspection \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/booleanToInt.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/booleanToInt.kt new file mode 100644 index 000000000000..66e2a321870c --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/booleanToInt.kt @@ -0,0 +1,6 @@ +// "Remove redundant calls of the conversion method" "false" +fun Boolean.toInt() = if (this) 1 else 0 + +fun test(x: Int, y: Int): Int { + return (x > y).toInt() +} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/byte.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/byte.kt new file mode 100644 index 000000000000..89dd8b70e05e --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/byte.kt @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = Byte.MAX_VALUE.toByte() +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/byte.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/byte.kt.after new file mode 100644 index 000000000000..5081c8b41fbd --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/byte.kt.after @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = Byte.MAX_VALUE +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/char.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/char.kt new file mode 100644 index 000000000000..886cd1c0de46 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/char.kt @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = 'a'.toChar() +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/char.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/char.kt.after new file mode 100644 index 000000000000..e31ebea4da97 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/char.kt.after @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = 'a' +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/double.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/double.kt new file mode 100644 index 000000000000..77ec43a2325d --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/double.kt @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = 1.1.toDouble() +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/double.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/double.kt.after new file mode 100644 index 000000000000..321a51f5abdb --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/double.kt.after @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = 1.1 +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/float.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/float.kt new file mode 100644 index 000000000000..213eee8c4b76 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/float.kt @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = 1.1f.toFloat() +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/float.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/float.kt.after new file mode 100644 index 000000000000..82f0173e7034 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/float.kt.after @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = 1.1f +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/int.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/int.kt new file mode 100644 index 000000000000..8d1d13652c6b --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/int.kt @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = 1.toInt() +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/int.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/int.kt.after new file mode 100644 index 000000000000..044413637e3e --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/int.kt.after @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = 1 +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/long.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/long.kt new file mode 100644 index 000000000000..c131842330d8 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/long.kt @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = Long.MAX_VALUE.toLong() +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/long.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/long.kt.after new file mode 100644 index 000000000000..f33c147fb23a --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/long.kt.after @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = Long.MAX_VALUE +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable.kt new file mode 100644 index 000000000000..d81857f4938e --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable.kt @@ -0,0 +1,5 @@ +// "Remove redundant calls of the conversion method" "false" +// WITH_STDLIB +fun foo(s: String?) { + val t: String = s.toString() +} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable2.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable2.kt new file mode 100644 index 000000000000..9ff06947e3d4 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/nullable2.kt @@ -0,0 +1,7 @@ +// "Remove redundant calls of the conversion method" "false" +// WITH_STDLIB +data class Foo(val name: String) + +fun nullable2(foo: Foo?) { + val s: String = foo?.name.toString() +} \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString.kt new file mode 100644 index 000000000000..7cfe4a5d53fa --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString.kt @@ -0,0 +1,9 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: The expression is unused + +fun test() { + val foo: String? = null + foo?.toString() +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString.kt.after new file mode 100644 index 000000000000..2442d26889b4 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString.kt.after @@ -0,0 +1,9 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: The expression is unused + +fun test() { + val foo: String? = null + foo +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString2.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString2.kt new file mode 100644 index 000000000000..6c21ed9c14de --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString2.kt @@ -0,0 +1,9 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 's' is never used +data class Foo(val name: String) + +fun test(foo: Foo?) { + val s: String? = foo?.name?.toString() +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString2.kt.after new file mode 100644 index 000000000000..f287467b2aed --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/safeString2.kt.after @@ -0,0 +1,9 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 's' is never used +data class Foo(val name: String) + +fun test(foo: Foo?) { + val s: String? = foo?.name +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/short.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/short.kt new file mode 100644 index 000000000000..32893b46043b --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/short.kt @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = Short.MAX_VALUE.toShort() +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/short.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/short.kt.after new file mode 100644 index 000000000000..bb5b82e40c6d --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/short.kt.after @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = Short.MAX_VALUE +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/string.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/string.kt new file mode 100644 index 000000000000..7953c9d0c051 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/string.kt @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = "".toString() +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/string.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/string.kt.after new file mode 100644 index 000000000000..8b8cdf46b103 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/string.kt.after @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = "" +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/toOtherType.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/toOtherType.kt new file mode 100644 index 000000000000..c7fe7ee06afc --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/toOtherType.kt @@ -0,0 +1,4 @@ +// "Remove redundant calls of the conversion method" "false" +// WITH_STDLIB +// PROBLEM: none +val foo = 1.toLong() \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/typealias.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/typealias.kt new file mode 100644 index 000000000000..587b003430e1 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/typealias.kt @@ -0,0 +1,8 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +typealias MyByte = Byte + +fun test(param: MyByte) { + val byte = param.toByte() +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/typealias.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/typealias.kt.after new file mode 100644 index 000000000000..cb5494515e0e --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/typealias.kt.after @@ -0,0 +1,8 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +typealias MyByte = Byte + +fun test(param: MyByte) { + val byte = param +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uByte.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uByte.kt new file mode 100644 index 000000000000..95aabe080e07 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uByte.kt @@ -0,0 +1,7 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 'foo' is never used +fun test(i: UByte) { + val foo = i.toUByte() +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uByte.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uByte.kt.after new file mode 100644 index 000000000000..e2f1442b225e --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uByte.kt.after @@ -0,0 +1,7 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 'foo' is never used +fun test(i: UByte) { + val foo = i +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uInt.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uInt.kt new file mode 100644 index 000000000000..37696dcf66d5 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uInt.kt @@ -0,0 +1,7 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 'foo' is never used +fun test(i: UInt) { + val foo = i.toUInt() +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uInt.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uInt.kt.after new file mode 100644 index 000000000000..850b0973283a --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uInt.kt.after @@ -0,0 +1,7 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 'foo' is never used +fun test(i: UInt) { + val foo = i +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uLong.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uLong.kt new file mode 100644 index 000000000000..02224f3a1cc4 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uLong.kt @@ -0,0 +1,7 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 'foo' is never used +fun test(i: ULong) { + val foo = i.toULong() +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uLong.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uLong.kt.after new file mode 100644 index 000000000000..87e2c6b1ecaa --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uLong.kt.after @@ -0,0 +1,7 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 'foo' is never used +fun test(i: ULong) { + val foo = i +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uShort.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uShort.kt new file mode 100644 index 000000000000..94ee023d0334 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uShort.kt @@ -0,0 +1,7 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 'foo' is never used +fun test(i: UShort) { + val foo = i.toUShort() +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uShort.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uShort.kt.after new file mode 100644 index 000000000000..8037ce2da254 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/uShort.kt.after @@ -0,0 +1,7 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +// AFTER-WARNING: Variable 'foo' is never used +fun test(i: UShort) { + val foo = i +} +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/variable.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/variable.kt new file mode 100644 index 000000000000..860e5c7cda63 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/variable.kt @@ -0,0 +1,5 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = "" +val bar = foo.toString() +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/variable.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/variable.kt.after new file mode 100644 index 000000000000..7c6b64cd307f --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeRedundantCallsOfConversionMethods/variable.kt.after @@ -0,0 +1,5 @@ +// "Remove redundant calls of the conversion method" "true" +// WITH_STDLIB +val foo = "" +val bar = foo +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix \ No newline at end of file diff --git a/plugins/kotlin/util/test-generator-fe10/test/org/jetbrains/kotlin/fe10/testGenerator/Fe10GenerateTests.kt b/plugins/kotlin/util/test-generator-fe10/test/org/jetbrains/kotlin/fe10/testGenerator/Fe10GenerateTests.kt index 75bbf9ac6ef5..26130115747d 100644 --- a/plugins/kotlin/util/test-generator-fe10/test/org/jetbrains/kotlin/fe10/testGenerator/Fe10GenerateTests.kt +++ b/plugins/kotlin/util/test-generator-fe10/test/org/jetbrains/kotlin/fe10/testGenerator/Fe10GenerateTests.kt @@ -67,10 +67,10 @@ import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest import org.jetbrains.kotlin.idea.hierarchy.AbstractHierarchyTest import org.jetbrains.kotlin.idea.hierarchy.AbstractHierarchyWithLibTest import org.jetbrains.kotlin.idea.highlighter.* -import org.jetbrains.kotlin.idea.imports.AbstractK1JsOptimizeImportsTest -import org.jetbrains.kotlin.idea.imports.AbstractK1JvmOptimizeImportsTest import org.jetbrains.kotlin.idea.imports.AbstractK1AutoImportTest import org.jetbrains.kotlin.idea.imports.AbstractK1FilteringAutoImportTest +import org.jetbrains.kotlin.idea.imports.AbstractK1JsOptimizeImportsTest +import org.jetbrains.kotlin.idea.imports.AbstractK1JvmOptimizeImportsTest import org.jetbrains.kotlin.idea.index.AbstractKotlinTypeAliasByExpansionShortNameIndexTest import org.jetbrains.kotlin.idea.inspections.* import org.jetbrains.kotlin.idea.intentions.AbstractConcatenatedStringGeneratorTest @@ -99,8 +99,8 @@ import org.jetbrains.kotlin.idea.refactoring.copy.AbstractMultiModuleCopyTest import org.jetbrains.kotlin.idea.refactoring.inline.AbstractInlineMultiFileTest import org.jetbrains.kotlin.idea.refactoring.inline.AbstractInlineTest import org.jetbrains.kotlin.idea.refactoring.inline.AbstractInlineTestWithSomeDescriptors -import org.jetbrains.kotlin.idea.refactoring.introduce.AbstractK1InplaceIntroduceFunctionTest import org.jetbrains.kotlin.idea.refactoring.introduce.AbstractK1ExtractionTest +import org.jetbrains.kotlin.idea.refactoring.introduce.AbstractK1InplaceIntroduceFunctionTest import org.jetbrains.kotlin.idea.refactoring.move.AbstractK1MultiModuleMoveTest import org.jetbrains.kotlin.idea.refactoring.move.AbstractMoveTest import org.jetbrains.kotlin.idea.refactoring.pullUp.AbstractPullUpTest @@ -483,6 +483,7 @@ private fun assembleWorkspace(): TWorkspace = workspace(KotlinPluginMode.K1) { "namedLambdaContextParameter", "useWithIndex", // Intention-based inspection in K1, covered by the intention tests "receiverShadowedByContextParameter", + "removeRedundantCallsOfConversionMethods", // K2 compiler diagnostic ) ) } diff --git a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2InspectionTests.kt b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2InspectionTests.kt index f3d7f0f72d80..bad3ac17f7cc 100644 --- a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2InspectionTests.kt +++ b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2InspectionTests.kt @@ -127,7 +127,10 @@ internal fun MutableTWorkspace.generateK2InspectionTests() { model("${idea}/inspectionsLocal/addOperatorModifier") model("${idea}/inspectionsLocal/kotlinUnreachableCode") model("${idea}/inspectionsLocal/removeRedundantLabel") - model("${idea}/inspectionsLocal/removeRedundantCallsOfConversionMethods") + + // removeRedundantCallsOfConversionMethods is implemented as compiler diagnostic, see quickfixes + model("${idea}/inspectionsLocal/removeRedundantCallsOfConversionMethods", isIgnored = true) + model("${idea}/inspectionsLocal/removeExplicitTypeArguments") model("${idea}/inspectionsLocal/defaultAnnotationTarget") model("${idea}/inspectionsLocal/redundantEnumConstructorInvocation") diff --git a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt index f48e21f13d27..1595484c9e95 100644 --- a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt +++ b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt @@ -1,11 +1,7 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.fir.testGenerator.codeinsight -import org.jetbrains.kotlin.idea.k2.codeinsight.fixes.AbstractHighLevelQuickFixMultiFileTest -import org.jetbrains.kotlin.idea.k2.codeinsight.fixes.AbstractHighLevelQuickFixMultiModuleTest -import org.jetbrains.kotlin.idea.k2.codeinsight.fixes.AbstractHighLevelQuickFixTest -import org.jetbrains.kotlin.idea.k2.codeinsight.fixes.AbstractHighLevelWithPostponedQuickFixMultiModuleTest -import org.jetbrains.kotlin.idea.k2.codeinsight.fixes.AbstractK2KDocUnresolvedReferenceTest +import org.jetbrains.kotlin.idea.k2.codeinsight.fixes.* import org.jetbrains.kotlin.testGenerator.model.* import org.jetbrains.kotlin.testGenerator.model.GroupCategory.QUICKFIXES import org.jetbrains.kotlin.testGenerator.model.Patterns.DIRECTORY @@ -144,6 +140,7 @@ internal fun MutableTWorkspace.generateK2FixTests() { model("$idea/quickfix/redundantModalityModifier", pattern = pattern) model("$idea/quickfix/redundantSuspend", pattern = pattern, isIgnored = true) model("$idea/quickfix/redundantVisibilityModifier", pattern = pattern) + model("$idea/quickfix/removeRedundantCallsOfConversionMethods", pattern = pattern) model("$idea/quickfix/removeRedundantReturn", pattern = pattern) model("$idea/quickfix/removeAnnotation", pattern = pattern, isIgnored = true) model("$idea/quickfix/removeArgument", pattern = pattern)