diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt index 9e33571ad82..5aa0da6e5d0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt @@ -98,7 +98,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder { // ENUM_ENTRY - ENUM_ENTRY is exception between(ENUM_ENTRY, DECLARATIONS).blankLines(1) - before(FUN).lineBreakInCode() + beforeInside(FUN, TokenSet.create(BODY, CLASS_BODY)).lineBreakInCode() before(PROPERTY).lineBreakInCode() diff --git a/idea/testData/formatter/FunctionExpression.after.kt b/idea/testData/formatter/FunctionExpression.after.kt new file mode 100644 index 00000000000..731b16e5c52 --- /dev/null +++ b/idea/testData/formatter/FunctionExpression.after.kt @@ -0,0 +1,34 @@ +val a = fun () { +} +val b = fun test() { +} + +val c = fun() { +} +val c = fun() = 4 + +val c = fun() = + 4 + +val c = fun() { +} +val c = fun() = 4 + +fun test() = fun test() = 4 + +fun test() { + test(fun test() { + }) + test(fun test() = 5) + + test(fun test() = fun test(a: Int) = 2) + + 2.(fun test() { + })() + + (fun() = 4) + (fun() { + }) + + test(fun test() = 4) +} \ No newline at end of file diff --git a/idea/testData/formatter/FunctionExpression.kt b/idea/testData/formatter/FunctionExpression.kt new file mode 100644 index 00000000000..df1ca355711 --- /dev/null +++ b/idea/testData/formatter/FunctionExpression.kt @@ -0,0 +1,27 @@ +val a = fun () {} +val b = fun test() {} + +val c=fun(){} +val c=fun()=4 + +val c=fun()= + 4 + +val c = fun() {} +val c = fun() = 4 + +fun test() = fun test() = 4 + +fun test() { + test(fun test() {}) + test(fun test() = 5) + + test(fun test() = fun test(a: Int) = 2) + + 2.(fun test() {})() + + (fun()=4) + (fun(){}) + + test( fun test ( ) = 4 ) +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInsideLambda.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInsideLambda.kt index a4203c9c1f7..55753af2bfd 100644 --- a/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInsideLambda.kt +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInsideLambda.kt @@ -6,6 +6,5 @@ fun foo(a: Any) {} val a = foo @a { - val a = - fun (): Int = 1 + val a = fun (): Int = 1 } \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterReceiverAndReturnInExpression.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterReceiverAndReturnInExpression.kt index 3fb482ed2d4..8cbc193d02c 100644 --- a/idea/testData/quickfix/migration/lambdaSyntax/afterReceiverAndReturnInExpression.kt +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterReceiverAndReturnInExpression.kt @@ -1,5 +1,4 @@ // "Migrate lambda syntax" "true" -val a = - fun Int.(a: Int): String = "" \ No newline at end of file +val a = fun Int.(a: Int): String = "" \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/lambdaSyntaxMultiple.after.data.Sample.kt b/idea/testData/quickfix/migration/lambdaSyntax/lambdaSyntaxMultiple.after.data.Sample.kt index 96c94faf368..34db40fdd86 100644 --- a/idea/testData/quickfix/migration/lambdaSyntax/lambdaSyntaxMultiple.after.data.Sample.kt +++ b/idea/testData/quickfix/migration/lambdaSyntax/lambdaSyntaxMultiple.after.data.Sample.kt @@ -1,8 +1,6 @@ val h = { -> } -val l = @bar ( - fun Int.bar() { - }) +val l = @bar (fun Int.bar() { +}) -val s = ( - fun (): Int = 5)() \ No newline at end of file +val s = (fun (): Int = 5)() \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/lambdaSyntaxMultiple.after.kt b/idea/testData/quickfix/migration/lambdaSyntax/lambdaSyntaxMultiple.after.kt index c80a50780c6..4b1ffd1abde 100644 --- a/idea/testData/quickfix/migration/lambdaSyntax/lambdaSyntaxMultiple.after.kt +++ b/idea/testData/quickfix/migration/lambdaSyntax/lambdaSyntaxMultiple.after.kt @@ -1,9 +1,7 @@ // "Migrate lambda syntax in whole project" "true" -val a = - fun (): Int { - val b = - fun (): Int = 5 +val a = fun (): Int { + val b = fun (): Int = 5 - return b() - } \ No newline at end of file + return b() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/JetFormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/JetFormatterTestGenerated.java index b35d12a9360..964a54ad4a5 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/JetFormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/JetFormatterTestGenerated.java @@ -256,6 +256,12 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest { doTest(fileName); } + @TestMetadata("FunctionExpression.after.kt") + public void testFunctionExpression() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/FunctionExpression.after.kt"); + doTest(fileName); + } + @TestMetadata("FunctionLineBreak.after.kt") public void testFunctionLineBreak() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/FunctionLineBreak.after.kt");