From 2669193755cb749d4f472de93b64b9a15710796d Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 6 Jun 2018 05:05:25 +0300 Subject: [PATCH] Use "Move to companion" quick fix for CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT So #KT-22871 Fixed --- .../MoveMemberToCompanionObjectIntention.kt | 17 ++++++++++++++++- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 3 +++ .../moveMemberToCompanionObject/simple.kt | 4 ++++ .../simple.kt.after | 6 ++++++ .../QuickFixMultiFileTestGenerated.java | 13 +++++++++++++ .../idea/quickfix/QuickFixTestGenerated.java | 18 ++++++++++++++++++ 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 idea/testData/quickfix/moveMemberToCompanionObject/simple.kt create mode 100644 idea/testData/quickfix/moveMemberToCompanionObject/simple.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveMemberToCompanionObjectIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveMemberToCompanionObjectIntention.kt index 936e6efc09b..9d15714945f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveMemberToCompanionObjectIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveMemberToCompanionObjectIntention.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.codeInsight.CodeInsightUtilCore +import com.intellij.codeInsight.intention.IntentionAction import com.intellij.codeInsight.template.TemplateBuilderImpl import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.TextRange @@ -38,11 +39,13 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.core.* +import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory import org.jetbrains.kotlin.idea.refactoring.checkConflictsInteractively import org.jetbrains.kotlin.idea.refactoring.move.OuterInstanceReferenceUsageInfo import org.jetbrains.kotlin.idea.refactoring.move.collectOuterInstanceReferences @@ -78,7 +81,13 @@ class MoveMemberToCompanionObjectIntention : SelfTargetingRangeIntentionconst val foo = "" +} \ No newline at end of file diff --git a/idea/testData/quickfix/moveMemberToCompanionObject/simple.kt.after b/idea/testData/quickfix/moveMemberToCompanionObject/simple.kt.after new file mode 100644 index 00000000000..5ee1f92ef2e --- /dev/null +++ b/idea/testData/quickfix/moveMemberToCompanionObject/simple.kt.after @@ -0,0 +1,6 @@ +// "Move to companion object" "true" +class Test { + companion object { + const val foo = "" + } +} \ 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 ad831720739..bdd0ed1b393 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -2948,6 +2948,19 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes } } + @TestMetadata("idea/testData/quickfix/moveMemberToCompanionObject") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class MoveMemberToCompanionObject extends AbstractQuickFixMultiFileTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTestWithExtraFile, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInMoveMemberToCompanionObject() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/moveMemberToCompanionObject"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true); + } + } + @TestMetadata("idea/testData/quickfix/moveReceiverAnnotation") @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 794b3fb3a41..40d56e325e1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -7873,6 +7873,24 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } } + @TestMetadata("idea/testData/quickfix/moveMemberToCompanionObject") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class MoveMemberToCompanionObject extends AbstractQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInMoveMemberToCompanionObject() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/moveMemberToCompanionObject"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("idea/testData/quickfix/moveMemberToCompanionObject/simple.kt"); + } + } + @TestMetadata("idea/testData/quickfix/moveReceiverAnnotation") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)