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()
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import kotlin.reflect.KClass
|
||||
annotation class Ann(vararg val value: Inner, val test1: Array<InnerParam> = [InnerParam(C::class)])
|
||||
annotation class Inner
|
||||
annotation class InnerParam(val value: KClass<*>)
|
||||
|
||||
@Ann(value = [Inner(), Inner()], test1 = [InnerParam(C::class)])
|
||||
class C
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
internal annotation class Anon(val s: String = "a", val stringArray: Array<String> = ["a", "b"], val intArray: IntArray)
|
||||
|
||||
@Anon(intArray = [1, 2])
|
||||
internal class A
|
||||
@@ -1,4 +1,5 @@
|
||||
internal annotation class Anon(vararg val value: String, val x: Int = 1)
|
||||
|
||||
@Anon("a", "b")
|
||||
internal interface I1
|
||||
|
||||
|
||||
@@ -23,10 +23,13 @@ internal class C {
|
||||
@Anon5(1)
|
||||
@Deprecated("")
|
||||
private val field1 = 0
|
||||
|
||||
@Anon5(1)
|
||||
private val field2 = 0
|
||||
|
||||
@Anon5(1)
|
||||
var field3 = 0
|
||||
|
||||
@Anon5(1)
|
||||
var field4 = 0
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
internal annotation class Ann(val value: KClass<*>, val other: KClass<*>)
|
||||
|
||||
@Ann(other = String::class, value = Any::class)
|
||||
internal class C
|
||||
@@ -1,6 +1,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
internal annotation class Ann(vararg val value: KClass<*>)
|
||||
|
||||
@Ann(String::class, Any::class)
|
||||
internal class C
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ internal class A {
|
||||
private var x = 0
|
||||
|
||||
constructor() {}
|
||||
|
||||
@JvmOverloads
|
||||
constructor(p: Int, s: String, x: Int = 1) {
|
||||
this.s = s
|
||||
|
||||
@@ -3,6 +3,7 @@ internal class A {
|
||||
@Deprecated("")
|
||||
@Volatile
|
||||
var field1 = 0
|
||||
|
||||
@Transient
|
||||
var field2 = 1
|
||||
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
object ArrayInitializerBugKt {
|
||||
private val GREETING = byteArrayOf('H'.toByte(), 'e'.toByte(), 'l'.toByte(), 'l'.toByte(), 'o'.toByte(), ','.toByte(), ' '.toByte(), 'b'.toByte(), 'u'.toByte(), 'g'.toByte(), '!'.toByte())
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
val greeting = String(GREETING)
|
||||
|
||||
Reference in New Issue
Block a user