boolean (PsiStatement statement, PsiLoopStatement loop) { if (flowBreaksLoop(statement, loop)) return true; if (loop instanceof PsiForStatement) { // Check that we're inside counted loop which increments some loop variable and // the code is executed under condition like if(var == something) PsiDeclarationStatement initialization = ObjectUtils.tryCast(((PsiForStatement)loop).getInitialization(), PsiDeclarationStatement.class); PsiStatement update = ((PsiForStatement)loop).getUpdate(); if (initialization != null && update != null) { PsiLocalVariable variable = StreamEx.of(initialization.getDeclaredElements()).select(PsiLocalVariable.class) .findFirst(var -> LoopDirection.evaluateLoopDirection(var, update) != null).orElse(null); if (variable != null) { boolean hasLoopVarCheck = conditions(statement).select(PsiBinaryExpression.class) .filter(binOp -> binOp.getOperationTokenType().equals(JavaTokenType.EQEQ)) .anyMatch(binOp -> ExpressionUtils.getOtherOperand(binOp, variable) != null); if (hasLoopVarCheck) { return ReferencesSearch.search(variable).allMatch(ref -> { PsiExpression expression = ObjectUtils.tryCast(ref.getElement(), PsiExpression.class); return expression == null || PsiTreeUtil.isAncestor(update, expression, false) || !PsiUtil.isAccessedForWriting(expression); }); } } } } return false; }