diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt b/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt index 0fa9933a15b..1624a8b6213 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt @@ -147,8 +147,6 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder { around(TokenSet.create(PLUSPLUS, MINUSMINUS, EXCLEXCL, MINUS, PLUS, EXCL)).spaceIf(jetCommonSettings.SPACE_AROUND_UNARY_OPERATOR) around(RANGE).spaceIf(jetSettings.SPACE_AROUND_RANGE) - beforeInside(BLOCK, FUN).spaceIf(jetCommonSettings.SPACE_BEFORE_METHOD_LBRACE) - afterInside(LPAR, VALUE_PARAMETER_LIST).spaces(0) beforeInside(RPAR, VALUE_PARAMETER_LIST).spaces(0) afterInside(LT, TYPE_PARAMETER_LIST).spaces(0) @@ -233,6 +231,8 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder { inPosition(parent = CATCH, right = BLOCK).customRule(leftBraceRule) inPosition(parent = FINALLY, right = BLOCK).customRule(leftBraceRule) + inPosition(parent = FUN, right = BLOCK).customRule(leftBraceRule) + val spacesInSimpleFunction = if (jetSettings.INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD) 1 else 0 inPosition(parent = FUNCTION_LITERAL, diff --git a/idea/testData/formatter/DoWhileLineBreak.after.kt b/idea/testData/formatter/DoWhileLineBreak.after.kt index faf5a5b7a1f..e7b49030143 100644 --- a/idea/testData/formatter/DoWhileLineBreak.after.kt +++ b/idea/testData/formatter/DoWhileLineBreak.after.kt @@ -1,4 +1,5 @@ -fun main() { +fun main() +{ do { diff --git a/idea/testData/formatter/ForLineBreak.after.kt b/idea/testData/formatter/ForLineBreak.after.kt index 9c9bfa7c33c..44dbc48cf4d 100644 --- a/idea/testData/formatter/ForLineBreak.after.kt +++ b/idea/testData/formatter/ForLineBreak.after.kt @@ -1,4 +1,5 @@ -fun main() { +fun main() +{ for (a in b) { } diff --git a/idea/testData/formatter/FunctionLineBreak.after.inv.kt b/idea/testData/formatter/FunctionLineBreak.after.inv.kt new file mode 100644 index 00000000000..6880dcb4da5 --- /dev/null +++ b/idea/testData/formatter/FunctionLineBreak.after.inv.kt @@ -0,0 +1,35 @@ +fun f() { +} + +fun f() { +} + +fun f() { +} + +fun f() //eol comment +{ +} + +fun f() //eol comment +{ +} + +class A { + fun f() { + } + + fun f() { + } +} + + +fun g() { + fun f() { + } + + fun f() { + } +} + +// SET_TRUE: LBRACE_ON_NEXT_LINE \ No newline at end of file diff --git a/idea/testData/formatter/FunctionLineBreak.after.kt b/idea/testData/formatter/FunctionLineBreak.after.kt new file mode 100644 index 00000000000..9559593186b --- /dev/null +++ b/idea/testData/formatter/FunctionLineBreak.after.kt @@ -0,0 +1,43 @@ +fun f() +{ +} + +fun f() +{ +} + +fun f() +{ +} + +fun f() //eol comment +{ +} + +fun f() //eol comment +{ +} + +class A { + fun f() + { + } + + fun f() + { + } +} + + +fun g() +{ + fun f() + { + } + + fun f() + { + } +} + +// SET_TRUE: LBRACE_ON_NEXT_LINE \ No newline at end of file diff --git a/idea/testData/formatter/FunctionLineBreak.kt b/idea/testData/formatter/FunctionLineBreak.kt new file mode 100644 index 00000000000..87f2a1451b5 --- /dev/null +++ b/idea/testData/formatter/FunctionLineBreak.kt @@ -0,0 +1,41 @@ +fun f() { +} + +fun f() +{ +} + +fun f() + +{ +} + +fun f() //eol comment +{ +} + +fun f() //eol comment + +{ +} + +class A { + fun f() { + } + + fun f() + { + } +} + + +fun g() { + fun f() { + } + + fun f() + { + } +} + +// SET_TRUE: LBRACE_ON_NEXT_LINE \ No newline at end of file diff --git a/idea/testData/formatter/FunctionWithNewLineBrace.after.kt b/idea/testData/formatter/FunctionWithNewLineBrace.after.kt deleted file mode 100644 index 10f601298b1..00000000000 --- a/idea/testData/formatter/FunctionWithNewLineBrace.after.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun test() -{ -} \ No newline at end of file diff --git a/idea/testData/formatter/FunctionWithNewLineBrace.kt b/idea/testData/formatter/FunctionWithNewLineBrace.kt deleted file mode 100644 index 10f601298b1..00000000000 --- a/idea/testData/formatter/FunctionWithNewLineBrace.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun test() -{ -} \ No newline at end of file diff --git a/idea/testData/formatter/IfElseWithLineBreak.after.kt b/idea/testData/formatter/IfElseWithLineBreak.after.kt index ed515aa53ec..82638979522 100644 --- a/idea/testData/formatter/IfElseWithLineBreak.after.kt +++ b/idea/testData/formatter/IfElseWithLineBreak.after.kt @@ -1,4 +1,5 @@ -fun main(args: Array) { +fun main(args: Array) +{ if (true) { false diff --git a/idea/testData/formatter/IfElseWithTrickyComments.after.inv.kt b/idea/testData/formatter/IfElseWithTrickyComments.after.inv.kt index b042c0ab740..45b47872549 100644 --- a/idea/testData/formatter/IfElseWithTrickyComments.after.inv.kt +++ b/idea/testData/formatter/IfElseWithTrickyComments.after.inv.kt @@ -1,4 +1,5 @@ -fun main(args: Array) { +fun main(args: Array) +{ if (true) // tricky comment { } diff --git a/idea/testData/formatter/TryCatchLineBreak.after.kt b/idea/testData/formatter/TryCatchLineBreak.after.kt index 92347c415a1..913c119a0c2 100644 --- a/idea/testData/formatter/TryCatchLineBreak.after.kt +++ b/idea/testData/formatter/TryCatchLineBreak.after.kt @@ -1,4 +1,5 @@ -fun f() { +fun f() +{ try { diff --git a/idea/testData/formatter/WhileLineBreak.after.kt b/idea/testData/formatter/WhileLineBreak.after.kt index 49f0b47a3a0..f6ba8d00564 100644 --- a/idea/testData/formatter/WhileLineBreak.after.kt +++ b/idea/testData/formatter/WhileLineBreak.after.kt @@ -1,4 +1,5 @@ -fun main(args: Array) { +fun main(args: Array) +{ while (true) { } diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java index 18ac310b497..dad1b7b687e 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java @@ -99,16 +99,16 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest { doTest("idea/testData/formatter/FunctionDefParametersAlign.after.kt"); } + @TestMetadata("FunctionLineBreak.after.kt") + public void testFunctionLineBreak() throws Exception { + doTest("idea/testData/formatter/FunctionLineBreak.after.kt"); + } + @TestMetadata("FunctionWithInference.after.kt") public void testFunctionWithInference() throws Exception { doTest("idea/testData/formatter/FunctionWithInference.after.kt"); } - @TestMetadata("FunctionWithNewLineBrace.after.kt") - public void testFunctionWithNewLineBrace() throws Exception { - doTest("idea/testData/formatter/FunctionWithNewLineBrace.after.kt"); - } - @TestMetadata("FunctionalType.after.kt") public void testFunctionalType() throws Exception { doTest("idea/testData/formatter/FunctionalType.after.kt"); @@ -372,6 +372,11 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest { doTestInverted("idea/testData/formatter/ForLineBreak.after.inv.kt"); } + @TestMetadata("FunctionLineBreak.after.inv.kt") + public void testFunctionLineBreak() throws Exception { + doTestInverted("idea/testData/formatter/FunctionLineBreak.after.inv.kt"); + } + @TestMetadata("FunctionalType.after.inv.kt") public void testFunctionalType() throws Exception { doTestInverted("idea/testData/formatter/FunctionalType.after.inv.kt");