boolean (@NotNull PsiElement element, @Nullable String elementName, @NotNull ScopeOwner ourScopeOwner, @NotNull ScopeOwner theirScopeOwner, @Nullable PsiElement resolveResult) { // Handle situations when there is no top-level declaration for globals and transitive resolve doesn't help final PsiFile ourFile = getElement().getContainingFile(); final PsiFile theirFile = element.getContainingFile(); if (ourFile == theirFile) { final boolean ourIsGlobal = ControlFlowCache.getScope(ourScopeOwner).isGlobal(elementName); final boolean theirIsGlobal = ControlFlowCache.getScope(theirScopeOwner).isGlobal(elementName); if (ourIsGlobal && theirIsGlobal) { return true; } } final var resolvedScopeOwner = ScopeUtil.getScopeOwner(resolveResult); if (resolvedScopeOwner != null && resolveResult.getContainingFile() == theirFile) { if (ControlFlowCache.getScope(resolvedScopeOwner).isGlobal(elementName) && ControlFlowCache.getScope(theirScopeOwner).isGlobal(elementName)) { return true; } } if (resolvedScopeOwner == ourFile && ControlFlowCache.getScope(theirScopeOwner).isGlobal(elementName)) { return true; } return false; }