PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitForStatement(@NotNull PsiForStatement statement) { PsiExpressionStatement updateStatement = tryCast(statement.getUpdate(), PsiExpressionStatement.class); if (updateStatement == null) return; PsiExpression updateExpression = updateStatement.getExpression(); PsiLocalVariable indexVariable = findIndexVariable(updateExpression); if (indexVariable == null) return; PsiType type = indexVariable.getType(); if (!type.equals(PsiTypes.intType()) && !type.equals(PsiTypes.longType())) return; ConditionType conditionType = getConditionType(statement.getCondition(), indexVariable); if (conditionType == ConditionType.Unknown) return; if (!notChangesMonotony(conditionType, updateExpression)) return; if (indexUpdatedInBody(statement, indexVariable, conditionType)) return; holder.registerProblem(statement.getFirstChild(), JavaBundle.message("inspection.overflowing.loop.index.inspection.description")); } }; }