mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Port InlineTypeParameterFix to K2
This quick is for the FINAL_UPPER_BOUND compiler warning. ^KTIJ-29501 GitOrigin-RevId: 8f8f66b1af5e60208a0ecf6e155466db76628ce9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4f99adcce1
commit
48117cfbb5
+37
@@ -0,0 +1,37 @@
|
||||
// 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.createSmartPointer
|
||||
import com.intellij.psi.util.descendantsOfType
|
||||
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
|
||||
import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
|
||||
import org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
import org.jetbrains.kotlin.idea.quickfix.prepareInlinedTypeParameterContext
|
||||
import org.jetbrains.kotlin.psi.KtTypeParameterListOwner
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
internal object FinalUpperBoundFixFactories {
|
||||
|
||||
val inlineTypeParameterFixFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.FinalUpperBound ->
|
||||
val element = diagnostic.psi as? KtTypeReference ?: return@ModCommandBased emptyList()
|
||||
val parameterListOwner = element.getStrictParentOfType<KtTypeParameterListOwner>() ?: return@ModCommandBased emptyList()
|
||||
val parameterList = parameterListOwner.typeParameterList ?: return@ModCommandBased emptyList()
|
||||
val (parameter, _, _) = prepareInlinedTypeParameterContext(element, parameterList) ?: return@ModCommandBased emptyList()
|
||||
val parameterSymbol = parameter.symbol
|
||||
|
||||
val typeReferencesToInline = parameterListOwner
|
||||
.descendantsOfType<KtTypeReference>()
|
||||
.filter { typeReference ->
|
||||
val typeElement = typeReference.typeElement
|
||||
val type = typeReference.type as? KaTypeParameterType
|
||||
typeElement != null && type?.symbol == parameterSymbol
|
||||
}.map { it.createSmartPointer() }
|
||||
.toList()
|
||||
|
||||
listOf(
|
||||
InlineTypeParameterFix(element, typeReferencesToInline)
|
||||
)
|
||||
}
|
||||
}
|
||||
+1
@@ -174,6 +174,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
|
||||
registerFactory(WrapWithParenthesesFixFactories.suspendFunErrorFixFactory)
|
||||
registerFactory(DeclarationCantBeInlinedFixFactories.removeOpenModifierFixFactory)
|
||||
registerFactory(WrongAnnotationTargetFixFactories.addAnnotationUseSiteTargetFixFactory)
|
||||
registerFactory(FinalUpperBoundFixFactories.inlineTypeParameterFixFactory)
|
||||
}
|
||||
|
||||
private val addAbstract = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||
|
||||
+37
@@ -9594,7 +9594,44 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../../idea/tests/testData/quickfix/inlineTypeParameterFix")
|
||||
public static class InlineTypeParameterFix 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("basic.kt")
|
||||
public void testBasic() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/inlineTypeParameterFix/basic.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("basicMultipleDef.kt")
|
||||
public void testBasicMultipleDef() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/inlineTypeParameterFix/basicMultipleDef.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("function.kt")
|
||||
public void testFunction() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/inlineTypeParameterFix/function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeConstraint.kt")
|
||||
public void testTypeConstraint() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/inlineTypeParameterFix/typeConstraint.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeConstraintMultipleDef.kt")
|
||||
public void testTypeConstraintMultipleDef() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/inlineTypeParameterFix/typeConstraintMultipleDef.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../../idea/tests/testData/quickfix/insertDelegationCall")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Inline type parameter" "true"
|
||||
|
||||
data class DC<T : Int<caret>>(val x: T, val y: String)
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Inline type parameter" "true"
|
||||
|
||||
data class DC(val x: Int, val y: String)
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
+2
-1
@@ -7,4 +7,5 @@ data class DC<T : Int<caret>, S : String>(val x: T, val y: String) {
|
||||
val c: T = Int.MIN_VALUE
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
+2
-1
@@ -7,4 +7,5 @@ data class DC<S : String>(val x: Int, val y: String) {
|
||||
val c: Int = Int.MIN_VALUE
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
@@ -5,4 +5,5 @@ data class DC(val x: Int, val y: String) {
|
||||
val a: S = Int.MAX_VALUE
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ data class DC(val x: Int, val y: String) {
|
||||
val a: Int = Int.MAX_VALUE
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
// "Inline type parameter" "true"
|
||||
fun <T> test(p: T, q: T) where T : String<caret> = p.length + q.length
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
// "Inline type parameter" "true"
|
||||
fun test(p: String, q: String) = p.length + q.length
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
// "Inline type parameter" "true"
|
||||
open class MyClass { val length = 0 }
|
||||
fun <T, U> test(p: T, q: U) where T : MyClass, U: Int<caret> = p.length + q
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
// "Inline type parameter" "true"
|
||||
open class MyClass { val length = 0 }
|
||||
fun <T> test(p: T, q: Int) where T : MyClass = p.length + q
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InlineTypeParameterFix
|
||||
+1
-1
@@ -126,7 +126,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
|
||||
model("$idea/quickfix/increaseVisibility", pattern = pattern)
|
||||
model("$idea/quickfix/initializeWithConstructorParameter", pattern = pattern)
|
||||
model("$idea/quickfix/inlineClass", pattern = pattern)
|
||||
model("$idea/quickfix/inlineTypeParameterFix", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/inlineTypeParameterFix", pattern = pattern)
|
||||
model("$idea/quickfix/insertDelegationCall", pattern = pattern)
|
||||
model("$idea/quickfix/isEnumEntry", pattern = pattern)
|
||||
model("$idea/quickfix/javaClassOnCompanion", pattern = pattern, isIgnored = true)
|
||||
|
||||
Reference in New Issue
Block a user