Formatter: fix line break between declarations with annotations
#KT-35093 Fixed #KT-35106 Fixed
This commit is contained in:
@@ -105,8 +105,7 @@ class KotlinSpacingBuilder(val commonCodeStyleSettings: CommonCodeStyleSettings,
|
||||
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 }
|
||||
?.startOfDeclaration()
|
||||
?.startOffset
|
||||
?.let { TextRange.create(it, left.textRange.endOffset) }
|
||||
?: left.textRange
|
||||
|
||||
@@ -95,9 +95,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
_: 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)) {
|
||||
val node = right.node ?: return null
|
||||
val elementStart = node.startOfDeclaration() ?: return null
|
||||
return if (StringUtil.containsLineBreak(node.text.subSequence(0, elementStart.startOffset - node.startOffset).trimStart())) {
|
||||
createSpacing(0, minLineFeeds = 2)
|
||||
} else
|
||||
null
|
||||
|
||||
@@ -13,6 +13,10 @@ interface Some {
|
||||
*/
|
||||
fun f6()
|
||||
fun f7()
|
||||
|
||||
@NotNull
|
||||
fun f8()
|
||||
fun f9()
|
||||
}
|
||||
|
||||
abstract class Abstract() {
|
||||
|
||||
@@ -11,6 +11,9 @@ interface Some {
|
||||
*/
|
||||
fun f6()
|
||||
fun f7()
|
||||
@NotNull
|
||||
fun f8()
|
||||
fun f9()
|
||||
}
|
||||
|
||||
abstract class Abstract() {
|
||||
|
||||
+1
@@ -4,6 +4,7 @@
|
||||
annotation class CommonAnnotation
|
||||
expect class My {
|
||||
tailrec fun foo(arg: Int): Int
|
||||
|
||||
@CommonAnnotation
|
||||
fun initialize()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user