Put lambda parameters on the same line as opening curly brace

This commit is contained in:
Dmitry Jemerov
2017-05-29 14:52:52 +02:00
parent af941bfdf5
commit f32dc9e84e
8 changed files with 16 additions and 30 deletions
@@ -399,20 +399,16 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
inPosition(parent = FUNCTION_LITERAL, inPosition(parent = FUNCTION_LITERAL,
left = LBRACE) left = LBRACE)
.customRule { .customRule { _, _, right ->
_, _, right ->
val rightNode = right.node!! val rightNode = right.node!!
val rightType = rightNode.elementType val rightType = rightNode.elementType
var numSpaces = spacesInSimpleFunction val numSpaces = spacesInSimpleFunction
if (rightType == VALUE_PARAMETER_LIST) { if (rightType == VALUE_PARAMETER_LIST) {
val firstParamListNode = rightNode.firstChildNode createSpacing(numSpaces, keepLineBreaks = false)
if (firstParamListNode != null && firstParamListNode.elementType == LPAR) { }
// Don't put space for situation {<here>(a: Int) -> a } else {
numSpaces = 0 createSpacing(numSpaces)
}
} }
createSpacing(numSpaces)
} }
inPosition(parent = CLASS_BODY, right = RBRACE).lineBreakIfLineBreakInParent(numSpacesOtherwise = 1) inPosition(parent = CLASS_BODY, right = RBRACE).lineBreakIfLineBreakInParent(numSpacesOtherwise = 1)
@@ -7,8 +7,7 @@ fun test() {
} }
} }
2 ?: some { 2 ?: some { s ->
s ->
val a = 12 val a = 12
} }
} }
@@ -4,7 +4,6 @@ data class XY(val x: String, val y: String)
fun convert(xy: XY, foo: (XY) -> Unit) = foo(xy) fun convert(xy: XY, foo: (XY) -> Unit) = foo(xy)
fun foo(xy: XY) = convert(xy) { fun foo(xy: XY) = convert(xy) { (x, y) ->
(x, y) ->
println(x + y) println(x + y)
} }
@@ -2,7 +2,6 @@ data class XY(val x: String, val y: String)
fun convert(xy: XY, foo: (XY) -> String) = foo(xy) fun convert(xy: XY, foo: (XY) -> String) = foo(xy)
fun foo(xy: XY) = convert(xy) { fun foo(xy: XY) = convert(xy) { (x, y) ->
(x, y) ->
x + y x + y
} }
@@ -1,6 +1,5 @@
fun main() { fun main() {
val oom: (Int)->Int = { val oom: (Int)->Int = { it: Int ->
it: Int ->
it * 2 it * 2
} }
} }
@@ -1,5 +1,4 @@
val foo: (Long) -> String = { val foo: (Long) -> String = { it: Long ->
it: Long ->
it.toString() it.toString()
@@ -1,6 +1,5 @@
fun foo() { fun foo() {
val ff = { val ff = { it: Int ->
it: Int ->
it it
} }
} }
@@ -986,13 +986,11 @@ class SmartEnterTest : KotlinLightCodeInsightFixtureTestCase() {
fun testInLambda2() = doFunTest( fun testInLambda2() = doFunTest(
""" """
some { some { p<caret> ->
p<caret> ->
} }
""", """,
""" """
some { some { p ->
p ->
<caret> <caret>
} }
""" """
@@ -1000,13 +998,11 @@ class SmartEnterTest : KotlinLightCodeInsightFixtureTestCase() {
fun testInLambda3() = doFunTest( fun testInLambda3() = doFunTest(
""" """
some { some { (<caret>p: Int) : Int ->
(<caret>p: Int) : Int ->
} }
""", """,
""" """
some { some { (p: Int) : Int ->
(p: Int) : Int ->
<caret> <caret>
} }
""" """