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 59e691fd667..e39a7acb3e8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt @@ -45,6 +45,7 @@ import org.jetbrains.kotlin.idea.refactoring.memberInfo.KtPsiClassWrapper import org.jetbrains.kotlin.idea.refactoring.memberInfo.toKtDeclarationWrapperAware import org.jetbrains.kotlin.idea.refactoring.safeDelete.removeOverrideModifier import org.jetbrains.kotlin.idea.util.anonymousObjectSuperTypeOrNull +import org.jetbrains.kotlin.idea.util.hasComments import org.jetbrains.kotlin.idea.util.psi.patternMatching.KotlinPsiUnifier import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens @@ -503,6 +504,9 @@ class KotlinPullUpHelper( if (member.typeReference == null) { movedMember.typeReference?.addToShorteningWaitSet() } + if (movedMember.nextSibling.hasComments()) { + movedMember.parent.addAfter(psiFactory.createNewLine(), movedMember) + } removeOriginalMemberOrAddOverride(member) } else { diff --git a/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent.kt b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent.kt new file mode 100644 index 00000000000..a74883dacfe --- /dev/null +++ b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent.kt @@ -0,0 +1,10 @@ +open class A + + class B : A() { + // INFO: {"checked": "true"} + fun barw() { + } + + // INFO: {"checked": "true", "toAbstract": "true"} + val foo8: Int = 1 +} \ No newline at end of file diff --git a/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent.kt.after b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent.kt.after new file mode 100644 index 00000000000..e5989823ae7 --- /dev/null +++ b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent.kt.after @@ -0,0 +1,14 @@ +abstract class A { + // INFO: {"checked": "true", "toAbstract": "true"} + abstract val foo8: Int + + // INFO: {"checked": "true"} + fun barw() { + } +} + +class B : A() { + + // INFO: {"checked": "true", "toAbstract": "true"} + override val foo8: Int = 1 +} \ No newline at end of file diff --git a/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent2.kt b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent2.kt new file mode 100644 index 00000000000..8dfc39152a3 --- /dev/null +++ b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent2.kt @@ -0,0 +1,12 @@ +open class A + +class Root { + class B : A() { + // INFO: {"checked": "true"} + fun barw() { + } + + // INFO: {"checked": "true", "toAbstract": "true"} + val foo8: Int = 1 + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent2.kt.after b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent2.kt.after new file mode 100644 index 00000000000..5c6cfca8052 --- /dev/null +++ b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent2.kt.after @@ -0,0 +1,16 @@ +abstract class A { + // INFO: {"checked": "true", "toAbstract": "true"} + abstract val foo8: Int + + // INFO: {"checked": "true"} + fun barw() { + } +} + +class Root { + class B : A() { + + // INFO: {"checked": "true", "toAbstract": "true"} + override val foo8: Int = 1 + } +} \ No newline at end of file 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 dc90b1cf90d..66ac909f197 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/pullUp/PullUpTestGenerated.java @@ -126,6 +126,16 @@ public class PullUpTestGenerated extends AbstractPullUpTest { runTest("idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstract.kt"); } + @TestMetadata("fromClassToClassMakeAbstractWithCommentAndAnotherIndent.kt") + public void testFromClassToClassMakeAbstractWithCommentAndAnotherIndent() throws Exception { + runTest("idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent.kt"); + } + + @TestMetadata("fromClassToClassMakeAbstractWithCommentAndAnotherIndent2.kt") + public void testFromClassToClassMakeAbstractWithCommentAndAnotherIndent2() throws Exception { + runTest("idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstractWithCommentAndAnotherIndent2.kt"); + } + @TestMetadata("fromClassToClassWithGenerics.kt") public void testFromClassToClassWithGenerics() throws Exception { runTest("idea/testData/refactoring/pullUp/k2k/fromClassToClassWithGenerics.kt");