List<OldSwitchStatementBranch> (@NotNull PsiCodeBlock body, PsiSwitchStatement switchStatement) { List<OldSwitchStatementBranch> branches = new ArrayList<>(); PsiStatement[] statements = body.getStatements(); int unmatchedCaseIndex = -1; OldSwitchStatementBranch previousBranch = null; for (int i = 0, length = statements.length; i < length; i++) { PsiStatement current = statements[i]; if (current instanceof PsiSwitchLabelStatement) { if (unmatchedCaseIndex != -1) { boolean isFallthrough = i != 0 && ControlFlowUtils.statementMayCompleteNormally(statements[i - 1]); OldSwitchStatementBranch newBranch = addBranch(branches, statements, unmatchedCaseIndex, i, isFallthrough, null); newBranch.myPreviousSwitchBranch = previousBranch; previousBranch = newBranch; } unmatchedCaseIndex = i; } else if (current instanceof PsiBreakStatement) { if (((PsiBreakStatement)current).findExitedStatement() != switchStatement) return null; if (unmatchedCaseIndex == -1) return null; OldSwitchStatementBranch newBranch = addBranch(branches, statements, unmatchedCaseIndex, i, false, (PsiBreakStatement)current); newBranch.myPreviousSwitchBranch = previousBranch; previousBranch = newBranch; unmatchedCaseIndex = -1; } else if (current instanceof PsiSwitchLabeledRuleStatement) { return null; } } // tail if (unmatchedCaseIndex != -1) { OldSwitchStatementBranch branch = addBranch(branches, statements, unmatchedCaseIndex, statements.length, false, null); branch.myPreviousSwitchBranch = previousBranch; } return branches; }