Extract method for else branch check in when expression

This commit is contained in:
Alexey Sedunov
2013-04-12 18:42:35 +04:00
parent edea00f53e
commit 033e82666d
4 changed files with 19 additions and 26 deletions
@@ -3626,13 +3626,7 @@ The "returned" value of try expression with no finally is either the last expres
}
Label end = new Label();
boolean hasElse = false;
for (JetWhenEntry whenEntry : expression.getEntries()) {
if (whenEntry.isElse()) {
hasElse = true;
break;
}
}
boolean hasElse = JetPsiUtil.checkWhenExpressionHasSingleElse(expression);
Label nextCondition = null;
for (JetWhenEntry whenEntry : expression.getEntries()) {
@@ -682,4 +682,14 @@ public class JetPsiUtil {
return false;
}
public static boolean checkWhenExpressionHasSingleElse(JetWhenExpression whenExpression) {
int elseCount = 0;
for (JetWhenEntry entry : whenExpression.getEntries()) {
if (entry.isElse()) {
elseCount++;
}
}
return (elseCount == 1);
}
}