From 1c16d2af1a6c0c0718af37878da13ed5ee3bb49e Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Wed, 11 Jan 2017 14:19:43 +0300 Subject: [PATCH] Extract Superclass/Interface/Pull Up: Reformat modifier lists of generated declarations (to add spaces where needed) #KT-15639 Fixed --- ChangeLog.md | 1 + .../idea/refactoring/pullUp/KotlinPullUpHelper.kt | 3 +++ .../extractSuperclass/reformatModifierList.kt | 8 ++++++++ .../extractSuperclass/reformatModifierList.kt.after | 13 +++++++++++++ .../refactoring/pullUp/k2k/reformatModifierList.kt | 8 ++++++++ .../pullUp/k2k/reformatModifierList.kt.after | 11 +++++++++++ .../introduce/ExtractionTestGenerated.java | 6 ++++++ .../refactoring/pullUp/PullUpTestGenerated.java | 6 ++++++ 8 files changed, 56 insertions(+) create mode 100644 idea/testData/refactoring/extractSuperclass/reformatModifierList.kt create mode 100644 idea/testData/refactoring/extractSuperclass/reformatModifierList.kt.after create mode 100644 idea/testData/refactoring/pullUp/k2k/reformatModifierList.kt create mode 100644 idea/testData/refactoring/pullUp/k2k/reformatModifierList.kt.after diff --git a/ChangeLog.md b/ChangeLog.md index 8a1660ce124..01cb355befc 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -480,6 +480,7 @@ These artifacts include extensions for the types available in the latter JDKs, s - [`KT-15643`](https://youtrack.jetbrains.com/issue/KT-15643) Extract Interface/Pull Up: Disable "Make abstract" and assume it to be true for primary constructor parameter when moving to an interface - [`KT-15607`](https://youtrack.jetbrains.com/issue/KT-15607) Extract Interface/Pull Up: Disable internal/protected members when moving to an interface - [`KT-15640`](https://youtrack.jetbrains.com/issue/KT-15640) Extract Interface/Pull Up: Drop 'final' modifier when moving to an interface +- [`KT-15639`](https://youtrack.jetbrains.com/issue/KT-15639) Extract Superclass/Interface/Pull Up: Add spaces between 'abstract' modifier and annotations #### Intention actions, inspections and quickfixes diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt index 0201bfeff74..e87fe3fa3f7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.idea.refactoring.pullUp import com.intellij.psi.* +import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.codeStyle.JavaCodeStyleManager import com.intellij.psi.impl.light.LightField import com.intellij.psi.search.GlobalSearchScope @@ -533,6 +534,8 @@ class KotlinPullUpHelper( else -> return } + movedMember.modifierList?.let { CodeStyleManager.getInstance(member.manager).reformat(it) } + applyMarking(movedMember, data.sourceToTargetClassSubstitutor, data.targetClassDescriptor) addMovedMember(movedMember) } diff --git a/idea/testData/refactoring/extractSuperclass/reformatModifierList.kt b/idea/testData/refactoring/extractSuperclass/reformatModifierList.kt new file mode 100644 index 00000000000..bb6d55e57ee --- /dev/null +++ b/idea/testData/refactoring/extractSuperclass/reformatModifierList.kt @@ -0,0 +1,8 @@ +// NAME: A +annotation class Concat + +// SIBLING: +class Abstraction { + // INFO: {"checked": "true", "toAbstract": "true"} + @Concat var extraction = 0 +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractSuperclass/reformatModifierList.kt.after b/idea/testData/refactoring/extractSuperclass/reformatModifierList.kt.after new file mode 100644 index 00000000000..4a6b9c8efbc --- /dev/null +++ b/idea/testData/refactoring/extractSuperclass/reformatModifierList.kt.after @@ -0,0 +1,13 @@ +// NAME: A +annotation class Concat + +abstract class A { + // INFO: {"checked": "true", "toAbstract": "true"} + @Concat abstract var extraction: Int +} + +// SIBLING: +class Abstraction : A() { + // INFO: {"checked": "true", "toAbstract": "true"} + @Concat override var extraction = 0 +} \ No newline at end of file diff --git a/idea/testData/refactoring/pullUp/k2k/reformatModifierList.kt b/idea/testData/refactoring/pullUp/k2k/reformatModifierList.kt new file mode 100644 index 00000000000..0429fff3071 --- /dev/null +++ b/idea/testData/refactoring/pullUp/k2k/reformatModifierList.kt @@ -0,0 +1,8 @@ +annotation class Concat + +open class A + +class Abstraction : A() { + // INFO: {"checked": "true", "toAbstract": "true"} + @Concat var extraction = 0 +} \ No newline at end of file diff --git a/idea/testData/refactoring/pullUp/k2k/reformatModifierList.kt.after b/idea/testData/refactoring/pullUp/k2k/reformatModifierList.kt.after new file mode 100644 index 00000000000..8b7acea5b13 --- /dev/null +++ b/idea/testData/refactoring/pullUp/k2k/reformatModifierList.kt.after @@ -0,0 +1,11 @@ +annotation class Concat + +abstract class A { + // INFO: {"checked": "true", "toAbstract": "true"} + @Concat abstract var extraction: Int +} + +class Abstraction : A() { + // INFO: {"checked": "true", "toAbstract": "true"} + @Concat override var extraction = 0 +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java index c950363d069..692f78d5f99 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java @@ -4307,6 +4307,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest { doExtractSuperclassTest(fileName); } + @TestMetadata("reformatModifierList.kt") + public void testReformatModifierList() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractSuperclass/reformatModifierList.kt"); + doExtractSuperclassTest(fileName); + } + @TestMetadata("replaceSuperclass.kt") public void testReplaceSuperclass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractSuperclass/replaceSuperclass.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java index 724eec1e245..e180ff09f74 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java @@ -314,6 +314,12 @@ public class PullUpTestGenerated extends AbstractPullUpTest { doKotlinTest(fileName); } + @TestMetadata("reformatModifierList.kt") + public void testReformatModifierList() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/reformatModifierList.kt"); + doKotlinTest(fileName); + } + @TestMetadata("removeVisibilityOnOverride.kt") public void testRemoveVisibilityOnOverride() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/removeVisibilityOnOverride.kt");