From ec31808dcd3cfdc1330088efe576fd27a70a7073 Mon Sep 17 00:00:00 2001 From: sayon Date: Tue, 27 Aug 2013 16:22:20 +0400 Subject: [PATCH 1/6] A bigger code example for codestyle provider --- .../JetLanguageCodeStyleSettingsProvider.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java index 596a6d530cb..fe4ec87aafa 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java @@ -57,17 +57,25 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti "}"; default: return - "open class Some {\n" + - " private val f = {(a: Int)->a*2}\n" + - " fun foo() : Int {\n" + - " val test : Int = 12\n" + - " return test\n" + - " }\n" + - " private fun foo2():Int where T : List {\n" + - " return 0\n" + - " }\n" + - "}\n\n" + - "class AnotherClass: Some"; + "open class Some {\n"+ + " private val f: (Int)->Int = { (a: Int) -> a * 2 }\n"+ + " fun foo(): Int {\n"+ + " val test: Int = 12\n"+ + " for (i in 10..42) {\n"+ + " println (when {\n"+ + " i < test -> -1\n"+ + " i > test -> 1\n"+ + " else -> 0\n"+ + " })\n"+ + " }\n"+ + " return test\n"+ + " }\n"+ + " private fun foo2(): Int where T : List {\n"+ + " return 0\n"+ + " }\n"+ + "}\n"+ + "class AnotherClass : Some()\n"; + } } From f8b280ba5732935c9bfb59aa7bd2932074dc017b Mon Sep 17 00:00:00 2001 From: sayon Date: Tue, 27 Aug 2013 16:22:20 +0400 Subject: [PATCH 2/6] New setting and test: space around arrow inside 'when' --- .../jet/plugin/formatter/JetCodeStyleSettings.java | 2 ++ .../jet/plugin/formatter/JetFormattingModelBuilder.java | 8 ++++---- .../formatter/JetLanguageCodeStyleSettingsProvider.java | 3 +++ idea/testData/formatter/WhenArrow.kt | 8 ++++++++ idea/testData/formatter/WhenArrow_after.kt | 8 ++++++++ idea/testData/formatter/WhenArrow_after_inv.kt | 8 ++++++++ .../org/jetbrains/jet/formatter/JetFormatterTest.java | 4 ++++ 7 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 idea/testData/formatter/WhenArrow.kt create mode 100644 idea/testData/formatter/WhenArrow_after.kt create mode 100644 idea/testData/formatter/WhenArrow_after_inv.kt diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java index b5a2d2d40c6..c04f4e9b829 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java @@ -34,6 +34,8 @@ public class JetCodeStyleSettings extends CustomCodeStyleSettings { public boolean INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD = true; public boolean ALIGN_IN_COLUMNS_CASE_BRANCH = false; + public boolean SPACE_AROUND_WHEN_ARROW = true; + public static JetCodeStyleSettings getInstance(Project project) { return CodeStyleSettingsManager.getSettings(project).getCustomSettings(JetCodeStyleSettings.class); } diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java index 6db9356dbb8..afcb90f39b0 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java @@ -36,11 +36,11 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) { PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(JetLanguage.INSTANCE); JetBlock block = new JetBlock( - containingFile.getNode(), ASTAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings, - createSpacingBuilder(settings)); + containingFile.getNode(), ASTAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings, + createSpacingBuilder(settings)); return FormattingModelProvider.createFormattingModelForPsiFile( - element.getContainingFile(), block, settings); + element.getContainingFile(), block, settings); } private static SpacingBuilder createSpacingBuilder(CodeStyleSettings settings) { @@ -106,7 +106,7 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { .afterInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON) .between(VALUE_ARGUMENT_LIST, FUNCTION_LITERAL_EXPRESSION).spaces(1) - .aroundInside(ARROW, WHEN_ENTRY).spaces(1) + .aroundInside(ARROW, WHEN_ENTRY).spaceIf(jetSettings.SPACE_AROUND_WHEN_ARROW) ; } diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java index fe4ec87aafa..a65cd6bb91b 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java @@ -123,6 +123,9 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti "Insert whitespaces in simple one line methods", CodeStyleSettingsCustomizable.SPACES_OTHER); + consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_AROUND_WHEN_ARROW", + "Surround arrow in \"when\" clause with spaces", + CodeStyleSettingsCustomizable.SPACES_OTHER); break; case WRAPPING_AND_BRACES_SETTINGS: consumer.showStandardOptions( diff --git a/idea/testData/formatter/WhenArrow.kt b/idea/testData/formatter/WhenArrow.kt new file mode 100644 index 00000000000..2db856359b1 --- /dev/null +++ b/idea/testData/formatter/WhenArrow.kt @@ -0,0 +1,8 @@ +fun f(x: Any): Int { + return when (x) { + is Int ->1 + else->0 + } +} + +// SET_FALSE: SPACE_AROUND_WHEN_ARROW \ No newline at end of file diff --git a/idea/testData/formatter/WhenArrow_after.kt b/idea/testData/formatter/WhenArrow_after.kt new file mode 100644 index 00000000000..405fc9833be --- /dev/null +++ b/idea/testData/formatter/WhenArrow_after.kt @@ -0,0 +1,8 @@ +fun f(x: Any): Int { + return when (x) { + is Int->1 + else->0 + } +} + +// SET_FALSE: SPACE_AROUND_WHEN_ARROW \ No newline at end of file diff --git a/idea/testData/formatter/WhenArrow_after_inv.kt b/idea/testData/formatter/WhenArrow_after_inv.kt new file mode 100644 index 00000000000..1a19bc413e7 --- /dev/null +++ b/idea/testData/formatter/WhenArrow_after_inv.kt @@ -0,0 +1,8 @@ +fun f(x: Any): Int { + return when (x) { + is Int -> 1 + else -> 0 + } +} + +// SET_FALSE: SPACE_AROUND_WHEN_ARROW \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java index dba2cdc827e..95afa1cbd09 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java @@ -131,6 +131,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTest(); } + public void testWhenArrow() throws Exception { + doTestWithInvert(); + } + @Override public void doTest() throws Exception { String originalFileText = AbstractJetFormatterTest.loadFile(getTestName(false) + ".kt"); From 965265b8b8e918bb465d8f695016a511ac57dc17 Mon Sep 17 00:00:00 2001 From: sayon Date: Wed, 28 Aug 2013 15:15:16 +0400 Subject: [PATCH 3/6] Formatting: omit blank lines between 'when' and left brace. Test is included. --- .../formatter/JetFormattingModelBuilder.java | 3 +++ .../testData/formatter/WhenLinesBeforeLbrace.kt | 17 +++++++++++++++++ .../formatter/WhenLinesBeforeLbrace_after.kt | 7 +++++++ .../jet/formatter/JetFormatterTest.java | 4 ++++ 4 files changed, 31 insertions(+) create mode 100644 idea/testData/formatter/WhenLinesBeforeLbrace.kt create mode 100644 idea/testData/formatter/WhenLinesBeforeLbrace_after.kt diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java index afcb90f39b0..58082979744 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java @@ -106,7 +106,10 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { .afterInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON) .between(VALUE_ARGUMENT_LIST, FUNCTION_LITERAL_EXPRESSION).spaces(1) + + //when .aroundInside(ARROW, WHEN_ENTRY).spaceIf(jetSettings.SPACE_AROUND_WHEN_ARROW) + .beforeInside(LBRACE, WHEN).spacing(1, 1, 0, true, 0) //omit blank lines before '{' in 'when' statement ; } diff --git a/idea/testData/formatter/WhenLinesBeforeLbrace.kt b/idea/testData/formatter/WhenLinesBeforeLbrace.kt new file mode 100644 index 00000000000..f5da9262b2f --- /dev/null +++ b/idea/testData/formatter/WhenLinesBeforeLbrace.kt @@ -0,0 +1,17 @@ +fun f(x: Any): Int { + return when (x) + + + + + + + + + + + { + is Int->1 + else->0 + } +} \ No newline at end of file diff --git a/idea/testData/formatter/WhenLinesBeforeLbrace_after.kt b/idea/testData/formatter/WhenLinesBeforeLbrace_after.kt new file mode 100644 index 00000000000..1d9ad0a982d --- /dev/null +++ b/idea/testData/formatter/WhenLinesBeforeLbrace_after.kt @@ -0,0 +1,7 @@ +fun f(x: Any): Int { + return when (x) + { + is Int -> 1 + else -> 0 + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java index 95afa1cbd09..d36151e3066 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java @@ -135,6 +135,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTestWithInvert(); } + public void testWhenLinesBeforeLbrace() throws Exception { + doTest(); + } + @Override public void doTest() throws Exception { String originalFileText = AbstractJetFormatterTest.loadFile(getTestName(false) + ".kt"); From 523a5bf6a9847ced6799a4a7ee5a9c9fb1d980f8 Mon Sep 17 00:00:00 2001 From: sayon Date: Tue, 27 Aug 2013 16:22:20 +0400 Subject: [PATCH 4/6] New setting and test: space around arrow in function types --- .../jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java | 2 ++ .../jet/plugin/formatter/JetFormattingModelBuilder.java | 2 ++ .../formatter/JetLanguageCodeStyleSettingsProvider.java | 4 ++++ idea/testData/formatter/FunctionalType.kt | 4 ++++ idea/testData/formatter/FunctionalType_after.kt | 4 ++++ idea/testData/formatter/FunctionalType_after_inv.kt | 4 ++++ idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java | 4 ++++ 7 files changed, 24 insertions(+) create mode 100644 idea/testData/formatter/FunctionalType.kt create mode 100644 idea/testData/formatter/FunctionalType_after.kt create mode 100644 idea/testData/formatter/FunctionalType_after_inv.kt diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java index c04f4e9b829..e6ccc82f97c 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java @@ -34,6 +34,8 @@ public class JetCodeStyleSettings extends CustomCodeStyleSettings { public boolean INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD = true; public boolean ALIGN_IN_COLUMNS_CASE_BRANCH = false; + public boolean SPACE_AROUND_FUNCTION_TYPE_ARROW = true; + public boolean SPACE_AROUND_WHEN_ARROW = true; public static JetCodeStyleSettings getInstance(Project project) { diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java index 58082979744..b810daccb87 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java @@ -110,6 +110,8 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { //when .aroundInside(ARROW, WHEN_ENTRY).spaceIf(jetSettings.SPACE_AROUND_WHEN_ARROW) .beforeInside(LBRACE, WHEN).spacing(1, 1, 0, true, 0) //omit blank lines before '{' in 'when' statement + + .aroundInside(ARROW, FUNCTION_TYPE).spaceIf(jetSettings.SPACE_AROUND_FUNCTION_TYPE_ARROW) ; } diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java index a65cd6bb91b..56b38dbd07e 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java @@ -123,6 +123,10 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti "Insert whitespaces in simple one line methods", CodeStyleSettingsCustomizable.SPACES_OTHER); + consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_AROUND_FUNCTION_TYPE_ARROW", + "Surround arrow in function types with spaces", + CodeStyleSettingsCustomizable.SPACES_OTHER); + consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_AROUND_WHEN_ARROW", "Surround arrow in \"when\" clause with spaces", CodeStyleSettingsCustomizable.SPACES_OTHER); diff --git a/idea/testData/formatter/FunctionalType.kt b/idea/testData/formatter/FunctionalType.kt new file mode 100644 index 00000000000..184133106fd --- /dev/null +++ b/idea/testData/formatter/FunctionalType.kt @@ -0,0 +1,4 @@ +fun test(some: ((Int)->Int) ->Int) { +} + +// SET_TRUE: SPACE_AROUND_FUNCTION_TYPE_ARROW \ No newline at end of file diff --git a/idea/testData/formatter/FunctionalType_after.kt b/idea/testData/formatter/FunctionalType_after.kt new file mode 100644 index 00000000000..8b45a18efd8 --- /dev/null +++ b/idea/testData/formatter/FunctionalType_after.kt @@ -0,0 +1,4 @@ +fun test(some: ((Int) -> Int) -> Int) { +} + +// SET_TRUE: SPACE_AROUND_FUNCTION_TYPE_ARROW \ No newline at end of file diff --git a/idea/testData/formatter/FunctionalType_after_inv.kt b/idea/testData/formatter/FunctionalType_after_inv.kt new file mode 100644 index 00000000000..8bbf78cd2bf --- /dev/null +++ b/idea/testData/formatter/FunctionalType_after_inv.kt @@ -0,0 +1,4 @@ +fun test(some: ((Int)->Int)->Int) { +} + +// SET_TRUE: SPACE_AROUND_FUNCTION_TYPE_ARROW \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java index d36151e3066..ff49ea3c73a 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java @@ -139,6 +139,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTest(); } + public void testFunctionalType() throws Exception { + doTestWithInvert(); + } + @Override public void doTest() throws Exception { String originalFileText = AbstractJetFormatterTest.loadFile(getTestName(false) + ".kt"); From a0500f56d24f6197ce05780cade4eb6c1b6b1c5c Mon Sep 17 00:00:00 2001 From: sayon Date: Tue, 27 Aug 2013 16:22:20 +0400 Subject: [PATCH 5/6] New setting and test: space before lambda arrow #KT-3932 fixed --- .../jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java | 1 + .../jet/plugin/formatter/JetFormattingModelBuilder.java | 1 + .../formatter/JetLanguageCodeStyleSettingsProvider.java | 5 +++++ idea/testData/formatter/LambdaArrow.kt | 3 +++ idea/testData/formatter/LambdaArrow_after.kt | 3 +++ idea/testData/formatter/LambdaArrow_after_inv.kt | 3 +++ idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java | 4 ++++ 7 files changed, 20 insertions(+) create mode 100644 idea/testData/formatter/LambdaArrow.kt create mode 100644 idea/testData/formatter/LambdaArrow_after.kt create mode 100644 idea/testData/formatter/LambdaArrow_after_inv.kt diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java index e6ccc82f97c..a5ddd3afe90 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetCodeStyleSettings.java @@ -37,6 +37,7 @@ public class JetCodeStyleSettings extends CustomCodeStyleSettings { public boolean SPACE_AROUND_FUNCTION_TYPE_ARROW = true; public boolean SPACE_AROUND_WHEN_ARROW = true; + public boolean SPACE_BEFORE_LAMBDA_ARROW = true; public static JetCodeStyleSettings getInstance(Project project) { return CodeStyleSettingsManager.getSettings(project).getCustomSettings(JetCodeStyleSettings.class); diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java index b810daccb87..b254adf099b 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java @@ -106,6 +106,7 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { .afterInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON) .between(VALUE_ARGUMENT_LIST, FUNCTION_LITERAL_EXPRESSION).spaces(1) + .beforeInside(ARROW, FUNCTION_LITERAL).spaceIf(jetSettings.SPACE_BEFORE_LAMBDA_ARROW) //when .aroundInside(ARROW, WHEN_ENTRY).spaceIf(jetSettings.SPACE_AROUND_WHEN_ARROW) diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java index 56b38dbd07e..22d9ad23575 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetLanguageCodeStyleSettingsProvider.java @@ -130,6 +130,11 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_AROUND_WHEN_ARROW", "Surround arrow in \"when\" clause with spaces", CodeStyleSettingsCustomizable.SPACES_OTHER); + + consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_BEFORE_LAMBDA_ARROW", + "Before lambda arrow", + CodeStyleSettingsCustomizable.SPACES_OTHER); + break; case WRAPPING_AND_BRACES_SETTINGS: consumer.showStandardOptions( diff --git a/idea/testData/formatter/LambdaArrow.kt b/idea/testData/formatter/LambdaArrow.kt new file mode 100644 index 00000000000..ccaae3ddf93 --- /dev/null +++ b/idea/testData/formatter/LambdaArrow.kt @@ -0,0 +1,3 @@ +val f: (Int, Int, Int) -> Int = { x, y, z -> x + y + z } + +// SET_FALSE: SPACE_BEFORE_LAMBDA_ARROW \ No newline at end of file diff --git a/idea/testData/formatter/LambdaArrow_after.kt b/idea/testData/formatter/LambdaArrow_after.kt new file mode 100644 index 00000000000..60fd61f3099 --- /dev/null +++ b/idea/testData/formatter/LambdaArrow_after.kt @@ -0,0 +1,3 @@ +val f: (Int, Int, Int) -> Int = { x, y, z-> x + y + z } + +// SET_FALSE: SPACE_BEFORE_LAMBDA_ARROW \ No newline at end of file diff --git a/idea/testData/formatter/LambdaArrow_after_inv.kt b/idea/testData/formatter/LambdaArrow_after_inv.kt new file mode 100644 index 00000000000..c9a3caca990 --- /dev/null +++ b/idea/testData/formatter/LambdaArrow_after_inv.kt @@ -0,0 +1,3 @@ +val f: (Int, Int, Int) -> Int = { x, y, z -> x + y + z } + +// SET_FALSE: SPACE_BEFORE_LAMBDA_ARROW \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java index ff49ea3c73a..860bf045c76 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java @@ -143,6 +143,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTestWithInvert(); } + public void testLambdaArrow() throws Exception { + doTestWithInvert(); + } + @Override public void doTest() throws Exception { String originalFileText = AbstractJetFormatterTest.loadFile(getTestName(false) + ".kt"); From a3bfd258252f98ed47fdc5292980f65eea44440c Mon Sep 17 00:00:00 2001 From: sayon Date: Tue, 27 Aug 2013 17:54:25 +0400 Subject: [PATCH 6/6] Formatter: now always adds space between reference expression and function literal. Test is included. #KT-3932 fixed --- .../jet/plugin/formatter/JetFormattingModelBuilder.java | 2 ++ idea/testData/formatter/ReferenceExpressionFunctionLiteral.kt | 3 +++ .../formatter/ReferenceExpressionFunctionLiteral_after.kt | 3 +++ idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java | 4 ++++ 4 files changed, 12 insertions(+) create mode 100644 idea/testData/formatter/ReferenceExpressionFunctionLiteral.kt create mode 100644 idea/testData/formatter/ReferenceExpressionFunctionLiteral_after.kt diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java index b254adf099b..aa740e1bbb0 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java @@ -113,6 +113,8 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { .beforeInside(LBRACE, WHEN).spacing(1, 1, 0, true, 0) //omit blank lines before '{' in 'when' statement .aroundInside(ARROW, FUNCTION_TYPE).spaceIf(jetSettings.SPACE_AROUND_FUNCTION_TYPE_ARROW) + + .betweenInside(REFERENCE_EXPRESSION, FUNCTION_LITERAL_EXPRESSION, CALL_EXPRESSION).spaces(1) ; } diff --git a/idea/testData/formatter/ReferenceExpressionFunctionLiteral.kt b/idea/testData/formatter/ReferenceExpressionFunctionLiteral.kt new file mode 100644 index 00000000000..226ba86f1e4 --- /dev/null +++ b/idea/testData/formatter/ReferenceExpressionFunctionLiteral.kt @@ -0,0 +1,3 @@ +fun f() { + array(1, 2, 3).map{ v -> v } +} \ No newline at end of file diff --git a/idea/testData/formatter/ReferenceExpressionFunctionLiteral_after.kt b/idea/testData/formatter/ReferenceExpressionFunctionLiteral_after.kt new file mode 100644 index 00000000000..6cc8094939c --- /dev/null +++ b/idea/testData/formatter/ReferenceExpressionFunctionLiteral_after.kt @@ -0,0 +1,3 @@ +fun f() { + array(1, 2, 3).map { v -> v } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java index 860bf045c76..2cee0d234eb 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java @@ -147,6 +147,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTestWithInvert(); } + public void testReferenceExpressionFunctionLiteral() throws Exception { + doTest(); + } + @Override public void doTest() throws Exception { String originalFileText = AbstractJetFormatterTest.loadFile(getTestName(false) + ".kt");