mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] KTIJ-36920 Convert RemoveRedundantCallsOfConversionMethodsInspection into a quickfix
As it is reported as compiler diagnostic GitOrigin-RevId: 0898acef4c4b2aab0bf39899427985da534265a6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b31f24c359
commit
8bdca1716f
+1
@@ -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)
|
||||
|
||||
+7
@@ -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<KaFirDiagnostic.RedundantCallOfConversionMethod> =
|
||||
KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.RedundantCallOfConversionMethod ->
|
||||
val element = diagnostic.psi as? KtQualifiedExpression ?: return@ModCommandBased emptyList()
|
||||
listOf(RemoveRedundantCallsOfConversionMethodsFix(element))
|
||||
}
|
||||
|
||||
val unsafeCallFactory: KotlinQuickFixFactory.ModCommandBased<KaFirDiagnostic.UnsafeCall> =
|
||||
KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.UnsafeCall ->
|
||||
val psi = diagnostic.psi
|
||||
|
||||
+115
-1
@@ -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 {
|
||||
|
||||
-10
@@ -950,16 +950,6 @@
|
||||
language="kotlin"
|
||||
key="inspection.unnecessary.variable.display.name" bundle="messages.KotlinBundle"/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.k2.codeinsight.inspections.diagnosticBased.RemoveRedundantCallsOfConversionMethodsInspection"
|
||||
groupPath="Kotlin"
|
||||
groupBundle="messages.KotlinBundle" groupKey="group.names.redundant.constructs"
|
||||
enabledByDefault="true"
|
||||
level="WARNING"
|
||||
language="kotlin"
|
||||
editorAttributes="NOT_USED_ELEMENT_ATTRIBUTES"
|
||||
key="redundant.call.of.the.conversion.method" bundle="messages.KotlinBundle">
|
||||
</localInspection>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.k2.codeinsight.intentions.RemoveEmptyPrimaryConstructorInspection"
|
||||
groupPath="Kotlin"
|
||||
groupBundle="messages.KotlinBundle" groupKey="group.names.redundant.constructs"
|
||||
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
// 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.idea.k2.codeinsight.inspections.diagnosticBased
|
||||
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.codeInspection.util.InspectionMessage
|
||||
import com.intellij.codeInspection.util.IntentionFamilyName
|
||||
import com.intellij.modcommand.ModPsiUpdater
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.analysis.api.KaSession
|
||||
import org.jetbrains.kotlin.analysis.api.components.KaDiagnosticCheckerFilter
|
||||
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections.KotlinModCommandQuickFix
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections.KotlinPsiDiagnosticBasedInspectionBase
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.ApplicabilityRange
|
||||
import org.jetbrains.kotlin.psi.KtQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtVisitor
|
||||
import org.jetbrains.kotlin.psi.qualifiedExpressionVisitor
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
internal class RemoveRedundantCallsOfConversionMethodsInspection :
|
||||
KotlinPsiDiagnosticBasedInspectionBase<KtQualifiedExpression, KaFirDiagnostic.RedundantCallOfConversionMethod, Unit>() {
|
||||
|
||||
override val diagnosticFilter: KaDiagnosticCheckerFilter = KaDiagnosticCheckerFilter.ONLY_COMMON_CHECKERS
|
||||
|
||||
override val diagnosticType: KClass<KaFirDiagnostic.RedundantCallOfConversionMethod>
|
||||
get() = KaFirDiagnostic.RedundantCallOfConversionMethod::class
|
||||
|
||||
override fun KaSession.prepareContextByDiagnostic(
|
||||
element: KtQualifiedExpression,
|
||||
diagnostic: KaFirDiagnostic.RedundantCallOfConversionMethod
|
||||
): Unit = Unit
|
||||
|
||||
override fun getApplicableRanges(element: KtQualifiedExpression): List<TextRange> {
|
||||
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<KtQualifiedExpression> = object : KotlinModCommandQuickFix<KtQualifiedExpression>() {
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
-112
@@ -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")
|
||||
|
||||
+11
@@ -76,6 +76,17 @@ class ReplaceImplicitReceiverCallFix(
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveRedundantCallsOfConversionMethodsFix(
|
||||
element: KtQualifiedExpression
|
||||
) : PsiUpdateModCommandAction<KtQualifiedExpression>(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
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
org.jetbrains.kotlin.idea.k2.codeinsight.inspections.diagnosticBased.RemoveRedundantCallsOfConversionMethodsInspection
|
||||
+6
@@ -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()<caret>
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
val foo = Byte.MAX_VALUE.toByte()<caret>
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+4
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
val foo = 'a'.toChar()<caret>
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+4
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
val foo = 1.1.toDouble()<caret>
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+4
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
val foo = 1.1f.toFloat()<caret>
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+4
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
val foo = 1.toInt()<caret>
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+4
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
val foo = Long.MAX_VALUE.toLong()<caret>
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+4
@@ -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
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Remove redundant calls of the conversion method" "false"
|
||||
// WITH_STDLIB
|
||||
fun foo(s: String?) {
|
||||
val t: String = s.toString()<caret>
|
||||
}
|
||||
+7
@@ -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()<caret>
|
||||
}
|
||||
+9
@@ -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()<caret>
|
||||
}
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+9
@@ -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
|
||||
+9
@@ -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()<caret>
|
||||
}
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+9
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
val foo = Short.MAX_VALUE.toShort<caret>()
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+4
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
val foo = "".toString()<caret>
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+4
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove redundant calls of the conversion method" "false"
|
||||
// WITH_STDLIB
|
||||
// PROBLEM: none
|
||||
val foo = 1.toLong()<caret>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
typealias MyByte = Byte
|
||||
|
||||
fun test(param: MyByte) {
|
||||
val byte = param.to<caret>Byte()
|
||||
}
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+8
@@ -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
|
||||
+7
@@ -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()<caret>
|
||||
}
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+7
@@ -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
|
||||
+7
@@ -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()<caret>
|
||||
}
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+7
@@ -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
|
||||
+7
@@ -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()<caret>
|
||||
}
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+7
@@ -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
|
||||
+7
@@ -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()<caret>
|
||||
}
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+7
@@ -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
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Remove redundant calls of the conversion method" "true"
|
||||
// WITH_STDLIB
|
||||
val foo = ""
|
||||
val bar = foo.toString()<caret>
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveRedundantCallsOfConversionMethodsFix
|
||||
+5
@@ -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
|
||||
+4
-3
@@ -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
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+4
-1
@@ -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")
|
||||
|
||||
+2
-5
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user