KT-24750 Blank line after class header formatter should use user setting

This commit is contained in:
Sinan Kozak
2020-03-25 19:58:43 +03:00
committed by Dmitry Gridin
parent e6f527f1d0
commit 3f8ffb5ea7
6 changed files with 162 additions and 3 deletions
@@ -153,13 +153,16 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
null null
} else { } else {
val minLineFeeds = if (right.requireNode().elementType == FUN || right.requireNode().elementType == PROPERTY) val minLineFeeds = if (right.requireNode().elementType == FUN || right.requireNode().elementType == PROPERTY)
1 kotlinCommonSettings.BLANK_LINES_AFTER_CLASS_HEADER + 1
else else
0 0
builderUtil.createLineFeedDependentSpacing( builderUtil.createLineFeedDependentSpacing(
1, 1, minLineFeeds, 1,
settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_DECLARATIONS, 1,
minLineFeeds,
commonCodeStyleSettings.KEEP_LINE_BREAKS,
commonCodeStyleSettings.KEEP_BLANK_LINES_IN_DECLARATIONS,
TextRange(parentPsi.textRange.startOffset, left.requireNode().psi.textRange.startOffset), TextRange(parentPsi.textRange.startOffset, left.requireNode().psi.textRange.startOffset),
DependentSpacingRule(DependentSpacingRule.Trigger.HAS_LINE_FEEDS) DependentSpacingRule(DependentSpacingRule.Trigger.HAS_LINE_FEEDS)
.registerData( .registerData(
@@ -1,23 +1,46 @@
class Foo { class Foo {
fun bar() { fun bar() {
} }
} }
object Bar { object Bar {
fun xyzzy() { fun xyzzy() {
} }
} }
object BarS {
fun xyzzy() {}
}
val f = object { val f = object {
fun foo() {} fun foo() {}
} }
class FooCO {
fun bar() {
}
companion object {
fun foo() {}
}
}
class FooM class FooM
: IFoo { : IFoo {
fun bar() fun bar()
} }
class FooN : IFoo {
fun bar()
}
class FooC( class FooC(
val x: String val x: String
) { ) {
@@ -28,6 +51,7 @@ class FooC(
enum class Foo { Bar, Baz } enum class Foo { Bar, Baz }
class Foo { class Foo {
fun bar() {} fun bar() {}
} }
+15
View File
@@ -8,15 +8,30 @@ object Bar {
} }
} }
object BarS { fun xyzzy() {} }
val f = object { val f = object {
fun foo() {} fun foo() {}
} }
class FooCO {
fun bar() {
}
companion object {
fun foo() {}
}
}
class FooM class FooM
: IFoo { : IFoo {
fun bar() fun bar()
} }
class FooN : IFoo {
fun bar()
}
class FooC( class FooC(
val x: String val x: String
) { ) {
@@ -0,0 +1,67 @@
class Foo {
fun bar() {
}
}
object Bar {
fun xyzzy() {
}
}
object BarS {
fun xyzzy() {}
}
val f = object {
fun foo() {}
}
class FooCO {
fun bar() {
}
companion object {
fun foo() {}
}
}
class FooM
: IFoo {
fun bar()
}
class FooN : IFoo {
fun bar()
}
class FooC(
val x: String
) {
fun bar()
}
enum class Foo { Bar, Baz }
class Foo {
fun bar() {}
}
// SET_INT: BLANK_LINES_AFTER_CLASS_HEADER = 2
+45
View File
@@ -0,0 +1,45 @@
class Foo {
fun bar() {
}
}
object Bar {
fun xyzzy() {
}
}
object BarS { fun xyzzy() {} }
val f = object {
fun foo() {}
}
class FooCO {
fun bar() {
}
companion object {
fun foo() {}
}
}
class FooM
: IFoo {
fun bar()
}
class FooN : IFoo {
fun bar()
}
class FooC(
val x: String
) {
fun bar()
}
enum class Foo{Bar,Baz}
class Foo{fun bar() {}}
// SET_INT: BLANK_LINES_AFTER_CLASS_HEADER = 2
@@ -95,6 +95,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
runTest("idea/testData/formatter/BlankLinesAfterClassHeader.after.kt"); runTest("idea/testData/formatter/BlankLinesAfterClassHeader.after.kt");
} }
@TestMetadata("BlankLinesAfterClassHeader2.after.kt")
public void testBlankLinesAfterClassHeader2() throws Exception {
runTest("idea/testData/formatter/BlankLinesAfterClassHeader2.after.kt");
}
@TestMetadata("BlankLinesBeforeRBrace.after.kt") @TestMetadata("BlankLinesBeforeRBrace.after.kt")
public void testBlankLinesBeforeRBrace() throws Exception { public void testBlankLinesBeforeRBrace() throws Exception {
runTest("idea/testData/formatter/BlankLinesBeforeRBrace.after.kt"); runTest("idea/testData/formatter/BlankLinesBeforeRBrace.after.kt");