PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitForStatement(@NotNull PsiForStatement statement) { visitLoop(statement, statement.getFirstChild()); } @Override public void visitWhileStatement(@NotNull PsiWhileStatement statement) { visitLoop(statement, statement.getFirstChild()); } @Override public void visitDoWhileStatement(@NotNull PsiDoWhileStatement statement) { visitLoop(statement, statement.getWhileKeyword()); } private void visitLoop(@NotNull PsiConditionalLoopStatement loopStatement, @Nullable PsiElement keyword) { if (keyword == null) return; Context context = Context.from(loopStatement, noConversionToDoWhile, suggestConversionWhenIfIsASingleStmtInLoop); if (context == null) return; LocalQuickFix[] fixes; if (context.conditionInTheBeginning) { fixes = new LocalQuickFix[]{new LoopTransformationFix(noConversionToDoWhile)}; } else { var setInspectionOptionFix = new UpdateInspectionOptionFix( ConditionalBreakInInfiniteLoopInspection.this, "noConversionToDoWhile", JavaBundle.message("inspection.conditional.break.in.infinite.loop.no.conversion.with.do.while"), true); fixes = new LocalQuickFix[]{new LoopTransformationFix(noConversionToDoWhile), LocalQuickFix.from(setInspectionOptionFix)}; } ProblemHighlightType highlightType; if (!allowConditionFusion && !context.isInfiniteLoop) { if (holder.isOnTheFly()) { highlightType = ProblemHighlightType.INFORMATION; } else { return; } } else { highlightType = ProblemHighlightType.GENERIC_ERROR_OR_WARNING; } holder.registerProblem(keyword, JavaBundle.message("inspection.conditional.break.in.infinite.loop.description"), highlightType, fixes); } }; }