[Kotlin] Add quick fix replacing arguments of annotation from expect declaration side

^KTIJ-26633

GitOrigin-RevId: 8324f66558b16549efcc545feb9609db34db3a8e
This commit is contained in:
Roman Efremov
2023-08-23 17:40:25 +00:00
committed by intellij-monorepo-bot
parent a3ae7868b0
commit 75bbbc2f00
8 changed files with 48 additions and 10 deletions
@@ -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
@@ -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)
@@ -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(
@@ -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)
@@ -0,0 +1,5 @@
// DISABLE-ERRORS
annotation class Ann(val value: String)
@Ann("value")
expect fun foo()
@@ -0,0 +1,5 @@
// DISABLE-ERRORS
annotation class Ann(val value: String)
@Ann("different value")
expect fun foo()
@@ -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 }
@@ -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<caret>() {}