private static boolean checkFoldableWhenExpressionWithReturns(JetWhenExpression whenExpression) { if (!JetPsiUtil.checkWhenExpressionHasSingleElse(whenExpression)) return false; List<JetWhenEntry> entries = whenExpression.getEntries(); if (entries.isEmpty()) return false; for (JetWhenEntry entry : entries) { if (getFoldableBranchedReturn(entry.getExpression()) == null) return false; } return true; }
private static boolean checkFoldableWhenExpressionWithAssignments( JetWhenExpression whenExpression) { if (!JetPsiUtil.checkWhenExpressionHasSingleElse(whenExpression)) return false; List<JetWhenEntry> entries = whenExpression.getEntries(); if (entries.isEmpty()) return false; List<JetBinaryExpression> assignments = new ArrayList<JetBinaryExpression>(); for (JetWhenEntry entry : entries) { JetBinaryExpression assignment = getFoldableBranchedAssignment(entry.getExpression()); if (assignment == null) return false; assignments.add(assignment); } assert !assignments.isEmpty(); JetBinaryExpression firstAssignment = assignments.get(0); for (JetBinaryExpression assignment : assignments) { if (!checkAssignmentsMatch(assignment, firstAssignment)) return false; } return true; }