Formatter: support "catch on new line" and "finally on new line" options

This commit is contained in:
Pavel V. Talanov
2014-01-17 19:20:30 +04:00
parent 7dc7db04b3
commit 53d503e242
10 changed files with 88 additions and 51 deletions
@@ -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",
@@ -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? {
@@ -2,14 +2,11 @@
fun foo(n: Int): Int {
return try {
n / 0
}
<caret>catch (e: ArithmeticException) {
} <caret>catch (e: ArithmeticException) {
-1
}
catch (e: Exception) {
} catch (e: Exception) {
-2
}
finally {
} finally {
}
}
@@ -2,11 +2,9 @@
fun foo(n: Int): Int {
return try {
n / 0
}
<caret>catch (e: Exception) {
} <caret>catch (e: Exception) {
-2
}
finally {
} finally {
}
}
@@ -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
@@ -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
@@ -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
@@ -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
{
}
@@ -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
{
}
@@ -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");