From 72fb2c0d02d96b2a927c51aac59056d00060e3a6 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 17 Sep 2012 11:27:38 +0400 Subject: [PATCH] KT-2242 Fix {(a: Int) -> a } case #KT-2242 Fixed --- .../org/jetbrains/jet/plugin/formatter/JetBlock.java | 11 +++++++++-- idea/testData/formatter/SingleLineFunctionLiteral.kt | 2 ++ .../formatter/SingleLineFunctionLiteral_after.kt | 2 ++ .../formatter/SingleLineFunctionLiteral_after_inv.kt | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java index 3365b6041ba..19919fc3b43 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java @@ -32,8 +32,7 @@ import org.jetbrains.jet.plugin.JetLanguage; import java.util.*; -import static org.jetbrains.jet.JetNodeTypes.BLOCK; -import static org.jetbrains.jet.JetNodeTypes.FUNCTION_LITERAL; +import static org.jetbrains.jet.JetNodeTypes.*; import static org.jetbrains.jet.lexer.JetTokens.*; /** @@ -166,6 +165,14 @@ public class JetBlock extends AbstractBlock { } if (parentType == FUNCTION_LITERAL && child1Type == LBRACE) { + if (child2Type == VALUE_PARAMETER_LIST) { + ASTNode firstParamListNode = ((ASTBlock) child2).getNode().getFirstChildNode(); + if (firstParamListNode != null && firstParamListNode.getElementType() == LPAR) { + // Don't put space for situation {(a: Int) -> a } + return Spacing.createSpacing(0, 0, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); + } + } + return Spacing.createSpacing(spacesInSimpleMethod, spacesInSimpleMethod, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } diff --git a/idea/testData/formatter/SingleLineFunctionLiteral.kt b/idea/testData/formatter/SingleLineFunctionLiteral.kt index 07a52f68fa3..ae2b67ff4a7 100644 --- a/idea/testData/formatter/SingleLineFunctionLiteral.kt +++ b/idea/testData/formatter/SingleLineFunctionLiteral.kt @@ -2,5 +2,7 @@ fun test(some: (Int) -> Int) { } fun foo() = test() { it } +val function = test { (a: Int) -> a } +val function1 = test {a : Int -> a} // SET_TRUE: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD \ No newline at end of file diff --git a/idea/testData/formatter/SingleLineFunctionLiteral_after.kt b/idea/testData/formatter/SingleLineFunctionLiteral_after.kt index 07a52f68fa3..6924202c419 100644 --- a/idea/testData/formatter/SingleLineFunctionLiteral_after.kt +++ b/idea/testData/formatter/SingleLineFunctionLiteral_after.kt @@ -2,5 +2,7 @@ fun test(some: (Int) -> Int) { } fun foo() = test() { it } +val function = test {(a: Int) -> a } +val function1 = test { a : Int -> a } // SET_TRUE: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD \ No newline at end of file diff --git a/idea/testData/formatter/SingleLineFunctionLiteral_after_inv.kt b/idea/testData/formatter/SingleLineFunctionLiteral_after_inv.kt index 55751353d14..ee26dd90c10 100644 --- a/idea/testData/formatter/SingleLineFunctionLiteral_after_inv.kt +++ b/idea/testData/formatter/SingleLineFunctionLiteral_after_inv.kt @@ -2,5 +2,7 @@ fun test(some: (Int) -> Int) { } fun foo() = test() {it} +val function = test {(a: Int) -> a} +val function1 = test {a : Int -> a} // SET_TRUE: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD \ No newline at end of file