[kotlin] Port MoveTypeParameterConstraintFix to K2

This quick fix is for the MISPLACED_TYPE_PARAMETER_CONSTRAINTS compiler warning.

^KTIJ-29517

GitOrigin-RevId: 6737678923ff3a19f835006e71589b41aff24007
This commit is contained in:
Andrey Cherkasov
2024-07-27 23:46:11 +00:00
committed by intellij-monorepo-bot
parent 9c97defdb5
commit 7b4e57696d
8 changed files with 45 additions and 5 deletions
@@ -135,6 +135,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
registerFactory(IsEnumEntryFixFactory.factory)
registerFactory(NoReturnInFunctionWithBlockBodyFixFactory.addReturnToLastExpression)
registerFactory(InlineClassDeprecatedFixFactory.replaceWithValue)
registerFactory(MisplacedTypeParameterConstraintsFixFactory.moveConstraintToWhereClause)
}
private val addAbstract = KtQuickFixesListBuilder.registerPsiQuickFix {
@@ -0,0 +1,13 @@
// 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 org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
import org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
internal object MisplacedTypeParameterConstraintsFixFactory {
val moveConstraintToWhereClause = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.MisplacedTypeParameterConstraints ->
listOf(MoveTypeParameterConstraintFix(diagnostic.psi))
}
}
@@ -10213,7 +10213,29 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../../../idea/tests/testData/quickfix/typeParameters")
public static class TypeParameters 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("misplacedClassTypeParameter.kt")
public void testMisplacedClassTypeParameter() throws Exception {
runTest("../../../idea/tests/testData/quickfix/typeParameters/misplacedClassTypeParameter.kt");
}
@TestMetadata("misplacedFunctionTypeParameter.kt")
public void testMisplacedFunctionTypeParameter() throws Exception {
runTest("../../../idea/tests/testData/quickfix/typeParameters/misplacedFunctionTypeParameter.kt");
}
}
@@ -2,4 +2,5 @@
class A<<caret>T : Cloneable> where T : Comparable<*> {
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
@@ -2,4 +2,5 @@
class A<T> where T : Cloneable, T : Comparable<*> {
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
@@ -2,4 +2,5 @@
fun <<caret>T : Cloneable> foo() where T : Comparable<*> {
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
@@ -2,4 +2,5 @@
fun <T> foo() where T : Cloneable, T : Comparable<*> {
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MoveTypeParameterConstraintFix
@@ -193,7 +193,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
model("$idea/quickfix/typeImports", pattern = pattern)
model("$idea/quickfix/typeInferenceExpectedTypeMismatch", pattern = pattern, isIgnored = true)
model("$idea/quickfix/typeOfAnnotationMember", pattern = pattern)
model("$idea/quickfix/typeParameters", pattern = pattern, isIgnored = true)
model("$idea/quickfix/typeParameters", pattern = pattern)
model("$idea/quickfix/typeProjection", pattern = pattern, isIgnored = true)
model("$idea/quickfix/unnecessaryLateinit", pattern = pattern, isIgnored = true)
model("$idea/quickfix/unusedSuppressAnnotation", pattern = pattern, isIgnored = true)