boolean (@NotNull PsiElement element1, @NotNull PsiElement element2) { PsiFile file1 = FileContextUtil.getContextFile(element1); PsiFile file2 = FileContextUtil.getContextFile(element2); if (Comparing.equal(file1, file2)) return true; if (file1 instanceof JavaDummyHolder && file2 instanceof JavaDummyHolder) return true; if (file1 instanceof JavaDummyHolder || file2 instanceof JavaDummyHolder) { JavaDummyHolder dummyHolder = (JavaDummyHolder) (file1 instanceof JavaDummyHolder ? file1 : file2); PsiElement other = file1 instanceof JavaDummyHolder ? file2 : file1; return dummyHolder.isSamePackage(other); } if (!(file1 instanceof PsiClassOwner)) return false; if (!(file2 instanceof PsiClassOwner)) return false; String package1 = ((PsiClassOwner) file1).getPackageName(); String package2 = ((PsiClassOwner) file2).getPackageName(); return Objects.equals(package1, package2); }