From 36b68786b04a842baad380123baae6fbc57a9e47 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Fri, 26 Apr 2013 13:40:12 +0400 Subject: [PATCH] Add new-line flags to 'if' factory method --- .../jetbrains/jet/lang/psi/JetPsiFactory.java | 16 ++++++++++++---- .../BranchedFoldingUtils.java | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.java index 6e5a58a2056..bbbb945a3d6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.java @@ -307,14 +307,22 @@ public class JetPsiFactory { } @NotNull - public static JetIfExpression createIf(Project project, @NotNull String condText, @NotNull String thenText, @Nullable String elseText) { - return (JetIfExpression) createExpression(project, "if (" + condText + ") " + thenText + (elseText != null ? " else " + elseText : "")); + public static JetIfExpression createIf( + Project project, + @NotNull String condText, @NotNull String thenText, @Nullable String elseText, + boolean thenNewLine, boolean elseNewLine) { + String thenSpace = thenNewLine ? "\n" : " "; + String elseSpace = elseNewLine ? "\n" : " "; + return (JetIfExpression) createExpression(project, "if (" + condText + ")" + thenSpace + thenText + (elseText != null ? elseSpace + "else " + elseText : "")); } @SuppressWarnings("ConstantConditions") @NotNull - public static JetIfExpression createIf(Project project, @NotNull JetExpression condition, @NotNull JetExpression thenExpr, @Nullable JetExpression elseExpr) { - JetIfExpression ifExpr = createIf(project, "_", "_", elseExpr != null ? "_" : null); + public static JetIfExpression createIf( + Project project, + @NotNull JetExpression condition, @NotNull JetExpression thenExpr, @Nullable JetExpression elseExpr, + boolean thenNewLine, boolean elseNewLine) { + JetIfExpression ifExpr = createIf(project, "_", "_", elseExpr != null ? "_" : null, thenNewLine, elseNewLine); assert ifExpr.getCondition() != null; assert ifExpr.getThen() != null; diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/BranchedFoldingUtils.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/BranchedFoldingUtils.java index f22bf545edd..402a4094cae 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/BranchedFoldingUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/BranchedFoldingUtils.java @@ -239,7 +239,7 @@ public class BranchedFoldingUtils { assertNotNull(elseRoot); //noinspection ConstantConditions - JetIfExpression newIfExpression = JetPsiFactory.createIf(project, condition, thenRoot, elseRoot); + JetIfExpression newIfExpression = JetPsiFactory.createIf(project, condition, thenRoot, elseRoot, false, false); JetReturnExpression newReturnExpression = JetPsiFactory.createReturn(project, newIfExpression); newIfExpression = (JetIfExpression)newReturnExpression.getReturnedExpression();