mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] K2: provide 'remove parameter name' quick fix for named lambda context params
KTIJ-34130 GitOrigin-RevId: efb62df7e085b505f6e0a1a491d199ee8bb3ba6c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7e5679a91e
commit
3a83ced677
@@ -1223,6 +1223,7 @@ remove.modifier.fix.family=Make not {0}
|
||||
remove.0.modifier=Remove ''{0}'' modifier
|
||||
remove.modifier=Remove modifier
|
||||
remove.identifier.from.anonymous.function=Remove identifier from anonymous function
|
||||
remove.parameter.name=Remove parameter name
|
||||
remove.constructor.call=Remove constructor call
|
||||
make.not.nullable=Make not-nullable
|
||||
remove.useless=Remove useless '?'
|
||||
|
||||
+1
@@ -564,6 +564,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
|
||||
registerFactory(ConvertExtensionToFunctionTypeFixFactory.superTypeIsExtensionFunctionType)
|
||||
|
||||
registerFactory(RenameUnderscoreFixFactory.renameUnderscore)
|
||||
registerFactory(NamedContextParameterInFunctionTypeFixFactory.removeParameterName)
|
||||
}
|
||||
|
||||
private val optIn = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// 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.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.RemoveParameterNameFix
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
|
||||
internal object NamedContextParameterInFunctionTypeFixFactory {
|
||||
val removeParameterName = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.NamedContextParameterInFunctionType ->
|
||||
val contextParameter = diagnostic.psi as? KtParameter ?: return@ModCommandBased emptyList()
|
||||
listOf(RemoveParameterNameFix(contextParameter))
|
||||
}
|
||||
}
|
||||
+39
@@ -13878,6 +13878,45 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../../idea/tests/testData/quickfix/namedLambdaContextParameter")
|
||||
public static class NamedLambdaContextParameter 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("noNameAlready.kt")
|
||||
public void testNoNameAlready() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/namedLambdaContextParameter/noNameAlready.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notLambdaContext.kt")
|
||||
public void testNotLambdaContext() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/namedLambdaContextParameter/notLambdaContext.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("oneContext.kt")
|
||||
public void testOneContext() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/namedLambdaContextParameter/oneContext.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("twoContexts.kt")
|
||||
public void testTwoContexts() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/namedLambdaContextParameter/twoContexts.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withComments.kt")
|
||||
public void testWithComments() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/namedLambdaContextParameter/withComments.kt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// 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.quickfix
|
||||
|
||||
import com.intellij.codeInspection.util.IntentionFamilyName
|
||||
import com.intellij.modcommand.ActionContext
|
||||
import com.intellij.modcommand.ModPsiUpdater
|
||||
import com.intellij.modcommand.PsiUpdateModCommandAction
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
|
||||
class RemoveParameterNameFix(element: KtParameter) : PsiUpdateModCommandAction<KtParameter>(element) {
|
||||
override fun getFamilyName(): @IntentionFamilyName String = KotlinBundle.message("remove.parameter.name")
|
||||
|
||||
override fun invoke(context: ActionContext, element: KtParameter, updater: ModPsiUpdater) {
|
||||
element.nameIdentifier?.delete()
|
||||
element.colon?.delete()
|
||||
}
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Remove parameter name" "false"
|
||||
// COMPILER_ARGUMENTS: -Xcontext-parameters
|
||||
|
||||
fun foo(bar: context(<caret>String)() -> Unit) {
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Remove parameter name" "false"
|
||||
// COMPILER_ARGUMENTS: -Xcontext-parameters
|
||||
|
||||
context(c: <caret>String)
|
||||
fun foo(bar: () -> Unit) {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Remove parameter name" "true"
|
||||
// COMPILER_ARGUMENTS: -Xcontext-parameters
|
||||
|
||||
fun foo(bar: context(c: <caret>String)() -> Unit) {
|
||||
}
|
||||
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveParameterNameFix
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Remove parameter name" "true"
|
||||
// COMPILER_ARGUMENTS: -Xcontext-parameters
|
||||
|
||||
fun foo(bar: context(String)() -> Unit) {
|
||||
}
|
||||
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveParameterNameFix
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Remove parameter name" "true"
|
||||
// COMPILER_ARGUMENTS: -Xcontext-parameters
|
||||
|
||||
fun foo(bar: context(Int, c2: <caret>String)() -> Unit) {
|
||||
}
|
||||
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveParameterNameFix
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Remove parameter name" "true"
|
||||
// COMPILER_ARGUMENTS: -Xcontext-parameters
|
||||
|
||||
fun foo(bar: context(Int, String)() -> Unit) {
|
||||
}
|
||||
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveParameterNameFix
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Remove parameter name" "true"
|
||||
// COMPILER_ARGUMENTS: -Xcontext-parameters
|
||||
|
||||
fun foo(bar: context(/*1*/c/*2*/:/*3*/ <caret>String/*4*/)() -> Unit) {
|
||||
}
|
||||
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveParameterNameFix
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Remove parameter name" "true"
|
||||
// COMPILER_ARGUMENTS: -Xcontext-parameters
|
||||
|
||||
fun foo(bar: context(/*1*//*2*//*3*/ String/*4*/)() -> Unit) {
|
||||
}
|
||||
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveParameterNameFix
|
||||
+1
@@ -453,6 +453,7 @@ private fun assembleWorkspace(): TWorkspace = workspace(KotlinPluginMode.K1) {
|
||||
"redundantInterpolationPrefix", // K2-only multi-dollar interpolation
|
||||
"addInterpolationPrefixUnresolvedReference", // K2-only multi-dollar interpolation
|
||||
"unsupportedFeature", // K2-related features only
|
||||
"namedLambdaContextParameter",
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+1
@@ -140,6 +140,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
|
||||
model("$idea/quickfix/moveToConstructorParameters", pattern = pattern)
|
||||
model("$idea/quickfix/moveToSealedParent", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/moveTypeAliasToTopLevel", pattern = pattern)
|
||||
model("$idea/quickfix/namedLambdaContextParameter", pattern = pattern)
|
||||
model("$idea/quickfix/obsoleteKotlinJsPackages", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/optimizeImports", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/platformClasses", pattern = pattern, isIgnored = true)
|
||||
|
||||
Reference in New Issue
Block a user