BreakConverter (PsiSwitchBlock switchStatement) { String replacement = switchStatement instanceof PsiSwitchStatement ? getReplacement((PsiStatement)switchStatement) : null; if (replacement == null) { class Visitor extends JavaRecursiveElementWalkingVisitor { boolean hasNonRemovableBreak; @Override public void visitBreakStatement(@NotNull PsiBreakStatement statement) { super.visitBreakStatement(statement); if (statement.findExitedStatement() == switchStatement && !isRemovable(switchStatement, statement)) { hasNonRemovableBreak = true; stopWalking(); } } @Override public void visitExpression(@NotNull PsiExpression expression) { // Going down into any expression seems redundant } @Override public void visitClass(@NotNull PsiClass aClass) {} } Visitor visitor = new Visitor(); switchStatement.accept(visitor); if (visitor.hasNonRemovableBreak) return null; } return new BreakConverter(switchStatement, replacement); }