From 8eb8e5a9288d96936329ea81fabcec0d3bc20364 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sat, 10 May 2014 21:11:07 +0400 Subject: [PATCH] Fix spacing after return (KT-4947) #KT-4947 Fixed --- .../plugin/formatter/kotlinSpacingRules.kt | 4 ++ .../formatter/ReturnExpression.after.kt | 39 +++++++++++++++++++ idea/testData/formatter/ReturnExpression.kt | 39 +++++++++++++++++++ .../ReturnContinue.after.kt | 4 ++ .../indentationOnNewline/ReturnContinue.kt | 3 ++ .../formatter/JetFormatterTestGenerated.java | 9 ++++- ...JetTypingIndentationTestBaseGenerated.java | 9 ++++- 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 idea/testData/formatter/ReturnExpression.after.kt create mode 100644 idea/testData/formatter/ReturnExpression.kt create mode 100644 idea/testData/indentationOnNewline/ReturnContinue.after.kt create mode 100644 idea/testData/indentationOnNewline/ReturnContinue.kt diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/kotlinSpacingRules.kt b/idea/src/org/jetbrains/jet/plugin/formatter/kotlinSpacingRules.kt index bdb9f9fa07d..0ba493823b1 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/kotlinSpacingRules.kt +++ b/idea/src/org/jetbrains/jet/plugin/formatter/kotlinSpacingRules.kt @@ -82,6 +82,10 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder { betweenInside(TYPE_REFERENCE, DOT, PROPERTY).spacing(0, 0, 0, false, 0) betweenInside(DOT, IDENTIFIER, PROPERTY).spacing(0, 0, 0, false, 0) + betweenInside(RETURN_KEYWORD, LABEL_QUALIFIER, RETURN).spaces(0) + afterInside(RETURN_KEYWORD, RETURN).spaces(1) + afterInside(LABEL_QUALIFIER, RETURN).spaces(1) + betweenInside(FUN_KEYWORD, IDENTIFIER, FUN).spaces(1) betweenInside(FUN_KEYWORD, TYPE_REFERENCE, FUN).spaces(1) betweenInside(TYPE_REFERENCE, DOT, FUN).spacing(0, 0, 0, false, 0) diff --git a/idea/testData/formatter/ReturnExpression.after.kt b/idea/testData/formatter/ReturnExpression.after.kt new file mode 100644 index 00000000000..fe2558f66e6 --- /dev/null +++ b/idea/testData/formatter/ReturnExpression.after.kt @@ -0,0 +1,39 @@ +fun test1(): Int { + return 1 +} + +fun test2(): Int { + return + 1 +} + +fun test3(): Int { + return + + + + 1 +} + +fun test4(): Int { + return synchronized(this) {(): Int -> + return@synchronized 12 + } +} + +fun test5(): Int { + return synchronized(this) {(): Int -> + return@synchronized 12 + } +} + +fun test6(): Int { + return synchronized(this) {(): Int -> + return + + @synchronized + + 12 + } +} + diff --git a/idea/testData/formatter/ReturnExpression.kt b/idea/testData/formatter/ReturnExpression.kt new file mode 100644 index 00000000000..94b952e7cfb --- /dev/null +++ b/idea/testData/formatter/ReturnExpression.kt @@ -0,0 +1,39 @@ +fun test1(): Int { + return 1 +} + +fun test2(): Int { + return + 1 +} + +fun test3(): Int { + return + + + + 1 +} + +fun test4(): Int { + return synchronized(this) {(): Int -> + return@synchronized 12 + } +} + +fun test5(): Int { + return synchronized(this) {(): Int -> + return @synchronized 12 + } +} + +fun test6(): Int { + return synchronized(this) {(): Int -> + return + + @synchronized + + 12 + } +} + diff --git a/idea/testData/indentationOnNewline/ReturnContinue.after.kt b/idea/testData/indentationOnNewline/ReturnContinue.after.kt new file mode 100644 index 00000000000..3bd794a6231 --- /dev/null +++ b/idea/testData/indentationOnNewline/ReturnContinue.after.kt @@ -0,0 +1,4 @@ +fun test(): Int { + return + +} \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/ReturnContinue.kt b/idea/testData/indentationOnNewline/ReturnContinue.kt new file mode 100644 index 00000000000..5d4c7e1044a --- /dev/null +++ b/idea/testData/indentationOnNewline/ReturnContinue.kt @@ -0,0 +1,3 @@ +fun test(): Int { + return +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java index 093b014a789..6bcf845f775 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTestGenerated.java @@ -244,6 +244,11 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest { doTest("idea/testData/formatter/RemoveSpacesAroundOperations.after.kt"); } + @TestMetadata("ReturnExpression.after.kt") + public void testReturnExpression() throws Exception { + doTest("idea/testData/formatter/ReturnExpression.after.kt"); + } + @TestMetadata("RightBracketOnNewLine.after.kt") public void testRightBracketOnNewLine() throws Exception { doTest("idea/testData/formatter/RightBracketOnNewLine.after.kt"); @@ -454,7 +459,9 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest { @InnerTestClasses({}) public static class FormatterInverted extends AbstractJetFormatterTest { public void testAllFilesPresentInFormatterInverted() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/formatter"), Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), true); + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", + new File("idea/testData/formatter"), + Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), true); } @TestMetadata("BinaryExpressions.after.inv.kt") diff --git a/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java b/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java index a9e4d02403a..05f7c835370 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetTypingIndentationTestBaseGenerated.java @@ -61,7 +61,9 @@ public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingInde } public void testAllFilesPresentInDirectSettings() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/indentationOnNewline"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true); + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", + new File("idea/testData/indentationOnNewline"), + Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true); } @TestMetadata("ConsecutiveCallsAfterDot.after.kt") @@ -214,6 +216,11 @@ public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingInde doNewlineTest("idea/testData/indentationOnNewline/PropertyWithInference.after.kt"); } + @TestMetadata("ReturnContinue.after.kt") + public void testReturnContinue() throws Exception { + doNewlineTest("idea/testData/indentationOnNewline/ReturnContinue.after.kt"); + } + @TestMetadata("SettingAlignMultilineParametersInCalls.after.kt") public void testSettingAlignMultilineParametersInCalls() throws Exception { doNewlineTest("idea/testData/indentationOnNewline/SettingAlignMultilineParametersInCalls.after.kt");