PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitSwitchExpression(@NotNull PsiSwitchExpression expression) { if (!isNonemptyRuleFormatSwitch(expression)) return; if (findReplacer(expression) == null) return; String message = JavaBundle.message("inspection.switch.expression.backward.expression.migration.inspection.name"); holder.registerProblem(expression.getFirstChild(), message, new ReplaceWithOldStyleSwitchFix()); } @Override public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) { if (!isNonemptyRuleFormatSwitch(statement)) return; if (findReplacer(statement) == null) return; String message = JavaBundle.message("inspection.switch.expression.backward.statement.migration.inspection.name"); holder.registerProblem(statement.getFirstChild(), message, new ReplaceWithOldStyleSwitchFix()); } private static boolean isNonemptyRuleFormatSwitch(PsiSwitchBlock block) { PsiSwitchLabelStatementBase label = PsiTreeUtil.getChildOfType(block.getBody(), PsiSwitchLabelStatementBase.class); return label instanceof PsiSwitchLabeledRuleStatement; } }; }