From 668473c33799123c60bfb278c318e1dbd248ddde Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 4 Dec 2019 13:08:00 +0900 Subject: [PATCH] Add quickfix for CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT to remove `const` modifier #KT-35215 Fixed --- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 5 ++++- .../testData/quickfix/redundantConst/simple.kt | 4 ++++ .../quickfix/redundantConst/simple.kt.after | 4 ++++ .../QuickFixMultiFileTestGenerated.java | 13 +++++++++++++ .../idea/quickfix/QuickFixTestGenerated.java | 18 ++++++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 idea/testData/quickfix/redundantConst/simple.kt create mode 100644 idea/testData/quickfix/redundantConst/simple.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 0eae3e1e9d5..2c543b40cd6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -599,7 +599,10 @@ class QuickFixRegistrar : QuickFixContributor { TYPE_VARIANCE_CONFLICT.registerFactory(RemoveTypeVarianceFix) - CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT.registerFactory(MoveMemberToCompanionObjectIntention) + CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT.registerFactory( + MoveMemberToCompanionObjectIntention, + RemoveModifierFix.createRemoveModifierFactory() + ) NO_COMPANION_OBJECT.registerFactory(AddIsToWhenConditionFix) diff --git a/idea/testData/quickfix/redundantConst/simple.kt b/idea/testData/quickfix/redundantConst/simple.kt new file mode 100644 index 00000000000..6f0062f940a --- /dev/null +++ b/idea/testData/quickfix/redundantConst/simple.kt @@ -0,0 +1,4 @@ +// "Remove 'const' modifier" "true" +class Foo { + const val s = "s" +} \ No newline at end of file diff --git a/idea/testData/quickfix/redundantConst/simple.kt.after b/idea/testData/quickfix/redundantConst/simple.kt.after new file mode 100644 index 00000000000..695cd29f312 --- /dev/null +++ b/idea/testData/quickfix/redundantConst/simple.kt.after @@ -0,0 +1,4 @@ +// "Remove 'const' modifier" "true" +class Foo { + val s = "s" +} \ 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 fe776afc307..96bb1f1338d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -3712,6 +3712,19 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes } } + @TestMetadata("idea/testData/quickfix/redundantConst") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RedundantConst extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, this, testDataFilePath); + } + + public void testAllFilesPresentInRedundantConst() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/redundantConst"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), null, true); + } + } + @TestMetadata("idea/testData/quickfix/redundantFun") @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 2f0f35d6a3e..1bc5694ae97 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -10667,6 +10667,24 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } } + @TestMetadata("idea/testData/quickfix/redundantConst") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RedundantConst extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInRedundantConst() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/redundantConst"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("idea/testData/quickfix/redundantConst/simple.kt"); + } + } + @TestMetadata("idea/testData/quickfix/redundantFun") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)