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 leftEndsWithComment = lastChild is PsiComment && lastChild.tokenType == KtTokens.EOL_COMMENT
|
||||||
val dependentSpacingRule = DependentSpacingRule(Trigger.HAS_LINE_FEEDS).registerData(Anchor.MIN_LINE_FEEDS, emptyLines + 1)
|
val dependentSpacingRule = DependentSpacingRule(Trigger.HAS_LINE_FEEDS).registerData(Anchor.MIN_LINE_FEEDS, emptyLines + 1)
|
||||||
val textRange = left.node
|
val textRange = left.node
|
||||||
?.children()
|
?.startOfDeclaration()
|
||||||
?.firstOrNull { it.elementType !in KtTokens.WHITE_SPACE_OR_COMMENT_BIT_SET }
|
|
||||||
?.startOffset
|
?.startOffset
|
||||||
?.let { TextRange.create(it, left.textRange.endOffset) }
|
?.let { TextRange.create(it, left.textRange.endOffset) }
|
||||||
?: left.textRange
|
?: left.textRange
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
|||||||
_: ASTBlock,
|
_: ASTBlock,
|
||||||
right: ASTBlock
|
right: ASTBlock
|
||||||
): Spacing? {
|
): Spacing? {
|
||||||
val firstChild = right.node?.firstChildNode as? PsiComment ?: return null
|
val node = right.node ?: return null
|
||||||
val whiteSpace = firstChild.nextSibling as? PsiWhiteSpace ?: return null
|
val elementStart = node.startOfDeclaration() ?: return null
|
||||||
return if (StringUtil.containsLineBreak(firstChild.text) || StringUtil.containsLineBreak(whiteSpace.text)) {
|
return if (StringUtil.containsLineBreak(node.text.subSequence(0, elementStart.startOffset - node.startOffset).trimStart())) {
|
||||||
createSpacing(0, minLineFeeds = 2)
|
createSpacing(0, minLineFeeds = 2)
|
||||||
} else
|
} else
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ interface Some {
|
|||||||
*/
|
*/
|
||||||
fun f6()
|
fun f6()
|
||||||
fun f7()
|
fun f7()
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
fun f8()
|
||||||
|
fun f9()
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Abstract() {
|
abstract class Abstract() {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ interface Some {
|
|||||||
*/
|
*/
|
||||||
fun f6()
|
fun f6()
|
||||||
fun f7()
|
fun f7()
|
||||||
|
@NotNull
|
||||||
|
fun f8()
|
||||||
|
fun f9()
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Abstract() {
|
abstract class Abstract() {
|
||||||
|
|||||||
+1
@@ -4,6 +4,7 @@
|
|||||||
annotation class CommonAnnotation
|
annotation class CommonAnnotation
|
||||||
expect class My {
|
expect class My {
|
||||||
tailrec fun foo(arg: Int): Int
|
tailrec fun foo(arg: Int): Int
|
||||||
|
|
||||||
@CommonAnnotation
|
@CommonAnnotation
|
||||||
fun initialize()
|
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 Ann(vararg val value: Inner, val test1: Array<InnerParam> = [InnerParam(C::class)])
|
||||||
annotation class Inner
|
annotation class Inner
|
||||||
annotation class InnerParam(val value: KClass<*>)
|
annotation class InnerParam(val value: KClass<*>)
|
||||||
|
|
||||||
@Ann(value = [Inner(), Inner()], test1 = [InnerParam(C::class)])
|
@Ann(value = [Inner(), Inner()], test1 = [InnerParam(C::class)])
|
||||||
class C
|
class C
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
internal annotation class Anon(val s: String = "a", val stringArray: Array<String> = ["a", "b"], val intArray: IntArray)
|
internal annotation class Anon(val s: String = "a", val stringArray: Array<String> = ["a", "b"], val intArray: IntArray)
|
||||||
|
|
||||||
@Anon(intArray = [1, 2])
|
@Anon(intArray = [1, 2])
|
||||||
internal class A
|
internal class A
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
internal annotation class Anon(vararg val value: String, val x: Int = 1)
|
internal annotation class Anon(vararg val value: String, val x: Int = 1)
|
||||||
|
|
||||||
@Anon("a", "b")
|
@Anon("a", "b")
|
||||||
internal interface I1
|
internal interface I1
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,13 @@ internal class C {
|
|||||||
@Anon5(1)
|
@Anon5(1)
|
||||||
@Deprecated("")
|
@Deprecated("")
|
||||||
private val field1 = 0
|
private val field1 = 0
|
||||||
|
|
||||||
@Anon5(1)
|
@Anon5(1)
|
||||||
private val field2 = 0
|
private val field2 = 0
|
||||||
|
|
||||||
@Anon5(1)
|
@Anon5(1)
|
||||||
var field3 = 0
|
var field3 = 0
|
||||||
|
|
||||||
@Anon5(1)
|
@Anon5(1)
|
||||||
var field4 = 0
|
var field4 = 0
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
internal annotation class Ann(val value: KClass<*>, val other: KClass<*>)
|
internal annotation class Ann(val value: KClass<*>, val other: KClass<*>)
|
||||||
|
|
||||||
@Ann(other = String::class, value = Any::class)
|
@Ann(other = String::class, value = Any::class)
|
||||||
internal class C
|
internal class C
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
internal annotation class Ann(vararg val value: KClass<*>)
|
internal annotation class Ann(vararg val value: KClass<*>)
|
||||||
|
|
||||||
@Ann(String::class, Any::class)
|
@Ann(String::class, Any::class)
|
||||||
internal class C
|
internal class C
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ internal class A {
|
|||||||
private var x = 0
|
private var x = 0
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(p: Int, s: String, x: Int = 1) {
|
constructor(p: Int, s: String, x: Int = 1) {
|
||||||
this.s = s
|
this.s = s
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ internal class A {
|
|||||||
@Deprecated("")
|
@Deprecated("")
|
||||||
@Volatile
|
@Volatile
|
||||||
var field1 = 0
|
var field1 = 0
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
var field2 = 1
|
var field2 = 1
|
||||||
|
|
||||||
|
|||||||
+1
@@ -1,5 +1,6 @@
|
|||||||
object ArrayInitializerBugKt {
|
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())
|
private val GREETING = byteArrayOf('H'.toByte(), 'e'.toByte(), 'l'.toByte(), 'l'.toByte(), 'o'.toByte(), ','.toByte(), ' '.toByte(), 'b'.toByte(), 'u'.toByte(), 'g'.toByte(), '!'.toByte())
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val greeting = String(GREETING)
|
val greeting = String(GREETING)
|
||||||
|
|||||||
Reference in New Issue
Block a user