From 75bbbc2f009049eadf7b420c3607507344e7ff88 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Tue, 15 Aug 2023 12:09:24 +0200 Subject: [PATCH] [Kotlin] Add quick fix replacing arguments of annotation from expect declaration side ^KTIJ-26633 GitOrigin-RevId: 8324f66558b16549efcc545feb9609db34db3a8e --- .../messages/KotlinBundle.properties | 1 + ...LevelQuickFixMultiModuleTestGenerated.java | 5 ++++ ...notationsNotMatchExpectFixFactoryCommon.kt | 25 +++++++++++-------- .../QuickFixMultiModuleTestGenerated.java | 5 ++++ .../replaceArgsOnExpect/common/common.kt | 5 ++++ .../common/common.kt.after | 5 ++++ .../replaceArgsOnExpect/dependencies.txt | 6 +++++ .../replaceArgsOnExpect/jvm/jvm.kt | 6 +++++ 8 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/common/common.kt create mode 100644 plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/common/common.kt.after create mode 100644 plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/dependencies.txt create mode 100644 plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/jvm/jvm.kt diff --git a/plugins/kotlin/base/resources/resources-en/messages/KotlinBundle.properties b/plugins/kotlin/base/resources/resources-en/messages/KotlinBundle.properties index ca7e4375f8f8..327796d2b769 100644 --- a/plugins/kotlin/base/resources/resources-en/messages/KotlinBundle.properties +++ b/plugins/kotlin/base/resources/resources-en/messages/KotlinBundle.properties @@ -174,6 +174,7 @@ fix.create.missing.actual.declarations.title=Add Missing Actual Declarations fix.remove.mismatched.annotation.from.expect.declaration.may.change.semantics=Remove mismatched annotation ''{0}'' from expect declaration (may change semantics) fix.copy.mismatched.annotation.to.actual.declaration.may.change.semantics=Copy mismatched annotation ''{0}'' from expect to actual declaration (may change semantics) fix.replace.mismatched.annotation.args.on.actual.declaration.may.change.semantics=Replace arguments of mismatched annotation ''{0}'' on actual declaration (may change semantics) +fix.replace.mismatched.annotation.args.on.expect.declaration.may.change.semantics=Replace arguments of mismatched annotation ''{0}'' on expect declaration (may change semantics) fix.create.declaration.error=Cannot generate {0}: {1} fix.create.declaration.error.inaccessible.type=Inaccessible Type diff --git a/plugins/kotlin/fir/test/org/jetbrains/kotlin/idea/fir/quickfix/HighLevelQuickFixMultiModuleTestGenerated.java b/plugins/kotlin/fir/test/org/jetbrains/kotlin/idea/fir/quickfix/HighLevelQuickFixMultiModuleTestGenerated.java index 9be627d9562b..aa1198d64f01 100644 --- a/plugins/kotlin/fir/test/org/jetbrains/kotlin/idea/fir/quickfix/HighLevelQuickFixMultiModuleTestGenerated.java +++ b/plugins/kotlin/fir/test/org/jetbrains/kotlin/idea/fir/quickfix/HighLevelQuickFixMultiModuleTestGenerated.java @@ -203,6 +203,11 @@ public abstract class HighLevelQuickFixMultiModuleTestGenerated extends Abstract public void testReplaceArgsOnActualOverrideWithEmpty() throws Exception { runTest("../idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnActualOverrideWithEmpty/"); } + + @TestMetadata("replaceArgsOnExpect") + public void testReplaceArgsOnExpect() throws Exception { + runTest("../idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/"); + } } @RunWith(JUnit3RunnerWithInners.class) diff --git a/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/ActualAnnotationsNotMatchExpectFixFactoryCommon.kt b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/ActualAnnotationsNotMatchExpectFixFactoryCommon.kt index d2bc20f4b166..b9c3a674a438 100644 --- a/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/ActualAnnotationsNotMatchExpectFixFactoryCommon.kt +++ b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/ActualAnnotationsNotMatchExpectFixFactoryCommon.kt @@ -39,18 +39,23 @@ object ActualAnnotationsNotMatchExpectFixFactoryCommon { is ExpectActualAnnotationsIncompatibilityType.DifferentOnActual -> incompatibilityType.actualAnnotation } - val fixOnActualFix = if (actualAnnotationEntry == null) { - createCopyFromExpectToActualFix(expectAnnotationEntry, actualDeclaration, annotationClassIdProvider) - } else { - val annotationName = expectAnnotationEntry.shortName ?: return emptyList() - ReplaceAnnotationArgumentsInExpectActualFix( - KotlinBundle.message("fix.replace.mismatched.annotation.args.on.actual.declaration.may.change.semantics", annotationName), - copyFromAnnotationEntry = expectAnnotationEntry, - copyToAnnotationEntry = actualAnnotationEntry, - ) + if (actualAnnotationEntry == null) { + val copyFromExpect = createCopyFromExpectToActualFix(expectAnnotationEntry, actualDeclaration, annotationClassIdProvider) + return listOfNotNull(copyFromExpect) } - return listOfNotNull(fixOnActualFix) + val annotationName = expectAnnotationEntry.shortName ?: return emptyList() + val fixOnActual = ReplaceAnnotationArgumentsInExpectActualFix( + KotlinBundle.message("fix.replace.mismatched.annotation.args.on.actual.declaration.may.change.semantics", annotationName), + copyFromAnnotationEntry = expectAnnotationEntry, + copyToAnnotationEntry = actualAnnotationEntry, + ) + val fixOnExpect = ReplaceAnnotationArgumentsInExpectActualFix( + KotlinBundle.message("fix.replace.mismatched.annotation.args.on.expect.declaration.may.change.semantics", annotationName), + copyFromAnnotationEntry = actualAnnotationEntry, + copyToAnnotationEntry = expectAnnotationEntry, + ) + return listOf(fixOnActual, fixOnExpect) } private fun createCopyFromExpectToActualFix( diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java index 5b64cb08f2f8..bfbeae764c44 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java @@ -203,6 +203,11 @@ public abstract class QuickFixMultiModuleTestGenerated extends AbstractQuickFixM public void testReplaceArgsOnActualOverrideWithEmpty() throws Exception { runTest("testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnActualOverrideWithEmpty/"); } + + @TestMetadata("replaceArgsOnExpect") + public void testReplaceArgsOnExpect() throws Exception { + runTest("testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/"); + } } @RunWith(JUnit3RunnerWithInners.class) diff --git a/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/common/common.kt b/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/common/common.kt new file mode 100644 index 000000000000..8c3cfa45fa2e --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/common/common.kt @@ -0,0 +1,5 @@ +// DISABLE-ERRORS +annotation class Ann(val value: String) + +@Ann("value") +expect fun foo() diff --git a/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/common/common.kt.after b/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/common/common.kt.after new file mode 100644 index 000000000000..df799749f309 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/common/common.kt.after @@ -0,0 +1,5 @@ +// DISABLE-ERRORS +annotation class Ann(val value: String) + +@Ann("different value") +expect fun foo() diff --git a/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/dependencies.txt b/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/dependencies.txt new file mode 100644 index 000000000000..2769ede81e95 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/dependencies.txt @@ -0,0 +1,6 @@ +MODULE common { platform=[JVM, JS, Native]; root=common } +MODULE jvm { platform=[JVM]; root=jvm } + +common -> STDLIB_COMMON { kind=DEPENDENCY } +jvm -> common { kind=DEPENDS_ON } +jvm -> STDLIB_JVM { kind=DEPENDENCY } diff --git a/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/jvm/jvm.kt b/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/jvm/jvm.kt new file mode 100644 index 000000000000..a4e1f5920bd1 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/multiModuleQuickFix/actualAnnotationsNotMatchExpect/replaceArgsOnExpect/jvm/jvm.kt @@ -0,0 +1,6 @@ +// "Replace arguments of mismatched annotation 'Ann' on expect declaration (may change semantics)" "true" +// DISABLE-ERRORS +// FIR_COMPARISON + +@Ann("different value") +actual fun foo() {}