void (PsiFile file) { //PyImportElement myImportElement = findImportElement(editor, file); assert myImportElement != null : "isAvailable() must have returned true, but myImportElement is null"; // usages of imported name are qualifiers; what they refer to? final PyReferenceExpression importReference = myImportElement.getImportReferenceExpression(); if (importReference != null) { myModuleName = PyPsiUtils.toPath(importReference); myQualifierName = myImportElement.getVisibleName(); myReferee = importReference.getReference().resolve(); myHasModuleReference = false; if (myReferee != null && myModuleName != null && myQualifierName != null) { final Collection<PsiReference> references = new ArrayList<>(); PsiTreeUtil.processElements(file, new PsiElementProcessor() { @Override public boolean execute(@NotNull PsiElement element) { if (element instanceof PyReferenceExpression ref && PsiTreeUtil.getParentOfType(element, PyImportElement.class) == null) { if (myQualifierName.equals(PyPsiUtils.toPath(ref))) { // filter out other names that might resolve to our target final PsiElement parentElt = ref.getParent(); if (parentElt instanceof PyQualifiedExpression) { // really qualified by us, not just referencing? final PsiElement resolved = ref.getReference().resolve(); if (resolved == myReferee) references.add(ref.getReference()); } else { myHasModuleReference = true; } } } return true; } }); myReferences = references; } } }