PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!HighlightingFeature.ENHANCED_SWITCH.isAvailable(holder.getFile())) return PsiElementVisitor.EMPTY_VISITOR; return new JavaElementVisitor() { @Override public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) { PsiElement switchKeyword = statement.getFirstChild(); if (switchKeyword == null) { return; } List<SwitchReplacer> replacers = findSwitchReplacers(statement, myMaxNumberStatementsForBranch); if (replacers.isEmpty()) return; Optional<SwitchReplacer> replacerWithWarningLevel = replacers.stream().filter(t -> isWarningLevel(t)).findFirst(); if (replacerWithWarningLevel.isPresent()) { SwitchReplacer replacer = replacerWithWarningLevel.get(); List<LocalQuickFix> fixes = new ArrayList<>(); fixes.add(new ReplaceWithSwitchExpressionFix(replacer.getType())); if (!myWarnOnlyOnExpressionConversion && replacer.getType() == ReplacementType.Statement) { fixes.add(LocalQuickFix.from(new UpdateInspectionOptionFix( EnhancedSwitchMigrationInspection.this, "myWarnOnlyOnExpressionConversion", JavaBundle.message("inspection.switch.expression.migration.warn.only.on.expression"), true))); } if (replacer.getType() == ReplacementType.Expression && replacer.getMaxNumberStatementsInBranch() != null && replacer.getMaxNumberStatementsInBranch() > 1) { int newMaxValue = replacer.getMaxNumberStatementsInBranch() - 1; fixes.add(LocalQuickFix.from(new UpdateInspectionOptionFix( EnhancedSwitchMigrationInspection.this, "myMaxNumberStatementsForBranch", JavaBundle.message("inspection.switch.expression.migration.option.expression.max.statements", newMaxValue), newMaxValue))); } holder.registerProblem(switchKeyword, JavaBundle.message("inspection.switch.expression.migration.inspection.switch.description"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fixes.toArray(LocalQuickFix.EMPTY_ARRAY)); replacers.remove(replacer); } if (!holder.isOnTheFly()) { return; } if (replacers.isEmpty()) { return; } List<LocalQuickFix> fixes = ContainerUtil.map(replacers, replacer -> new ReplaceWithSwitchExpressionFix(replacer.getType())); holder.registerProblem(switchKeyword, JavaBundle.message("inspection.switch.expression.migration.inspection.switch.description"), ProblemHighlightType.INFORMATION, fixes.toArray(LocalQuickFix.EMPTY_ARRAY)); } private boolean isWarningLevel(@NotNull SwitchReplacer replacer) { if (replacer.isInformLevel()) { return false; } return !(myWarnOnlyOnExpressionConversion && replacer.getType() == ReplacementType.Statement); } }; }