From bfd539d5d1ee61142d0eecec7c28b471821f3f11 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Fri, 15 Nov 2019 21:57:37 +0700 Subject: [PATCH] Formatter: fix line break between declarations with comment #KT-12490 Fixed #KT-35088 Fixed --- .../idea/formatter/KotlinSpacingBuilder.kt | 17 +++++++++++++-- .../idea/formatter/kotlinSpacingRules.kt | 19 ++++++++++++++--- .../overrideRespectCaretPosition.kt.after | 1 + .../EmptyLineAfterObjectDeclaration.after.kt | 1 + .../EmptyLineAfterObjectDeclaration.kt | 1 + .../EmptyLineBetweeAbstractFunctions.after.kt | 21 +++++++++++++++++++ .../EmptyLineBetweeAbstractFunctions.kt | 17 +++++++++++++++ ...tyLineBetweeSecondaryConstructors.after.kt | 11 ++++++++++ .../EmptyLineBetweeSecondaryConstructors.kt | 10 +++++++++ .../EmptyLineBetweenClassAndFunction.after.kt | 2 ++ .../EmptyLineBetweenClassAndFunction.kt | 2 ++ .../EmptyLineBetweenClasses.after.kt | 1 + .../formatter/EmptyLineBetweenClasses.kt | 1 + .../EmptyLineBetweenEnumEntries.after.inv.kt | 1 + .../EmptyLineBetweenEnumEntries.after.kt | 1 + .../formatter/EmptyLineBetweenEnumEntries.kt | 1 + .../EmptyLineBetweenFunAndProperty.after.kt | 2 +- .../EmptyLineBetweenFunAndProperty.kt | 1 + .../EmptyLineBetweenFunctions.after.kt | 3 +++ .../formatter/EmptyLineBetweenFunctions.kt | 2 ++ .../EmptyLineBetweenProperties.after.kt | 1 + .../formatter/EmptyLineBetweenProperties.kt | 1 + .../formatter/SpacesInDeclarations.after.kt | 5 ++++- .../formatter/TypeAliasSpacing.after.kt | 2 +- .../createExpect/commented/header/My.kt.after | 1 + .../sealedClass/header/My.kt.after | 2 ++ .../j2k/fromClassToClassWithGenerics.kt.after | 3 +++ .../pullUp/k2k/fromClassToClass.kt.after | 3 +++ .../k2k/fromClassToClassMakeAbstract.kt.after | 3 +++ .../k2k/fromClassToClassWithGenerics.kt.after | 7 +++++++ .../pullUp/k2k/fromClassToInterface.kt.after | 4 ++++ .../fromClassToInterfaceMakeAbstract.kt.after | 3 +++ ...isibilityCheckBetweenMovedMembers.kt.after | 1 + .../k2k/propertyDependenceSatisfied.kt.after | 4 ++++ .../propertyDependenceUnsatisfied.kt.after | 3 +++ .../pullUp/k2k/superToThis.kt.after | 1 + .../pushDown/k2k/pushClassMembers.kt.after | 7 +++++++ .../pushClassMembersAndMakeAbstract.kt.after | 9 ++++++++ .../k2k/pushClassMembersWithGenerics.kt.after | 2 ++ .../k2k/pushInterfaceMembers.kt.after | 6 ++++++ ...shInterfaceMembersAndMakeAbstract.kt.after | 6 ++++++ .../formatter/FormatterTestGenerated.java | 5 +++++ nj2k/testData/newJ2k/comments/comments2.kt | 1 + .../newJ2k/detectProperties/Comments.kt | 1 + .../field/volatileTransientAndStrictFp.kt | 1 + .../nonStaticMembersWithComments.kt | 1 - .../staticAndNonStaticMembersWithComments.kt | 3 +-- .../formatting/staticMembersWithComments.kt | 1 - nj2k/testData/newJ2k/issues/comments.kt | 1 + 49 files changed, 191 insertions(+), 12 deletions(-) create mode 100644 idea/testData/formatter/EmptyLineBetweeSecondaryConstructors.after.kt create mode 100644 idea/testData/formatter/EmptyLineBetweeSecondaryConstructors.kt diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinSpacingBuilder.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinSpacingBuilder.kt index fb527863e39..909a1b31874 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinSpacingBuilder.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinSpacingBuilder.kt @@ -17,7 +17,8 @@ import com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.idea.util.requireNode import org.jetbrains.kotlin.lexer.KtTokens -import java.util.* +import org.jetbrains.kotlin.psi.psiUtil.children +import org.jetbrains.kotlin.psi.stubs.elements.KtModifierListElementType import kotlin.math.max fun CommonCodeStyleSettings.createSpaceBeforeRBrace(numSpacesOtherwise: Int, textRange: TextRange): Spacing? { @@ -103,13 +104,20 @@ class KotlinSpacingBuilder(val commonCodeStyleSettings: CommonCodeStyleSettings, val lastChild = left.node?.psi?.lastChild val leftEndsWithComment = lastChild is PsiComment && lastChild.tokenType == KtTokens.EOL_COMMENT val dependentSpacingRule = DependentSpacingRule(Trigger.HAS_LINE_FEEDS).registerData(Anchor.MIN_LINE_FEEDS, emptyLines + 1) + val textRange = left.node + ?.children() + ?.firstOrNull { it.elementType !in KtTokens.WHITE_SPACE_OR_COMMENT_BIT_SET } + ?.startOffset + ?.let { TextRange.create(it, left.textRange.endOffset) } + ?: left.textRange + spacingBuilderUtil.createLineFeedDependentSpacing( numSpacesOtherwise, numSpacesOtherwise, if (leftEndsWithComment) max(1, numberOfLineFeedsOtherwise) else numberOfLineFeedsOtherwise, commonCodeStyleSettings.KEEP_LINE_BREAKS, commonCodeStyleSettings.KEEP_BLANK_LINES_IN_DECLARATIONS, - left.textRange, + textRange, dependentSpacingRule ) } @@ -200,3 +208,8 @@ fun rules( builder.init() return builder } + +internal fun ASTNode.startOfDeclaration(): ASTNode? = children().firstOrNull { + val elementType = it.elementType + elementType !is KtModifierListElementType<*> && elementType !in KtTokens.WHITE_SPACE_OR_COMMENT_BIT_SET +} diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt index cd2b967a830..88e0f1ebf5e 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt @@ -12,6 +12,7 @@ import com.intellij.formatting.SpacingBuilder import com.intellij.formatting.SpacingBuilder.RuleBuilder import com.intellij.lang.ASTNode import com.intellij.openapi.util.TextRange +import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiComment import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.codeStyle.CodeStyleSettings @@ -32,6 +33,8 @@ val MODIFIERS_LIST_ENTRIES = TokenSet.orSet(TokenSet.create(ANNOTATION_ENTRY, AN val EXTEND_COLON_ELEMENTS = TokenSet.create(TYPE_CONSTRAINT, CLASS, OBJECT_DECLARATION, TYPE_PARAMETER, ENUM_ENTRY, SECONDARY_CONSTRUCTOR) +val DECLARATIONS = TokenSet.create(PROPERTY, FUN, CLASS, OBJECT_DECLARATION, ENUM_ENTRY, SECONDARY_CONSTRUCTOR, CLASS_INITIALIZER) + fun SpacingBuilder.beforeInside(element: IElementType, tokenSet: TokenSet, spacingFun: RuleBuilder.() -> Unit) { tokenSet.types.forEach { inType -> beforeInside(element, inType).spacingFun() } } @@ -47,9 +50,6 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing val kotlinCommonSettings = settings.kotlinCommonSettings val kotlinCustomSettings = settings.kotlinCustomSettings return rules(kotlinCommonSettings, builderUtil) { - val DECLARATIONS = - TokenSet.create(PROPERTY, FUN, CLASS, OBJECT_DECLARATION, ENUM_ENTRY, SECONDARY_CONSTRUCTOR, CLASS_INITIALIZER) - simple { before(FILE_ANNOTATION_LIST).lineBreakInCode() after(FILE_ANNOTATION_LIST).blankLines(1) @@ -87,8 +87,21 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing null } } + inPosition(right = BLOCK_COMMENT).spacing(commentSpacing(0)) inPosition(right = EOL_COMMENT).spacing(commentSpacing(1)) + inPosition(leftSet = DECLARATIONS, rightSet = DECLARATIONS).customRule(fun( + _: ASTBlock, + _: ASTBlock, + right: ASTBlock + ): Spacing? { + val firstChild = right.node?.firstChildNode as? PsiComment ?: return null + val whiteSpace = firstChild.nextSibling as? PsiWhiteSpace ?: return null + return if (StringUtil.containsLineBreak(firstChild.text) || StringUtil.containsLineBreak(whiteSpace.text)) { + createSpacing(0, minLineFeeds = 2) + } else + null + }) inPosition(left = CLASS, right = CLASS).emptyLinesIfLineBreakInLeft(1) inPosition(left = CLASS, right = OBJECT_DECLARATION).emptyLinesIfLineBreakInLeft(1) diff --git a/idea/testData/codeInsight/overrideImplement/overrideRespectCaretPosition.kt.after b/idea/testData/codeInsight/overrideImplement/overrideRespectCaretPosition.kt.after index 62d5cbf3cd7..bed129bd1b7 100644 --- a/idea/testData/codeInsight/overrideImplement/overrideRespectCaretPosition.kt.after +++ b/idea/testData/codeInsight/overrideImplement/overrideRespectCaretPosition.kt.after @@ -5,6 +5,7 @@ open class A() { class C : A() { val constant = 42 + // Some comment override val bar: Int get() = super.bar diff --git a/idea/testData/formatter/EmptyLineAfterObjectDeclaration.after.kt b/idea/testData/formatter/EmptyLineAfterObjectDeclaration.after.kt index ec106066a96..9e5e006826d 100644 --- a/idea/testData/formatter/EmptyLineAfterObjectDeclaration.after.kt +++ b/idea/testData/formatter/EmptyLineAfterObjectDeclaration.after.kt @@ -33,6 +33,7 @@ class C1M // ----- +// test object O6 interface T1 diff --git a/idea/testData/formatter/EmptyLineAfterObjectDeclaration.kt b/idea/testData/formatter/EmptyLineAfterObjectDeclaration.kt index 57af260ab95..837fd0bfb59 100644 --- a/idea/testData/formatter/EmptyLineAfterObjectDeclaration.kt +++ b/idea/testData/formatter/EmptyLineAfterObjectDeclaration.kt @@ -29,6 +29,7 @@ class C1M // ----- +// test object O6 interface T1 diff --git a/idea/testData/formatter/EmptyLineBetweeAbstractFunctions.after.kt b/idea/testData/formatter/EmptyLineBetweeAbstractFunctions.after.kt index 170addc5e64..f7910d02873 100644 --- a/idea/testData/formatter/EmptyLineBetweeAbstractFunctions.after.kt +++ b/idea/testData/formatter/EmptyLineBetweeAbstractFunctions.after.kt @@ -1,9 +1,30 @@ interface Some { fun f1() fun f2() + fun f3() + + /* test */ + fun f4() + /* test */ fun f5() + + /** + * test + * 2 + */ + fun f6() + fun f7() } abstract class Abstract() { abstract fun f1() abstract fun f2() + + // test + abstract fun f3() + + // test + /* test */ abstract fun f4() + abstract fun f5() + abstract fun f6() + /* test */ abstract fun f7() } \ No newline at end of file diff --git a/idea/testData/formatter/EmptyLineBetweeAbstractFunctions.kt b/idea/testData/formatter/EmptyLineBetweeAbstractFunctions.kt index 170addc5e64..6a8de4790b4 100644 --- a/idea/testData/formatter/EmptyLineBetweeAbstractFunctions.kt +++ b/idea/testData/formatter/EmptyLineBetweeAbstractFunctions.kt @@ -1,9 +1,26 @@ interface Some { fun f1() fun f2() + fun f3() + /* test */ + fun f4() + /* test */ fun f5() + /** + * test + * 2 + */ + fun f6() + fun f7() } abstract class Abstract() { abstract fun f1() abstract fun f2() + // test + abstract fun f3() + // test + /* test */ abstract fun f4() + abstract fun f5() + abstract fun f6() + /* test */ abstract fun f7() } \ No newline at end of file diff --git a/idea/testData/formatter/EmptyLineBetweeSecondaryConstructors.after.kt b/idea/testData/formatter/EmptyLineBetweeSecondaryConstructors.after.kt new file mode 100644 index 00000000000..aea8c5b3dbd --- /dev/null +++ b/idea/testData/formatter/EmptyLineBetweeSecondaryConstructors.after.kt @@ -0,0 +1,11 @@ +class Some(b: Boolean) { + // Comment. + constructor(b: Int) : this(b == 0) + + /** + * test + * 2 + */ + constructor(b: String) : this(b.isEmpty()) + constructor(b: Long) : this(b == 0L) +} \ No newline at end of file diff --git a/idea/testData/formatter/EmptyLineBetweeSecondaryConstructors.kt b/idea/testData/formatter/EmptyLineBetweeSecondaryConstructors.kt new file mode 100644 index 00000000000..be2f0cd1de6 --- /dev/null +++ b/idea/testData/formatter/EmptyLineBetweeSecondaryConstructors.kt @@ -0,0 +1,10 @@ +class Some(b: Boolean) { + // Comment. + constructor(b: Int) : this(b == 0) + /** + * test + * 2 + */ + constructor(b: String) : this(b.isEmpty()) + constructor(b: Long) : this(b == 0L) +} \ No newline at end of file diff --git a/idea/testData/formatter/EmptyLineBetweenClassAndFunction.after.kt b/idea/testData/formatter/EmptyLineBetweenClassAndFunction.after.kt index 47c274a5e7b..dfee6084d55 100644 --- a/idea/testData/formatter/EmptyLineBetweenClassAndFunction.after.kt +++ b/idea/testData/formatter/EmptyLineBetweenClassAndFunction.after.kt @@ -8,11 +8,13 @@ class C2 // ----- +// test fun f3 = 1 class C3 {} // ----- +/*test*/ fun f4 = 2 class C4 diff --git a/idea/testData/formatter/EmptyLineBetweenClassAndFunction.kt b/idea/testData/formatter/EmptyLineBetweenClassAndFunction.kt index 08c70b44c91..7bef8ec92bd 100644 --- a/idea/testData/formatter/EmptyLineBetweenClassAndFunction.kt +++ b/idea/testData/formatter/EmptyLineBetweenClassAndFunction.kt @@ -8,11 +8,13 @@ class C2 // ----- +// test fun f3 = 1 class C3 {} // ----- +/*test*/ fun f4 = 2 class C4 diff --git a/idea/testData/formatter/EmptyLineBetweenClasses.after.kt b/idea/testData/formatter/EmptyLineBetweenClasses.after.kt index f2f618cbd23..1ccf19670cb 100644 --- a/idea/testData/formatter/EmptyLineBetweenClasses.after.kt +++ b/idea/testData/formatter/EmptyLineBetweenClasses.after.kt @@ -13,6 +13,7 @@ class E class F +// test fun some() = 1 class G diff --git a/idea/testData/formatter/EmptyLineBetweenClasses.kt b/idea/testData/formatter/EmptyLineBetweenClasses.kt index a6b4c6ded49..ffb420aa04d 100644 --- a/idea/testData/formatter/EmptyLineBetweenClasses.kt +++ b/idea/testData/formatter/EmptyLineBetweenClasses.kt @@ -10,6 +10,7 @@ class E : Some class F +// test fun some() = 1 class G fun some() = 1 diff --git a/idea/testData/formatter/EmptyLineBetweenEnumEntries.after.inv.kt b/idea/testData/formatter/EmptyLineBetweenEnumEntries.after.inv.kt index 7ed92e1ba43..bccd3d5d8af 100644 --- a/idea/testData/formatter/EmptyLineBetweenEnumEntries.after.inv.kt +++ b/idea/testData/formatter/EmptyLineBetweenEnumEntries.after.inv.kt @@ -26,6 +26,7 @@ enum class E7 { } enum class E8 { + // test A, // A B // B } diff --git a/idea/testData/formatter/EmptyLineBetweenEnumEntries.after.kt b/idea/testData/formatter/EmptyLineBetweenEnumEntries.after.kt index c9fddb07c50..8bb5a518799 100644 --- a/idea/testData/formatter/EmptyLineBetweenEnumEntries.after.kt +++ b/idea/testData/formatter/EmptyLineBetweenEnumEntries.after.kt @@ -28,6 +28,7 @@ enum class E7 { } enum class E8 { + // test A, // A B // B } diff --git a/idea/testData/formatter/EmptyLineBetweenEnumEntries.kt b/idea/testData/formatter/EmptyLineBetweenEnumEntries.kt index 668c690bf65..01a4ffdf55c 100644 --- a/idea/testData/formatter/EmptyLineBetweenEnumEntries.kt +++ b/idea/testData/formatter/EmptyLineBetweenEnumEntries.kt @@ -25,6 +25,7 @@ enum class E7 { } enum class E8 { + // test A, // A B // B } diff --git a/idea/testData/formatter/EmptyLineBetweenFunAndProperty.after.kt b/idea/testData/formatter/EmptyLineBetweenFunAndProperty.after.kt index d886cf0cef5..e4590a00b58 100644 --- a/idea/testData/formatter/EmptyLineBetweenFunAndProperty.after.kt +++ b/idea/testData/formatter/EmptyLineBetweenFunAndProperty.after.kt @@ -1,9 +1,9 @@ // No lines fun f1() {} - val p1 = 1 fun f2() {} +// test fun f3() = 1 val p2 = 1 fun f4() = 1 diff --git a/idea/testData/formatter/EmptyLineBetweenFunAndProperty.kt b/idea/testData/formatter/EmptyLineBetweenFunAndProperty.kt index adb19ece3f0..6337f7fbe76 100644 --- a/idea/testData/formatter/EmptyLineBetweenFunAndProperty.kt +++ b/idea/testData/formatter/EmptyLineBetweenFunAndProperty.kt @@ -3,6 +3,7 @@ fun f1() {} val p1 = 1 fun f2() {} +// test fun f3() = 1 val p2 = 1 fun f4() = 1 diff --git a/idea/testData/formatter/EmptyLineBetweenFunctions.after.kt b/idea/testData/formatter/EmptyLineBetweenFunctions.after.kt index 0ec7f7c4380..c5cef5c5259 100644 --- a/idea/testData/formatter/EmptyLineBetweenFunctions.after.kt +++ b/idea/testData/formatter/EmptyLineBetweenFunctions.after.kt @@ -27,6 +27,9 @@ fun f6() = 1 fun f7() = 8 +// test +fun f8() = 42 + // Two lines between fun l1() {} diff --git a/idea/testData/formatter/EmptyLineBetweenFunctions.kt b/idea/testData/formatter/EmptyLineBetweenFunctions.kt index 5eefbc3028e..1b4961b65fe 100644 --- a/idea/testData/formatter/EmptyLineBetweenFunctions.kt +++ b/idea/testData/formatter/EmptyLineBetweenFunctions.kt @@ -25,6 +25,8 @@ fun f5() { fun f6() = 1 fun f7() = 8 +// test +fun f8() = 42 // Two lines between fun l1() {} diff --git a/idea/testData/formatter/EmptyLineBetweenProperties.after.kt b/idea/testData/formatter/EmptyLineBetweenProperties.after.kt index d19b714d537..d43bf7503d0 100644 --- a/idea/testData/formatter/EmptyLineBetweenProperties.after.kt +++ b/idea/testData/formatter/EmptyLineBetweenProperties.after.kt @@ -1,3 +1,4 @@ +// test val p1 by Some val p2 = 1 val p3: Int get() = 3 diff --git a/idea/testData/formatter/EmptyLineBetweenProperties.kt b/idea/testData/formatter/EmptyLineBetweenProperties.kt index 64a4087f71a..6cdaedb3e39 100644 --- a/idea/testData/formatter/EmptyLineBetweenProperties.kt +++ b/idea/testData/formatter/EmptyLineBetweenProperties.kt @@ -1,3 +1,4 @@ +// test val p1 by Some val p2 = 1 val p3: Int get() = 3 diff --git a/idea/testData/formatter/SpacesInDeclarations.after.kt b/idea/testData/formatter/SpacesInDeclarations.after.kt index 23a783fdda4..d519f5af61d 100644 --- a/idea/testData/formatter/SpacesInDeclarations.after.kt +++ b/idea/testData/formatter/SpacesInDeclarations.after.kt @@ -24,22 +24,26 @@ fun Int.extFun2() { val fooVal1 = 1 val fooVal2 = 1 + //----------------------- var fooVar1 = 1 var fooVar2 = 2 + //----------------------- private val Int.extVal1 = 122 private val Int.extVal: Int = 1 + //----------------------- public var Int.extVar1: Int = 122 public var Int.extVar: Int = 1 + //----------------------- public var varWithAccessors1: Int get() { @@ -64,7 +68,6 @@ val //----------------------- annotation class A1 - annotation class A2 private @[A1 A2 A1] diff --git a/idea/testData/formatter/TypeAliasSpacing.after.kt b/idea/testData/formatter/TypeAliasSpacing.after.kt index c2307e0ace9..8dd0aa321e8 100644 --- a/idea/testData/formatter/TypeAliasSpacing.after.kt +++ b/idea/testData/formatter/TypeAliasSpacing.after.kt @@ -2,7 +2,6 @@ typealias A = Int typealias B = Int // typealias C = Int - typealias D = Int @@ -23,6 +22,7 @@ object O typealias I = Int fun foo() {} + // fun foo() {} typealias J = Int diff --git a/idea/testData/multiModuleQuickFix/createExpect/commented/header/My.kt.after b/idea/testData/multiModuleQuickFix/createExpect/commented/header/My.kt.after index c4c3a4b8c7b..a7ab764416e 100644 --- a/idea/testData/multiModuleQuickFix/createExpect/commented/header/My.kt.after +++ b/idea/testData/multiModuleQuickFix/createExpect/commented/header/My.kt.after @@ -6,6 +6,7 @@ expect class My { fun foo(param: String): Int fun String.bar(y: Double): Boolean + /** * Dokka comment: Just does nothing */ diff --git a/idea/testData/multiModuleQuickFix/createExpect/sealedClass/header/My.kt.after b/idea/testData/multiModuleQuickFix/createExpect/sealedClass/header/My.kt.after index ec216854e37..ea01d994a27 100644 --- a/idea/testData/multiModuleQuickFix/createExpect/sealedClass/header/My.kt.after +++ b/idea/testData/multiModuleQuickFix/createExpect/sealedClass/header/My.kt.after @@ -7,9 +7,11 @@ expect sealed class My(x: Double) { object First : My { override val num: Int } + class Some(num: Int) : My { override val num: Int } + object Best : My { override val num: Int override fun isGood(): Boolean diff --git a/idea/testData/refactoring/pullUp/j2k/fromClassToClassWithGenerics.kt.after b/idea/testData/refactoring/pullUp/j2k/fromClassToClassWithGenerics.kt.after index 3e6dbdcab17..2328960c337 100644 --- a/idea/testData/refactoring/pullUp/j2k/fromClassToClassWithGenerics.kt.after +++ b/idea/testData/refactoring/pullUp/j2k/fromClassToClassWithGenerics.kt.after @@ -5,10 +5,13 @@ interface Z open class A { // INFO: {"checked": "true"} var foo1: T + // INFO: {"checked": "true"} var foo2: Z + // INFO: {"checked": "true"} var foo3: Any + // INFO: {"checked": "true"} var foo4: Z diff --git a/idea/testData/refactoring/pullUp/k2k/fromClassToClass.kt.after b/idea/testData/refactoring/pullUp/k2k/fromClassToClass.kt.after index 25eaa7b6c7a..6c152e80a72 100644 --- a/idea/testData/refactoring/pullUp/k2k/fromClassToClass.kt.after +++ b/idea/testData/refactoring/pullUp/k2k/fromClassToClass.kt.after @@ -2,10 +2,13 @@ abstract class A { // INFO: {"checked": "true"} val x = 1 + // INFO: {"checked": "true"} val y: Int get() = 2 + // INFO: {"checked": "true"} val z: Int by lazy { 3 } + // INFO: {"checked": "true"} abstract val t: Int diff --git a/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstract.kt.after b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstract.kt.after index 00a2fd23ffc..e0b3cb506a7 100644 --- a/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstract.kt.after +++ b/idea/testData/refactoring/pullUp/k2k/fromClassToClassMakeAbstract.kt.after @@ -2,10 +2,13 @@ abstract class A { // INFO: {"checked": "true", "toAbstract": "true"} abstract val x: Int + // INFO: {"checked": "true", "toAbstract": "true"} abstract val y: Int + // INFO: {"checked": "true", "toAbstract": "true"} abstract val z: Int + // INFO: {"checked": "true", "toAbstract": "true"} abstract val t: Int diff --git a/idea/testData/refactoring/pullUp/k2k/fromClassToClassWithGenerics.kt.after b/idea/testData/refactoring/pullUp/k2k/fromClassToClassWithGenerics.kt.after index ac2efb4d6cb..ebba3d5bb5d 100644 --- a/idea/testData/refactoring/pullUp/k2k/fromClassToClassWithGenerics.kt.after +++ b/idea/testData/refactoring/pullUp/k2k/fromClassToClassWithGenerics.kt.after @@ -6,18 +6,25 @@ interface Z abstract class A(x: T, y: Any?) { // INFO: {"checked": "true"} val foo1: T + // INFO: {"checked": "true"} val foo2: Z + // INFO: {"checked": "true"} val foo3: Any? + // INFO: {"checked": "true"} val foo4: Z + // INFO: {"checked": "true", "toAbstract": "true"} abstract val foo5: T + // INFO: {"checked": "true", "toAbstract": "true"} abstract val foo6: Z + // INFO: {"checked": "true", "toAbstract": "true"} abstract val foo7: Any? + // INFO: {"checked": "true", "toAbstract": "true"} abstract val foo8: Z diff --git a/idea/testData/refactoring/pullUp/k2k/fromClassToInterface.kt.after b/idea/testData/refactoring/pullUp/k2k/fromClassToInterface.kt.after index 2ed2f473555..a3a9ec68268 100644 --- a/idea/testData/refactoring/pullUp/k2k/fromClassToInterface.kt.after +++ b/idea/testData/refactoring/pullUp/k2k/fromClassToInterface.kt.after @@ -2,10 +2,13 @@ interface T { // INFO: {"checked": "true"} val x: Int + // INFO: {"checked": "true"} val y: Int get() = 2 + // INFO: {"checked": "true"} val z: Int + // INFO: {"checked": "true"} val t: Int @@ -38,6 +41,7 @@ abstract class B: T { // INFO: {"checked": "true"} override val x = 1 + // INFO: {"checked": "true"} override val z: Int by lazy { 3 } diff --git a/idea/testData/refactoring/pullUp/k2k/fromClassToInterfaceMakeAbstract.kt.after b/idea/testData/refactoring/pullUp/k2k/fromClassToInterfaceMakeAbstract.kt.after index 637276934f0..a20cc2f25c2 100644 --- a/idea/testData/refactoring/pullUp/k2k/fromClassToInterfaceMakeAbstract.kt.after +++ b/idea/testData/refactoring/pullUp/k2k/fromClassToInterfaceMakeAbstract.kt.after @@ -2,10 +2,13 @@ interface T { // INFO: {"checked": "true", "toAbstract": "true"} val x: Int + // INFO: {"checked": "true", "toAbstract": "true"} val y: Int + // INFO: {"checked": "true", "toAbstract": "true"} val z: Int + // INFO: {"checked": "true", "toAbstract": "true"} val t: Int diff --git a/idea/testData/refactoring/pullUp/k2k/noVisibilityCheckBetweenMovedMembers.kt.after b/idea/testData/refactoring/pullUp/k2k/noVisibilityCheckBetweenMovedMembers.kt.after index 831fe4b01a7..d4f389d2498 100644 --- a/idea/testData/refactoring/pullUp/k2k/noVisibilityCheckBetweenMovedMembers.kt.after +++ b/idea/testData/refactoring/pullUp/k2k/noVisibilityCheckBetweenMovedMembers.kt.after @@ -1,6 +1,7 @@ open class Temp1 { // INFO: {"checked": "true"} private val used: Int = 1 + // INFO: {"checked": "true"} private val using: Int = used + 1 } diff --git a/idea/testData/refactoring/pullUp/k2k/propertyDependenceSatisfied.kt.after b/idea/testData/refactoring/pullUp/k2k/propertyDependenceSatisfied.kt.after index 8f23872e280..41d627d5f26 100644 --- a/idea/testData/refactoring/pullUp/k2k/propertyDependenceSatisfied.kt.after +++ b/idea/testData/refactoring/pullUp/k2k/propertyDependenceSatisfied.kt.after @@ -1,12 +1,16 @@ open class A(p: Int) { // INFO: {"checked": "true"} val n: Int + // INFO: {"checked": "true"} val x: Int = 3 + // INFO: {"checked": "true"} val y: Int = 4 + // INFO: {"checked": "true"} val a: Int = 1 + // INFO: {"checked": "true"} val b: Int = x + y diff --git a/idea/testData/refactoring/pullUp/k2k/propertyDependenceUnsatisfied.kt.after b/idea/testData/refactoring/pullUp/k2k/propertyDependenceUnsatisfied.kt.after index eb31bc94b4a..4a86b8bea09 100644 --- a/idea/testData/refactoring/pullUp/k2k/propertyDependenceUnsatisfied.kt.after +++ b/idea/testData/refactoring/pullUp/k2k/propertyDependenceUnsatisfied.kt.after @@ -1,10 +1,13 @@ open class A { // INFO: {"checked": "true"} val n: Int + // INFO: {"checked": "true"} val x: Int = 3 + // INFO: {"checked": "true"} val a: Int = 1 + // INFO: {"checked": "true"} val b: Int = x + y } diff --git a/idea/testData/refactoring/pullUp/k2k/superToThis.kt.after b/idea/testData/refactoring/pullUp/k2k/superToThis.kt.after index 97d2b191c5b..d3db7065021 100644 --- a/idea/testData/refactoring/pullUp/k2k/superToThis.kt.after +++ b/idea/testData/refactoring/pullUp/k2k/superToThis.kt.after @@ -1,5 +1,6 @@ open class A { open fun bar() = 1 + // INFO: {"checked": "true"} fun foo() = bar() } diff --git a/idea/testData/refactoring/pushDown/k2k/pushClassMembers.kt.after b/idea/testData/refactoring/pushDown/k2k/pushClassMembers.kt.after index 3a955187e9c..a92f2b57301 100644 --- a/idea/testData/refactoring/pushDown/k2k/pushClassMembers.kt.after +++ b/idea/testData/refactoring/pushDown/k2k/pushClassMembers.kt.after @@ -5,10 +5,13 @@ abstract class A { abstract class B : A() { // INFO: {"checked": "true"} val x = 1 + // INFO: {"checked": "true"} val y: Int get() = 2 + // INFO: {"checked": "true"} val z: Int by lazy { 3 } + // INFO: {"checked": "true"} abstract val t: Int @@ -32,14 +35,18 @@ abstract class B : A() { class C : A() { val t = 1 + // INFO: {"checked": "true"} val x = 1 + // INFO: {"checked": "true"} val y: Int get() = 2 + // INFO: {"checked": "true"} val z: Int by lazy { 3 } fun bar(s: String) = s.length() + // INFO: {"checked": "true"} fun foo(n: Int): Boolean = n > 0 diff --git a/idea/testData/refactoring/pushDown/k2k/pushClassMembersAndMakeAbstract.kt.after b/idea/testData/refactoring/pushDown/k2k/pushClassMembersAndMakeAbstract.kt.after index 3160e0b041d..165af5f0d80 100644 --- a/idea/testData/refactoring/pushDown/k2k/pushClassMembersAndMakeAbstract.kt.after +++ b/idea/testData/refactoring/pushDown/k2k/pushClassMembersAndMakeAbstract.kt.after @@ -1,8 +1,10 @@ abstract class A { // INFO: {"checked": "true", "toAbstract": "true"} abstract val x: Int + // INFO: {"checked": "true", "toAbstract": "true"} abstract val y: Int + // INFO: {"checked": "true", "toAbstract": "true"} abstract val z: Int @@ -14,10 +16,13 @@ abstract class A { abstract class B : A() { // INFO: {"checked": "true", "toAbstract": "true"} override val x = 1 + // INFO: {"checked": "true", "toAbstract": "true"} override val y: Int get() = 2 + // INFO: {"checked": "true", "toAbstract": "true"} override val z: Int by lazy { 3 } + // INFO: {"checked": "true", "toAbstract": "true"} abstract val t: Int @@ -41,14 +46,18 @@ abstract class B : A() { class C : A() { val t = 1 + // INFO: {"checked": "true", "toAbstract": "true"} override val x = 1 + // INFO: {"checked": "true", "toAbstract": "true"} override val y: Int get() = 2 + // INFO: {"checked": "true", "toAbstract": "true"} override val z: Int by lazy { 3 } fun bar(s: String) = s.length() + // INFO: {"checked": "true", "toAbstract": "true"} override fun foo(n: Int): Boolean = n > 0 diff --git a/idea/testData/refactoring/pushDown/k2k/pushClassMembersWithGenerics.kt.after b/idea/testData/refactoring/pushDown/k2k/pushClassMembersWithGenerics.kt.after index db2466372b1..45d1c6e03b8 100644 --- a/idea/testData/refactoring/pushDown/k2k/pushClassMembersWithGenerics.kt.after +++ b/idea/testData/refactoring/pushDown/k2k/pushClassMembersWithGenerics.kt.after @@ -7,6 +7,7 @@ open class A { class B : A>() { // INFO: {"checked": "true"} val t1: Z + // INFO: {"checked": "true"} val t2: Z> @@ -28,6 +29,7 @@ class B : A>() { class C : A>() { // INFO: {"checked": "true"} val t1: B + // INFO: {"checked": "true"} val t2: Z> diff --git a/idea/testData/refactoring/pushDown/k2k/pushInterfaceMembers.kt.after b/idea/testData/refactoring/pushDown/k2k/pushInterfaceMembers.kt.after index 57b34ac24d0..7841c1c8c96 100644 --- a/idea/testData/refactoring/pushDown/k2k/pushInterfaceMembers.kt.after +++ b/idea/testData/refactoring/pushDown/k2k/pushInterfaceMembers.kt.after @@ -5,6 +5,7 @@ interface I { abstract class A : I { // INFO: {"checked": "true"} val x: Int get() = 2 + // INFO: {"checked": "true"} abstract val y: Int @@ -22,10 +23,12 @@ abstract class A : I { class B : I { val y = 1 + // INFO: {"checked": "true"} val x: Int get() = 2 fun bar(s: String) = s.length() + // INFO: {"checked": "true"} fun foo(n: Int): Boolean = n > 0 @@ -38,6 +41,7 @@ class B : I { interface J : I { // INFO: {"checked": "true"} val x: Int get() = 2 + // INFO: {"checked": "true"} val y: Int @@ -55,10 +59,12 @@ interface J : I { interface K : I { val y: Int get() = 1 + // INFO: {"checked": "true"} val x: Int get() = 2 fun bar(s: String) = s.length() + // INFO: {"checked": "true"} fun foo(n: Int): Boolean = n > 0 diff --git a/idea/testData/refactoring/pushDown/k2k/pushInterfaceMembersAndMakeAbstract.kt.after b/idea/testData/refactoring/pushDown/k2k/pushInterfaceMembersAndMakeAbstract.kt.after index 2b062a3b600..8d3360f1b09 100644 --- a/idea/testData/refactoring/pushDown/k2k/pushInterfaceMembersAndMakeAbstract.kt.after +++ b/idea/testData/refactoring/pushDown/k2k/pushInterfaceMembersAndMakeAbstract.kt.after @@ -10,6 +10,7 @@ interface I { abstract class A : I { // INFO: {"checked": "true", "toAbstract": "true"} override val x: Int get() = 2 + // INFO: {"checked": "true", "toAbstract": "true"} abstract val y: Int @@ -27,10 +28,12 @@ abstract class A : I { class B : I { val y = 1 + // INFO: {"checked": "true", "toAbstract": "true"} override val x: Int get() = 2 fun bar(s: String) = s.length() + // INFO: {"checked": "true", "toAbstract": "true"} override fun foo(n: Int): Boolean = n > 0 @@ -43,6 +46,7 @@ class B : I { interface J : I { // INFO: {"checked": "true", "toAbstract": "true"} override val x: Int get() = 2 + // INFO: {"checked": "true", "toAbstract": "true"} val y: Int @@ -60,10 +64,12 @@ interface J : I { interface K : I { val y: Int get() = 1 + // INFO: {"checked": "true", "toAbstract": "true"} override val x: Int get() = 2 fun bar(s: String) = s.length() + // INFO: {"checked": "true", "toAbstract": "true"} override fun foo(n: Int): Boolean = n > 0 diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index f8a91551037..1970e45cede 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -270,6 +270,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest { runTest("idea/testData/formatter/EmptyLineBetweeAbstractFunctions.after.kt"); } + @TestMetadata("EmptyLineBetweeSecondaryConstructors.after.kt") + public void testEmptyLineBetweeSecondaryConstructors() throws Exception { + runTest("idea/testData/formatter/EmptyLineBetweeSecondaryConstructors.after.kt"); + } + @TestMetadata("EmptyLineBetweenClassAndFunction.after.kt") public void testEmptyLineBetweenClassAndFunction() throws Exception { runTest("idea/testData/formatter/EmptyLineBetweenClassAndFunction.after.kt"); diff --git a/nj2k/testData/newJ2k/comments/comments2.kt b/nj2k/testData/newJ2k/comments/comments2.kt index a596c4e82fb..f77b6789d11 100644 --- a/nj2k/testData/newJ2k/comments/comments2.kt +++ b/nj2k/testData/newJ2k/comments/comments2.kt @@ -14,6 +14,7 @@ internal class A { private /*it's private*/ val field = 0 /*it's public*/ fun foo(s: String?): Char {} protected /*it's protected*/ fun foo(c: Char) {} + /** * Method description. * Multi-line method description. diff --git a/nj2k/testData/newJ2k/detectProperties/Comments.kt b/nj2k/testData/newJ2k/detectProperties/Comments.kt index baf5a932e4c..391e2f649fa 100644 --- a/nj2k/testData/newJ2k/detectProperties/Comments.kt +++ b/nj2k/testData/newJ2k/detectProperties/Comments.kt @@ -8,6 +8,7 @@ internal class A(// comment for field2 setter // Comment for field1 getter // Comment for field1 var field1 = 0 + // comment for field3 setter // comment for field3 getter // comment before field3 diff --git a/nj2k/testData/newJ2k/field/volatileTransientAndStrictFp.kt b/nj2k/testData/newJ2k/field/volatileTransientAndStrictFp.kt index 1b93d6de871..13d33ac05bb 100644 --- a/nj2k/testData/newJ2k/field/volatileTransientAndStrictFp.kt +++ b/nj2k/testData/newJ2k/field/volatileTransientAndStrictFp.kt @@ -5,6 +5,7 @@ internal class A { var field1 = 0 @Transient var field2 = 1 + // Should work even for bad modifiers @Strictfp var field3 = 2.0 diff --git a/nj2k/testData/newJ2k/formatting/nonStaticMembersWithComments.kt b/nj2k/testData/newJ2k/formatting/nonStaticMembersWithComments.kt index ebdaa650e98..36e1376442b 100644 --- a/nj2k/testData/newJ2k/formatting/nonStaticMembersWithComments.kt +++ b/nj2k/testData/newJ2k/formatting/nonStaticMembersWithComments.kt @@ -6,7 +6,6 @@ internal class F { //c3 //c4 fun f2() {} - var i = 0 fun f3() {} //c5 } \ No newline at end of file diff --git a/nj2k/testData/newJ2k/formatting/staticAndNonStaticMembersWithComments.kt b/nj2k/testData/newJ2k/formatting/staticAndNonStaticMembersWithComments.kt index c973fc780e5..ac57dafa1ac 100644 --- a/nj2k/testData/newJ2k/formatting/staticAndNonStaticMembersWithComments.kt +++ b/nj2k/testData/newJ2k/formatting/staticAndNonStaticMembersWithComments.kt @@ -2,7 +2,6 @@ internal class F { //c3 //c4 fun f2() {} - fun f3() {} fun f4() {} @@ -10,8 +9,8 @@ internal class F { //c1 /*c2*/ fun f1() {} - var i = 0 + //c5 fun f5() {} //c6 } diff --git a/nj2k/testData/newJ2k/formatting/staticMembersWithComments.kt b/nj2k/testData/newJ2k/formatting/staticMembersWithComments.kt index 52bd7a387bd..c3d8e836c06 100644 --- a/nj2k/testData/newJ2k/formatting/staticMembersWithComments.kt +++ b/nj2k/testData/newJ2k/formatting/staticMembersWithComments.kt @@ -6,7 +6,6 @@ internal object F { //c3 //c4 fun f2() {} - var i = 0 fun f3() {} //c5 } \ No newline at end of file diff --git a/nj2k/testData/newJ2k/issues/comments.kt b/nj2k/testData/newJ2k/issues/comments.kt index cb3ccefecc5..264edf6427b 100644 --- a/nj2k/testData/newJ2k/issues/comments.kt +++ b/nj2k/testData/newJ2k/issues/comments.kt @@ -49,6 +49,7 @@ internal class C { */ //comments var l = 0 + /*two*/ /*comments*/ /*line*/ var z = 0 } \ No newline at end of file