diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt index c149041b888..8c4ee30d2a4 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt @@ -201,11 +201,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing after(LBRACKET).spaces(0) before(RBRACKET).spaces(0) - after(LPAR).spaces(0) - before(RPAR).spaces(0) - afterInside(LPAR, VALUE_PARAMETER_LIST).spaces(0) - beforeInside(RPAR, VALUE_PARAMETER_LIST).spaces(0) + afterInside(LPAR, VALUE_PARAMETER_LIST).spaces(0, kotlinCommonSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE) + beforeInside(RPAR, VALUE_PARAMETER_LIST).spaces(0, kotlinCommonSettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE) afterInside(LT, TYPE_PARAMETER_LIST).spaces(0) beforeInside(GT, TYPE_PARAMETER_LIST).spaces(0) afterInside(LPAR, VALUE_ARGUMENT_LIST).spaces(0) @@ -214,6 +212,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing beforeInside(GT, TYPE_ARGUMENT_LIST).spaces(0) before(TYPE_ARGUMENT_LIST).spaces(0) + after(LPAR).spaces(0) + before(RPAR).spaces(0) + betweenInside(FOR_KEYWORD, LPAR, FOR).spaceIf(kotlinCommonSettings.SPACE_BEFORE_FOR_PARENTHESES) betweenInside(IF_KEYWORD, LPAR, IF).spaceIf(kotlinCommonSettings.SPACE_BEFORE_IF_PARENTHESES) betweenInside(WHILE_KEYWORD, LPAR, WHILE).spaceIf(kotlinCommonSettings.SPACE_BEFORE_WHILE_PARENTHESES) diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt index fda929c182f..51e3da7db06 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt @@ -46,6 +46,10 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide try { return foo1(12, 13, 14) } catch (e: Exception) { return 0 } finally { if (true) { return 1 } else { return 2 } } } private val f = {(a: Int)->a*2} + + fun longMethod(param1: Int, + param2: String) { + } } enum class Enumeration { @@ -198,7 +202,9 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide "CATCH_ON_NEW_LINE", "FINALLY_ON_NEW_LINE", "CALL_PARAMETERS_WRAP", - "METHOD_PARAMETERS_WRAP" + "METHOD_PARAMETERS_WRAP", + "METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE", + "METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" ) consumer.renameStandardOption(CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT, "'when' statements") consumer.showCustomOption(KotlinCodeStyleSettings::class.java, "ALIGN_IN_COLUMNS_CASE_BRANCH", "Align 'when' branches in columns", diff --git a/idea/testData/formatter/MethodLParenthOnNextLine.after.inv.kt b/idea/testData/formatter/MethodLParenthOnNextLine.after.inv.kt new file mode 100644 index 00000000000..443385d61e5 --- /dev/null +++ b/idea/testData/formatter/MethodLParenthOnNextLine.after.inv.kt @@ -0,0 +1,4 @@ +fun foo(a: String, + b: String) + +// SET_TRUE: METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE diff --git a/idea/testData/formatter/MethodLParenthOnNextLine.after.kt b/idea/testData/formatter/MethodLParenthOnNextLine.after.kt new file mode 100644 index 00000000000..6d7d6473308 --- /dev/null +++ b/idea/testData/formatter/MethodLParenthOnNextLine.after.kt @@ -0,0 +1,5 @@ +fun foo( + a: String, + b: String) + +// SET_TRUE: METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE diff --git a/idea/testData/formatter/MethodLParenthOnNextLine.kt b/idea/testData/formatter/MethodLParenthOnNextLine.kt new file mode 100644 index 00000000000..443385d61e5 --- /dev/null +++ b/idea/testData/formatter/MethodLParenthOnNextLine.kt @@ -0,0 +1,4 @@ +fun foo(a: String, + b: String) + +// SET_TRUE: METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE diff --git a/idea/testData/formatter/MethodRParenthOnNextLine.after.inv.kt b/idea/testData/formatter/MethodRParenthOnNextLine.after.inv.kt new file mode 100644 index 00000000000..966a6dea8e5 --- /dev/null +++ b/idea/testData/formatter/MethodRParenthOnNextLine.after.inv.kt @@ -0,0 +1,4 @@ +fun foo(a: String, + b: String) + +// SET_TRUE: METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE diff --git a/idea/testData/formatter/MethodRParenthOnNextLine.after.kt b/idea/testData/formatter/MethodRParenthOnNextLine.after.kt new file mode 100644 index 00000000000..b576dbc2ef6 --- /dev/null +++ b/idea/testData/formatter/MethodRParenthOnNextLine.after.kt @@ -0,0 +1,5 @@ +fun foo(a: String, + b: String +) + +// SET_TRUE: METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE diff --git a/idea/testData/formatter/MethodRParenthOnNextLine.kt b/idea/testData/formatter/MethodRParenthOnNextLine.kt new file mode 100644 index 00000000000..966a6dea8e5 --- /dev/null +++ b/idea/testData/formatter/MethodRParenthOnNextLine.kt @@ -0,0 +1,4 @@ +fun foo(a: String, + b: String) + +// SET_TRUE: METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index 1c6de7b6307..36a6ed93d97 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -434,6 +434,18 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTest(fileName); } + @TestMetadata("MethodLParenthOnNextLine.after.kt") + public void testMethodLParenthOnNextLine() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/MethodLParenthOnNextLine.after.kt"); + doTest(fileName); + } + + @TestMetadata("MethodRParenthOnNextLine.after.kt") + public void testMethodRParenthOnNextLine() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/MethodRParenthOnNextLine.after.kt"); + doTest(fileName); + } + @TestMetadata("Multideclaration.after.kt") public void testMultideclaration() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/Multideclaration.after.kt"); @@ -1094,6 +1106,18 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTestInverted(fileName); } + @TestMetadata("MethodLParenthOnNextLine.after.inv.kt") + public void testMethodLParenthOnNextLine() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/MethodLParenthOnNextLine.after.inv.kt"); + doTestInverted(fileName); + } + + @TestMetadata("MethodRParenthOnNextLine.after.inv.kt") + public void testMethodRParenthOnNextLine() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/MethodRParenthOnNextLine.after.inv.kt"); + doTestInverted(fileName); + } + @TestMetadata("MultilineFunctionLiteralWithParams.after.inv.kt") public void testMultilineFunctionLiteralWithParams() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/MultilineFunctionLiteralWithParams.after.inv.kt");