void (@NotNull PyReferenceExpression node, @NotNull PsiElement element) { // We will remember reference in deepest node (except for references to PyImportedModules, as we need references to modules, not to // their packages) final PyExpression qualifier = node.getQualifier(); if (qualifier != null && !(resolveExpression(qualifier) instanceof PyImportedModule)) { return; } final List<PsiElement> allResolveResults = multiResolveExpression(node); PsiElement target = ContainerUtil.getFirstItem(allResolveResults); if (target instanceof PsiNamedElement && !PsiTreeUtil.isAncestor(element, target, false)) { final PyImportedNameDefiner importElement = getImportElement(node); if (!PyUtil.inSameFile(element, target) && importElement == null && !(target instanceof PsiFileSystemItem)) { return; } if (target instanceof PyTargetExpression && PyNames.ALL.equals(((PyTargetExpression)target).getName())) { for (PsiElement result : allResolveResults) { if (result instanceof PyImportElement) { final QualifiedName importedQName = ((PyImportElement)result).getImportedQName(); if (importedQName != null) { target = new DynamicNamedElement(target.getContainingFile(), importedQName.toString()); break; } } } } node.putCopyableUserData(ENCODED_IMPORT, (PsiNamedElement)target); if (importElement instanceof PyImportElement) { node.putCopyableUserData(ENCODED_IMPORT_AS, ((PyImportElement)importElement).getAsName()); } node.putCopyableUserData(ENCODED_USE_FROM_IMPORT, qualifier == null); } }