IterateStreamSource (@NotNull PsiForStatement forStatement) { PsiExpression condition = forStatement.getCondition(); if (!PsiUtil.isLanguageLevel9OrHigher(forStatement) && condition != null) return null; PsiStatement initialization = forStatement.getInitialization(); PsiDeclarationStatement initStmt = tryCast(initialization, PsiDeclarationStatement.class); if (initStmt == null || initStmt.getDeclaredElements().length != 1) return null; PsiLocalVariable variable = tryCast(initStmt.getDeclaredElements()[0], PsiLocalVariable.class); if (variable == null) return null; if (StreamApiUtil.getStreamClassForType(variable.getType()) == null) return null; PsiExpression initializer = variable.getInitializer(); if (initializer == null) return null; PsiStatement update = forStatement.getUpdate(); if (update == null) return null; PsiExpressionStatement exprStmt = tryCast(update, PsiExpressionStatement.class); if (exprStmt == null) return null; PsiExpression expression = exprStmt.getExpression(); PsiExpression updateExpr = null; IElementType op; PsiUnaryExpression unaryExpression = null; if (expression instanceof PsiAssignmentExpression assignment) { op = TypeConversionUtil.convertEQtoOperation(assignment.getOperationTokenType()); updateExpr = assignment.getRExpression(); if (!ExpressionUtils.isReferenceTo(assignment.getLExpression(), variable)) return null; if (updateExpr == null) return null; } else if (expression instanceof PsiUnaryExpression) { unaryExpression = (PsiUnaryExpression)expression; IElementType tokenType = unaryExpression.getOperationTokenType(); op = getOperation(tokenType); if (op == null) return null; } else { return null; } if (updateExpr != null && !ExceptionUtil.getThrownCheckedExceptions(updateExpr).isEmpty()) return null; if (condition != null && !ExceptionUtil.getThrownCheckedExceptions(condition).isEmpty()) return null; if (!VariableAccessUtils.variableIsUsed(variable, update)) return null; return new IterateStreamSource(forStatement, variable, updateExpr, initializer, condition, op, unaryExpression); }