Add new-line flags to 'if' factory method

This commit is contained in:
Alexey Sedunov
2013-04-26 13:40:12 +04:00
parent 057528eb39
commit 36b68786b0
2 changed files with 13 additions and 5 deletions
@@ -307,14 +307,22 @@ public class JetPsiFactory {
} }
@NotNull @NotNull
public static JetIfExpression createIf(Project project, @NotNull String condText, @NotNull String thenText, @Nullable String elseText) { public static JetIfExpression createIf(
return (JetIfExpression) createExpression(project, "if (" + condText + ") " + thenText + (elseText != null ? " else " + elseText : "")); 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") @SuppressWarnings("ConstantConditions")
@NotNull @NotNull
public static JetIfExpression createIf(Project project, @NotNull JetExpression condition, @NotNull JetExpression thenExpr, @Nullable JetExpression elseExpr) { public static JetIfExpression createIf(
JetIfExpression ifExpr = createIf(project, "_", "_", elseExpr != null ? "_" : null); 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.getCondition() != null;
assert ifExpr.getThen() != null; assert ifExpr.getThen() != null;
@@ -239,7 +239,7 @@ public class BranchedFoldingUtils {
assertNotNull(elseRoot); assertNotNull(elseRoot);
//noinspection ConstantConditions //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); JetReturnExpression newReturnExpression = JetPsiFactory.createReturn(project, newIfExpression);
newIfExpression = (JetIfExpression)newReturnExpression.getReturnedExpression(); newIfExpression = (JetIfExpression)newReturnExpression.getReturnedExpression();