PsiNamedElement (Iterable<? extends PsiNamedElement> it, String name) { PsiNamedElement ret = null; for (PsiNamedElement elt : it) { if (elt != null) { // qualified refs don't match by last name, and we're not checking FQNs here if (elt instanceof PyQualifiedExpression && ((PyQualifiedExpression)elt).isQualified()) continue; if (name.equals(elt.getName())) { // plain name matches ret = elt; break; } } } return ret; }