diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java index 3b657deb7dd..d44a270c54f 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java @@ -143,7 +143,9 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti "ALIGN_MULTILINE_PARAMETERS_IN_CALLS", "ALIGN_MULTILINE_METHOD_BRACKETS", "ELSE_ON_NEW_LINE", - "WHILE_ON_NEW_LINE" + "WHILE_ON_NEW_LINE", + "CATCH_ON_NEW_LINE", + "FINALLY_ON_NEW_LINE" ); consumer.renameStandardOption(CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT, "'when' statements"); consumer.showCustomOption(JetCodeStyleSettings.class, "ALIGN_IN_COLUMNS_CASE_BRANCH", "Align in columns 'case' branches", diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt b/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt index 42419c510b3..c21cf5b92fe 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt @@ -206,6 +206,8 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder { ruleForKeywordOnNewLine(jetCommonSettings.ELSE_ON_NEW_LINE, keyword = ELSE_KEYWORD, parent = IF) ruleForKeywordOnNewLine(jetCommonSettings.WHILE_ON_NEW_LINE, keyword = WHILE_KEYWORD, parent = DO_WHILE) + ruleForKeywordOnNewLine(jetCommonSettings.CATCH_ON_NEW_LINE, keyword = CATCH, parent = TRY) + ruleForKeywordOnNewLine(jetCommonSettings.FINALLY_ON_NEW_LINE, keyword = FINALLY, parent = TRY) fun spacingForLeftBrace(block: ASTNode?, blockType: IElementType = BLOCK): Spacing? { diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeCatch/catch.kt b/idea/testData/codeInsight/unwrapAndRemove/removeCatch/catch.kt index d34c09620f6..5ec279ee7af 100644 --- a/idea/testData/codeInsight/unwrapAndRemove/removeCatch/catch.kt +++ b/idea/testData/codeInsight/unwrapAndRemove/removeCatch/catch.kt @@ -2,14 +2,11 @@ fun foo(n: Int): Int { return try { n / 0 - } - catch (e: ArithmeticException) { + } catch (e: ArithmeticException) { -1 - } - catch (e: Exception) { + } catch (e: Exception) { -2 - } - finally { + } finally { } } diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeCatch/catch.kt.after b/idea/testData/codeInsight/unwrapAndRemove/removeCatch/catch.kt.after index cd1400f4005..44f4b94de43 100644 --- a/idea/testData/codeInsight/unwrapAndRemove/removeCatch/catch.kt.after +++ b/idea/testData/codeInsight/unwrapAndRemove/removeCatch/catch.kt.after @@ -2,11 +2,9 @@ fun foo(n: Int): Int { return try { n / 0 - } - catch (e: Exception) { + } catch (e: Exception) { -2 - } - finally { + } finally { } } diff --git a/idea/testData/formatter/CatchFinallyOnNewLine.after.inv.kt b/idea/testData/formatter/CatchFinallyOnNewLine.after.inv.kt new file mode 100644 index 00000000000..cfb992229c6 --- /dev/null +++ b/idea/testData/formatter/CatchFinallyOnNewLine.after.inv.kt @@ -0,0 +1,14 @@ +fun f() { + try { + } catch (e: E) { + } finally { + } + + try { + } catch (e: E) { + } finally { + } +} + +// SET_TRUE: CATCH_ON_NEW_LINE +// SET_TRUE: FINALLY_ON_NEW_LINE \ No newline at end of file diff --git a/idea/testData/formatter/CatchFinallyOnNewLine.after.kt b/idea/testData/formatter/CatchFinallyOnNewLine.after.kt new file mode 100644 index 00000000000..b1e18121c0a --- /dev/null +++ b/idea/testData/formatter/CatchFinallyOnNewLine.after.kt @@ -0,0 +1,18 @@ +fun f() { + try { + } + catch (e: E) { + } + finally { + } + + try { + } + catch (e: E) { + } + finally { + } +} + +// SET_TRUE: CATCH_ON_NEW_LINE +// SET_TRUE: FINALLY_ON_NEW_LINE \ No newline at end of file diff --git a/idea/testData/formatter/CatchFinallyOnNewLine.kt b/idea/testData/formatter/CatchFinallyOnNewLine.kt new file mode 100644 index 00000000000..34539aec936 --- /dev/null +++ b/idea/testData/formatter/CatchFinallyOnNewLine.kt @@ -0,0 +1,16 @@ +fun f() { + try { + } + catch (e: E) { + } + finally { + } + + try { + } catch (e: E) { + } finally { + } +} + +// SET_TRUE: CATCH_ON_NEW_LINE +// SET_TRUE: FINALLY_ON_NEW_LINE \ No newline at end of file diff --git a/idea/testData/formatter/TryCatchLineBreak.after.inv.kt b/idea/testData/formatter/TryCatchLineBreak.after.inv.kt index 44d728b6b61..f7b301b2136 100644 --- a/idea/testData/formatter/TryCatchLineBreak.after.inv.kt +++ b/idea/testData/formatter/TryCatchLineBreak.after.inv.kt @@ -1,43 +1,35 @@ fun f() { try { - } - catch (e: Exception) { + } catch (e: Exception) { - } - finally { + } finally { } try { - } - catch (e: Exception) { + } catch (e: Exception) { - } - finally { + } finally { } try { - } - catch (e: Exception) { + } catch (e: Exception) { - } - finally { + } finally { } try //eol comment { - } - catch (e: Exception) //eol comment + } catch (e: Exception) //eol comment { - } - finally //eol comment + } finally //eol comment { } @@ -45,12 +37,10 @@ fun f() { try //eol comment { - } - catch (e: Exception) //eol comment + } catch (e: Exception) //eol comment { - } - finally //eol comment + } finally //eol comment { } diff --git a/idea/testData/formatter/TryCatchLineBreak.after.kt b/idea/testData/formatter/TryCatchLineBreak.after.kt index 913c119a0c2..77bc1666a78 100644 --- a/idea/testData/formatter/TryCatchLineBreak.after.kt +++ b/idea/testData/formatter/TryCatchLineBreak.after.kt @@ -3,12 +3,10 @@ fun f() try { - } - catch (e: Exception) + } catch (e: Exception) { - } - finally + } finally { } @@ -16,12 +14,10 @@ fun f() try { - } - catch (e: Exception) + } catch (e: Exception) { - } - finally + } finally { } @@ -29,12 +25,10 @@ fun f() try { - } - catch (e: Exception) + } catch (e: Exception) { - } - finally + } finally { } @@ -42,12 +36,10 @@ fun f() try //eol comment { - } - catch (e: Exception) //eol comment + } catch (e: Exception) //eol comment { - } - finally //eol comment + } finally //eol comment { } @@ -55,12 +47,10 @@ fun f() try //eol comment { - } - catch (e: Exception) //eol comment + } catch (e: Exception) //eol comment { - } - finally //eol comment + } finally //eol comment { } diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java index 5ff4320d12e..182b8ff2ecd 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java @@ -44,6 +44,11 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest { doTest("idea/testData/formatter/BlockFor.after.kt"); } + @TestMetadata("CatchFinallyOnNewLine.after.kt") + public void testCatchFinallyOnNewLine() throws Exception { + doTest("idea/testData/formatter/CatchFinallyOnNewLine.after.kt"); + } + @TestMetadata("Class.after.kt") public void testClass() throws Exception { doTest("idea/testData/formatter/Class.after.kt"); @@ -382,6 +387,11 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/formatter"), Pattern.compile("^([^\\.]+)\\.after.inv.kt$"), true); } + @TestMetadata("CatchFinallyOnNewLine.after.inv.kt") + public void testCatchFinallyOnNewLine() throws Exception { + doTestInverted("idea/testData/formatter/CatchFinallyOnNewLine.after.inv.kt"); + } + @TestMetadata("ClassLineBreak.after.inv.kt") public void testClassLineBreak() throws Exception { doTestInverted("idea/testData/formatter/ClassLineBreak.after.inv.kt");