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
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;
@@ -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();