Collection<PyElement> (final PyElement element) { Collection<PyElement> children = new LinkedHashSet<>(); PyPsiUtils.assertValid(element); element.acceptChildren(new PyElementVisitor() { @Override public void visitElement(@NotNull PsiElement e) { if (isWorthyItem(e, element)) { children.add((PyElement)e); } else { e.acceptChildren(this); } } }); if (element instanceof PyClass) { final List<PyElement> attrs = getClassAttributes((PyClass)element); final List<PyElement> filtered = new ArrayList<>(); final Set<String> names = new HashSet<>(); for (PyElement attr : attrs) { final String name = attr.getName(); PyPsiUtils.assertValid(attr); if (!names.contains(name)) { filtered.add(attr); } names.add(name); } final Comparator<PyElement> comparator = (e1, e2) -> { final String n1 = e1.getName(); final String n2 = e2.getName(); return (n1 != null && n2 != null) ? n1.compareTo(n2) : 0; }; filtered.sort(comparator); children.addAll(filtered); } return children; }