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,
left = LBRACE)
.customRule {
_, _, right ->
.customRule { _, _, right ->
val rightNode = right.node!!
val rightType = rightNode.elementType
var numSpaces = spacesInSimpleFunction
val numSpaces = spacesInSimpleFunction
if (rightType == VALUE_PARAMETER_LIST) {
val firstParamListNode = rightNode.firstChildNode
if (firstParamListNode != null && firstParamListNode.elementType == LPAR) {
// Don't put space for situation {<here>(a: Int) -> a }
numSpaces = 0
}
createSpacing(numSpaces, keepLineBreaks = false)
}
else {
createSpacing(numSpaces)
}
createSpacing(numSpaces)
}
inPosition(parent = CLASS_BODY, right = RBRACE).lineBreakIfLineBreakInParent(numSpacesOtherwise = 1)
@@ -7,8 +7,7 @@ fun test() {
}
}
2 ?: some {
s ->
2 ?: some { s ->
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 foo(xy: XY) = convert(xy) {
(x, y) ->
fun foo(xy: XY) = convert(xy) { (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 foo(xy: XY) = convert(xy) {
(x, y) ->
fun foo(xy: XY) = convert(xy) { (x, y) ->
x + y
}
@@ -1,6 +1,5 @@
fun main() {
val oom: (Int)->Int = {
it: Int ->
val oom: (Int)->Int = { it: Int ->
it * 2
}
}
@@ -1,5 +1,4 @@
val foo: (Long) -> String = {
it: Long ->
val foo: (Long) -> String = { it: Long ->
it.toString()
@@ -1,6 +1,5 @@
fun foo() {
val ff = {
it: Int ->
val ff = { it: Int ->
it
}
}
@@ -986,13 +986,11 @@ class SmartEnterTest : KotlinLightCodeInsightFixtureTestCase() {
fun testInLambda2() = doFunTest(
"""
some {
p<caret> ->
some { p<caret> ->
}
""",
"""
some {
p ->
some { p ->
<caret>
}
"""
@@ -1000,13 +998,11 @@ class SmartEnterTest : KotlinLightCodeInsightFixtureTestCase() {
fun testInLambda3() = doFunTest(
"""
some {
(<caret>p: Int) : Int ->
some { (<caret>p: Int) : Int ->
}
""",
"""
some {
(p: Int) : Int ->
some { (p: Int) : Int ->
<caret>
}
"""