List<PyElement> (PyFile file) { List<PyElement> result = new ArrayList<>(); for (PyClass cls : file.getTopLevelClasses()) { if (isDocTestClass(cls)) { result.add(cls); } } for (PyFunction cls : file.getTopLevelFunctions()) { if (isDocTestFunction(cls)) { result.add(cls); } } if (file.getDocStringExpression() != null) { PyStringLiteralExpression docString = file.getDocStringExpression(); if (docString != null && hasExample(docString.getStringValue())) { result.add(file); } } return result; }