void (int offset, PsiElement element, final Collection<PsiReference> outReferences, PyResolveContext resolveContext) { final PsiReference[] references; if (element instanceof PyReferenceOwner owner) { final PsiPolyVariantReference reference = owner.getReference(resolveContext); references = new PsiReference[]{reference}; } else { references = element.getReferences(); } for (final PsiReference reference : references) { for (TextRange range : ReferenceRange.getRanges(reference)) { assert range != null : reference; if (range.containsOffset(offset)) { outReferences.add(reference); } } } }