diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt index d39a0432bf9..e5b8fe17413 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -352,6 +352,9 @@ abstract class KotlinCommonBlock( } } + elementType === KtNodeTypes.CLASS_BODY -> + return getWrappingStrategyForItemList(commonSettings.ENUM_CONSTANTS_WRAP, KtNodeTypes.ENUM_ENTRY) + elementType === KtNodeTypes.MODIFIER_LIST -> when (node.treeParent.psi) { is KtParameter -> diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt index 6a44f1e5fee..ef203160d3b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt @@ -53,8 +53,7 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide } enum class Enumeration { - A, - B + A, B } """.trimIndent() @@ -242,7 +241,8 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide "METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE", "METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE", "CALL_PARAMETERS_LPAREN_ON_NEXT_LINE", - "CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" + "CALL_PARAMETERS_RPAREN_ON_NEXT_LINE", + "ENUM_CONSTANTS_WRAP" ) consumer.renameStandardOption(CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT, "'when' statements") showCustomOption(KotlinCodeStyleSettings::ALIGN_IN_COLUMNS_CASE_BRANCH, diff --git a/idea/testData/formatter/EnumWrapping.after.kt b/idea/testData/formatter/EnumWrapping.after.kt new file mode 100644 index 00000000000..613844047a7 --- /dev/null +++ b/idea/testData/formatter/EnumWrapping.after.kt @@ -0,0 +1,8 @@ +enum class A { + ENUM_OPTION_A, + ENUM_OPTION_B, + ENUM_OPTION_C, + ENUM_OPTION_D +} + +// SET_INT: ENUM_CONSTANTS_WRAP = 2 \ No newline at end of file diff --git a/idea/testData/formatter/EnumWrapping.kt b/idea/testData/formatter/EnumWrapping.kt new file mode 100644 index 00000000000..10c4582cfdc --- /dev/null +++ b/idea/testData/formatter/EnumWrapping.kt @@ -0,0 +1,5 @@ +enum class A { + ENUM_OPTION_A, ENUM_OPTION_B, ENUM_OPTION_C, ENUM_OPTION_D +} + +// SET_INT: ENUM_CONSTANTS_WRAP = 2 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index f9686696099..cf36b34c81b 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -320,6 +320,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTest(fileName); } + @TestMetadata("EnumWrapping.after.kt") + public void testEnumWrapping() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/EnumWrapping.after.kt"); + doTest(fileName); + } + @TestMetadata("ExtendsListWrap.after.kt") public void testExtendsListWrap() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ExtendsListWrap.after.kt");