PsiElement (final String name) { final List<RatedResolveResult> results = multiResolveName(name); final List<PsiElement> elements = PyUtil.filterTopPriorityResults(results.toArray(ResolveResult.EMPTY_ARRAY)); final PsiElement element = elements.isEmpty() ? null : elements.get(elements.size() - 1); if (element != null) { if (!element.isValid()) { throw new PsiInvalidElementAccessException(element); } return element; } return null; }