diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/InlineClassDeprecatedFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/InlineClassDeprecatedFix.kt new file mode 100644 index 00000000000..93ba544cceb --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/InlineClassDeprecatedFix.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.quickfix + +import com.intellij.codeInsight.intention.IntentionAction +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.idea.KotlinBundle +import org.jetbrains.kotlin.idea.util.addAnnotation +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.KtModifierListOwner +import org.jetbrains.kotlin.psi.psiUtil.getParentOfType +import org.jetbrains.kotlin.resolve.JVM_INLINE_ANNOTATION_FQ_NAME + +class InlineClassDeprecatedFix( + element: KtModifierListOwner +) : KotlinQuickFixAction(element), CleanupFix { + + private val text = KotlinBundle.message("replace.with.0", "@JvmInline value") + + override fun getText() = text + + override fun getFamilyName() = KotlinBundle.message("replace.modifier") + + override fun invoke(project: Project, editor: Editor?, file: KtFile) { + element?.removeModifier(KtTokens.INLINE_KEYWORD) + element?.addModifier(KtTokens.VALUE_KEYWORD) + element?.addAnnotation(JVM_INLINE_ANNOTATION_FQ_NAME) + } + + companion object : KotlinSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic): IntentionAction? { + val deprecatedModifier = Errors.INLINE_CLASS_DEPRECATED.cast(diagnostic) + val modifierListOwner = deprecatedModifier.psiElement.getParentOfType(strict = true) ?: return null + return if (deprecatedModifier != null) InlineClassDeprecatedFix(modifierListOwner) else null + } + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 8bb02fce77f..7d02be4e728 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -662,6 +662,8 @@ class QuickFixRegistrar : QuickFixContributor { INLINE_CLASS_CONSTRUCTOR_NOT_FINAL_READ_ONLY_PARAMETER.registerFactory(InlineClassConstructorNotValParameterFactory) + INLINE_CLASS_DEPRECATED.registerFactory(InlineClassDeprecatedFix) + SEALED_INHERITOR_IN_DIFFERENT_PACKAGE.registerFactory(MoveToSealedMatchingPackageFix) SEALED_INHERITOR_IN_DIFFERENT_MODULE.registerFactory(MoveToSealedMatchingPackageFix) } diff --git a/idea/testData/quickfix/inlineClass/inlineClassDeprecated.kt b/idea/testData/quickfix/inlineClass/inlineClassDeprecated.kt new file mode 100644 index 00000000000..0a220d37ddd --- /dev/null +++ b/idea/testData/quickfix/inlineClass/inlineClassDeprecated.kt @@ -0,0 +1,4 @@ +// "Replace with '@JvmInline value'" "true" +// WITH_RUNTIME + +inline class IC(val i: Int) \ No newline at end of file diff --git a/idea/testData/quickfix/inlineClass/inlineClassDeprecated.kt.after b/idea/testData/quickfix/inlineClass/inlineClassDeprecated.kt.after new file mode 100644 index 00000000000..aaf9daefc84 --- /dev/null +++ b/idea/testData/quickfix/inlineClass/inlineClassDeprecated.kt.after @@ -0,0 +1,5 @@ +// "Replace with '@JvmInline value'" "true" +// WITH_RUNTIME + +@JvmInline +value class IC(val i: Int) \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index 085c463d4df..9812bb9443d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -3054,6 +3054,19 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes } } + @TestMetadata("idea/testData/quickfix/inlineClass") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class InlineClass extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, this, testDataFilePath); + } + + public void testAllFilesPresentInInlineClass() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/inlineClass"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), null, true); + } + } + @TestMetadata("idea/testData/quickfix/inlineClassConstructorNotValParameter") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 70c4af4e255..9ada12914ea 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -8519,6 +8519,24 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } } + @TestMetadata("idea/testData/quickfix/inlineClass") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class InlineClass extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInInlineClass() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/inlineClass"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true); + } + + @TestMetadata("inlineClassDeprecated.kt") + public void testInlineClassDeprecated() throws Exception { + runTest("idea/testData/quickfix/inlineClass/inlineClassDeprecated.kt"); + } + } + @TestMetadata("idea/testData/quickfix/inlineClassConstructorNotValParameter") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)