BufferedReaderLines (@Nullable PsiExpression condition, @NotNull PsiLoopStatement loopStatement) { PsiBinaryExpression binOp = tryCast(PsiUtil.skipParenthesizedExprDown(condition), PsiBinaryExpression.class); if (binOp == null) return null; if (!JavaTokenType.NE.equals(binOp.getOperationTokenType())) return null; PsiExpression operand = ExpressionUtils.getValueComparedWithNull(binOp); if (operand == null) return null; PsiAssignmentExpression assignment = ExpressionUtils.getAssignment(operand); if (assignment == null) return null; PsiMethodCallExpression readerCall = tryCast(PsiUtil.skipParenthesizedExprDown(assignment.getRExpression()), PsiMethodCallExpression.class); if (!BUFFERED_READER_READ_LINE.test(readerCall)) return null; PsiExpression reader = readerCall.getMethodExpression().getQualifierExpression(); PsiLocalVariable lineVar = ExpressionUtils.resolveLocalVariable(assignment.getLExpression()); if (lineVar == null) return null; if (ReferencesSearch.search(lineVar).anyMatch(ref -> !PsiTreeUtil.isAncestor(loopStatement, ref.getElement(), true))) { return null; } return new BufferedReaderLines(loopStatement, lineVar, reader, false); }