List<PyTargetExpression> (@NotNull PyFunction function) { final PyFunctionStub stub = function.getStub(); if (stub != null) { return Arrays.asList(stub.getChildrenByType(PyElementTypes.TARGET_EXPRESSION, PyTargetExpression.EMPTY_ARRAY)); } else { final PyStatementList statementList = function.getStatementList(); final List<PyTargetExpression> result = new ArrayList<>(); statementList.accept(new PyRecursiveElementVisitor() { @Override public void visitPyClass(@NotNull PyClass node) { } @Override public void visitPyAssignmentStatement(final @NotNull PyAssignmentStatement node) { for (PyExpression expression : node.getTargets()) { if (expression instanceof PyTargetExpression) { result.add((PyTargetExpression)expression); } } } @Override public void visitPyWithStatement(@NotNull PyWithStatement node) { StreamEx .of(node.getWithItems()) .map(PyWithItem::getTarget) .select(PyTargetExpression.class) .forEach(result::add); super.visitPyWithStatement(node); } }); return result; } }