[Kotlin] Drop quickfixes that rename mod into rem

The Kotlin compiler reports INAPPLICABLE_OPERATOR_MODIFIER instead of
FORBIDDEN_BINARY_MOD.

#KT-36107

GitOrigin-RevId: 8d251e1c84c6a75af39d5d541dccdf0f410d8d62
This commit is contained in:
Ivan Kylchik
2024-10-01 08:28:55 +00:00
committed by intellij-monorepo-bot
parent 43c13a2fe5
commit d202a7a689
20 changed files with 1 additions and 313 deletions
@@ -138,8 +138,6 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
registerFactory(ChangeAccessorTypeFixFactory.wrongGetterReturnTypeFactory)
registerFactory(ChangeAccessorTypeFixFactory.wrongSetterParameterTypeFactory)
registerFactory(LiftAssignmentOutOfTryFixFactory.liftAssignmentOutOfTryFix)
registerFactory(RenameModToRemFixFactory.deprecatedBinaryModFactory)
registerFactory(RenameModToRemFixFactory.forbiddenBinaryModFactory)
registerFactory(KaFirDiagnostic.UnresolvedLabel::class, CreateLabelFixFactories.unresolvedLabelFactory)
registerFactory(KaFirDiagnostic.NotALoopLabel::class, CreateLabelFixFactories.notALoopLabelFactory)
registerFactory(AddDefaultConstructorFixFactory.addDefaultConstructorFixFactory)
@@ -1,30 +0,0 @@
// Copyright 2000-2024 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
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
import org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
import org.jetbrains.kotlin.types.expressions.OperatorConventions.REM_TO_MOD_OPERATION_NAMES
internal object RenameModToRemFixFactory {
val deprecatedBinaryModFactory = KotlinQuickFixFactory.IntentionBased { diagnostic: KaFirDiagnostic.DeprecatedBinaryMod ->
createQuickFix(diagnostic.psi)
}
val forbiddenBinaryModFactory = KotlinQuickFixFactory.IntentionBased { diagnostic: KaFirDiagnostic.ForbiddenBinaryMod ->
createQuickFix(diagnostic.psi)
}
private fun createQuickFix(element: PsiElement): List<RenameModToRemFix> {
val operatorMod = element.getNonStrictParentOfType<KtNamedFunction>() ?: return emptyList()
val newName = operatorMod.nameAsName?.let { REM_TO_MOD_OPERATION_NAMES.inverse()[it] } ?: return emptyList()
return listOf(
RenameModToRemFix(operatorMod, newName)
)
}
}
@@ -1912,21 +1912,6 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
runTest("../../../idea/tests/testData/quickfix/modifiers/removeInnerForClassInInterface.kt");
}
@TestMetadata("removeModifierFromForbiddenOperatorMod.kt")
public void testRemoveModifierFromForbiddenOperatorMod() throws Exception {
runTest("../../../idea/tests/testData/quickfix/modifiers/removeModifierFromForbiddenOperatorMod.kt");
}
@TestMetadata("removeModifierFromOperatorMod.kt")
public void testRemoveModifierFromOperatorMod() throws Exception {
runTest("../../../idea/tests/testData/quickfix/modifiers/removeModifierFromOperatorMod.kt");
}
@TestMetadata("removeModifierFromOperatorModAssign.kt")
public void testRemoveModifierFromOperatorModAssign() throws Exception {
runTest("../../../idea/tests/testData/quickfix/modifiers/removeModifierFromOperatorModAssign.kt");
}
@TestMetadata("removeProtectedModifier.kt")
public void testRemoveProtectedModifier() throws Exception {
runTest("../../../idea/tests/testData/quickfix/modifiers/removeProtectedModifier.kt");
@@ -10684,36 +10669,8 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../../../idea/tests/testData/quickfix/renameToRem")
public static class RenameToRem extends AbstractHighLevelQuickFixTest {
@java.lang.Override
@org.jetbrains.annotations.NotNull
public final KotlinPluginMode getPluginMode() {
return KotlinPluginMode.K2;
}
public abstract static class RenameToRem extends AbstractHighLevelQuickFixTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("forbiddenModAsMember.kt")
public void testForbiddenModAsMember() throws Exception {
runTest("../../../idea/tests/testData/quickfix/renameToRem/forbiddenModAsMember.kt");
}
@TestMetadata("modAsExtension.kt")
public void testModAsExtension() throws Exception {
runTest("../../../idea/tests/testData/quickfix/renameToRem/modAsExtension.kt");
}
@TestMetadata("modAsMember.kt")
public void testModAsMember() throws Exception {
runTest("../../../idea/tests/testData/quickfix/renameToRem/modAsMember.kt");
}
@TestMetadata("modAssignAsMember.kt")
public void testModAssignAsMember() throws Exception {
runTest("../../../idea/tests/testData/quickfix/renameToRem/modAssignAsMember.kt");
}
}
@@ -152,10 +152,6 @@ class QuickFixRegistrar : QuickFixContributor {
NON_PRIVATE_CONSTRUCTOR_IN_SEALED.registerFactory(RemoveModifierFixBase.removeNonRedundantModifier)
NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED.registerFactory(RemoveModifierFixBase.removeNonRedundantModifier)
TYPE_CANT_BE_USED_FOR_CONST_VAL.registerFactory(RemoveModifierFixBase.removeNonRedundantModifier)
DEPRECATED_BINARY_MOD.registerFactory(RemoveModifierFixBase.removeNonRedundantModifier)
DEPRECATED_BINARY_MOD.registerFactory(RenameModToRemFixFactory)
FORBIDDEN_BINARY_MOD.registerFactory(RemoveModifierFixBase.removeNonRedundantModifier)
FORBIDDEN_BINARY_MOD.registerFactory(RenameModToRemFixFactory)
NO_EXPLICIT_VISIBILITY_IN_API_MODE.registerFactory(ChangeVisibilityFix.SetExplicitVisibilityFactory)
NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING.registerFactory(ChangeVisibilityFix.SetExplicitVisibilityFactory)
@@ -1,20 +0,0 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.quickfix
import com.intellij.codeInsight.intention.IntentionAction
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
import org.jetbrains.kotlin.types.expressions.OperatorConventions.REM_TO_MOD_OPERATION_NAMES
internal object RenameModToRemFixFactory : KotlinSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
if (diagnostic.factory != Errors.DEPRECATED_BINARY_MOD && diagnostic.factory != Errors.FORBIDDEN_BINARY_MOD) return null
val operatorMod = diagnostic.psiElement.getNonStrictParentOfType<KtNamedFunction>() ?: return null
val newName = operatorMod.nameAsName?.let { REM_TO_MOD_OPERATION_NAMES.inverse()[it] } ?: return null
return RenameModToRemFix(operatorMod, newName)
}
}
@@ -11646,21 +11646,6 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest {
runTest("testData/quickfix/modifiers/removeInnerForClassInInterface.kt");
}
@TestMetadata("removeModifierFromForbiddenOperatorMod.kt")
public void testRemoveModifierFromForbiddenOperatorMod() throws Exception {
runTest("testData/quickfix/modifiers/removeModifierFromForbiddenOperatorMod.kt");
}
@TestMetadata("removeModifierFromOperatorMod.kt")
public void testRemoveModifierFromOperatorMod() throws Exception {
runTest("testData/quickfix/modifiers/removeModifierFromOperatorMod.kt");
}
@TestMetadata("removeModifierFromOperatorModAssign.kt")
public void testRemoveModifierFromOperatorModAssign() throws Exception {
runTest("testData/quickfix/modifiers/removeModifierFromOperatorModAssign.kt");
}
@TestMetadata("removeProtectedModifier.kt")
public void testRemoveProtectedModifier() throws Exception {
runTest("testData/quickfix/modifiers/removeProtectedModifier.kt");
@@ -14637,40 +14622,6 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest {
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("testData/quickfix/renameToRem")
public static class RenameToRem extends AbstractK1QuickFixTest {
@java.lang.Override
@org.jetbrains.annotations.NotNull
public final KotlinPluginMode getPluginMode() {
return KotlinPluginMode.K1;
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("forbiddenModAsMember.kt")
public void testForbiddenModAsMember() throws Exception {
runTest("testData/quickfix/renameToRem/forbiddenModAsMember.kt");
}
@TestMetadata("modAsExtension.kt")
public void testModAsExtension() throws Exception {
runTest("testData/quickfix/renameToRem/modAsExtension.kt");
}
@TestMetadata("modAsMember.kt")
public void testModAsMember() throws Exception {
runTest("testData/quickfix/renameToRem/modAsMember.kt");
}
@TestMetadata("modAssignAsMember.kt")
public void testModAssignAsMember() throws Exception {
runTest("testData/quickfix/renameToRem/modAssignAsMember.kt");
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("testData/quickfix/renameToUnderscore")
public static class RenameToUnderscore extends AbstractK1QuickFixTest {
@@ -1,8 +0,0 @@
// "Remove 'operator' modifier" "true"
// COMPILER_ARGUMENTS: -XXLanguage:+ProhibitOperatorMod
object A {
operator<caret> fun mod(x: Int) {}
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
@@ -1,8 +0,0 @@
// "Remove 'operator' modifier" "true"
// COMPILER_ARGUMENTS: -XXLanguage:+ProhibitOperatorMod
object A {
fun mod(x: Int) {}
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
@@ -1,7 +0,0 @@
// "Remove 'operator' modifier" "true"
object A {
operator<caret> fun mod(x: Int) {}
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
@@ -1,7 +0,0 @@
// "Remove 'operator' modifier" "true"
object A {
<caret>fun mod(x: Int) {}
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
@@ -1,7 +0,0 @@
// "Remove 'operator' modifier" "true"
object A {
operator<caret> fun modAssign(x: Int) {}
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
@@ -1,7 +0,0 @@
// "Remove 'operator' modifier" "true"
object A {
<caret>fun modAssign(x: Int) {}
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
@@ -1,16 +0,0 @@
// "Rename to 'rem'" "true"
// DISABLE-ERRORS
// COMPILER_ARGUMENTS: -XXLanguage:+ProhibitOperatorMod
object Rem {
operator<caret> fun mod(x: Int) {}
operator fun modAssign(x: Int) {}
}
fun test() {
Rem % 1
Rem.mod(1)
Rem.modAssign(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
@@ -1,16 +0,0 @@
// "Rename to 'rem'" "true"
// DISABLE-ERRORS
// COMPILER_ARGUMENTS: -XXLanguage:+ProhibitOperatorMod
object Rem {
operator fun rem(x: Int) {}
operator fun modAssign(x: Int) {}
}
fun test() {
Rem % 1
Rem.rem(1)
Rem.modAssign(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
@@ -1,12 +0,0 @@
// "Rename to 'rem'" "true"
// DISABLE-ERRORS
object A
operator<caret> fun A.mod(x: Int) {}
fun test() {
A.mod(3)
A % 2
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
@@ -1,12 +0,0 @@
// "Rename to 'rem'" "true"
// DISABLE-ERRORS
object A
operator<caret> fun A.rem(x: Int) {}
fun test() {
A.rem(3)
A % 2
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
@@ -1,15 +0,0 @@
// "Rename to 'rem'" "true"
// DISABLE-ERRORS
object Rem {
operator<caret> fun mod(x: Int) {}
operator fun modAssign(x: Int) {}
}
fun test() {
Rem % 1
Rem.mod(1)
Rem.modAssign(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
@@ -1,15 +0,0 @@
// "Rename to 'rem'" "true"
// DISABLE-ERRORS
object Rem {
operator fun rem(x: Int) {}
operator fun modAssign(x: Int) {}
}
fun test() {
Rem % 1
Rem.rem(1)
Rem.modAssign(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
@@ -1,17 +0,0 @@
// "Rename to 'remAssign'" "true"
// DISABLE-ERRORS
object Rem {
operator fun mod(x: Int) {}
operator<caret> fun modAssign(x: Int) {}
}
fun test() {
Rem % 1
Rem.mod(1)
Rem.modAssign(1)
val c = Rem
c %= 1
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
@@ -1,17 +0,0 @@
// "Rename to 'remAssign'" "true"
// DISABLE-ERRORS
object Rem {
operator fun mod(x: Int) {}
operator fun remAssign(x: Int) {}
}
fun test() {
Rem % 1
Rem.mod(1)
Rem.remAssign(1)
val c = Rem
c %= 1
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RenameModToRemFix