BufferedReaderLines (PsiLoopStatement loopStatement) { PsiForStatement forLoop = tryCast(loopStatement, PsiForStatement.class); if (forLoop == null || forLoop.getUpdate() != null) return null; BufferedReaderLines reader = extractReaderFromCondition(forLoop.getCondition(), loopStatement); if (reader == null) return null; PsiDeclarationStatement declaration = tryCast(forLoop.getInitialization(), PsiDeclarationStatement.class); if (declaration == null) return null; PsiElement[] declaredElements = declaration.getDeclaredElements(); if (declaredElements.length != 1) return null; PsiVariable lineVar = reader.getVariable(); if (declaredElements[0] != lineVar) return null; return reader; }