PsiPackage (@NotNull PsiDirectory dir) { Project project = dir.getProject(); VirtualFile file = dir.getVirtualFile(); if (file instanceof LightVirtualFile lvf && lvf.getOriginalFile() != null) { file = lvf.getOriginalFile(); } String packageName = PackageIndex.getInstance(project).getPackageNameByDirectory(file); if (packageName == null) return null; return JavaPsiFacade.getInstance(project).findPackage(packageName); }