PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!HighlightingFeature.SWITCH_EXPRESSION.isAvailable(holder.getFile())) return PsiElementVisitor.EMPTY_VISITOR; return new JavaElementVisitor() { @Override public void visitSwitchExpression(@NotNull PsiSwitchExpression expression) { processBlock(expression); } @Override public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) { processBlock(statement); } private void processBlock(PsiSwitchBlock block) { List<PsiExpression> branches = extractBranches(block); if (branches == null) return; PsiExpression[] diffs = findDiffs(block, branches); if (diffs.length != 0) { holder.registerProblem(block.getFirstChild(), InspectionGadgetsBundle.message("inspection.common.subexpression.in.switch.display.name"), new PushDownSwitchExpressionFix()); } } }; }