boolean (PsiSwitchBlock switchStatement, PsiStatement statement) { if (switchStatement instanceof PsiSwitchExpression) { // any breaks inside switch expressions are not convertible return false; } PsiElement parent = statement.getParent(); if (parent instanceof PsiSwitchLabeledRuleStatement) { return true; } if (parent instanceof PsiIfStatement || parent instanceof PsiLabeledStatement) { return isRemovable(switchStatement, (PsiStatement)parent); } PsiStatement nextStatement = PsiTreeUtil.getNextSiblingOfType(statement, PsiStatement.class); if (nextStatement == null) { if (parent instanceof PsiCodeBlock) { PsiElement grandParent = parent.getParent(); return grandParent == switchStatement || grandParent instanceof PsiBlockStatement && isRemovable(switchStatement, (PsiStatement)grandParent); } } if (nextStatement instanceof PsiSwitchLabelStatement) { return ((PsiSwitchLabelStatement)nextStatement).getEnclosingSwitchBlock() == switchStatement && !ControlFlowUtils.statementMayCompleteNormally(statement); } if (nextStatement instanceof PsiBreakStatement) { return ((PsiBreakStatement)nextStatement).findExitedStatement() == switchStatement; } return false; }