PsiElement (@NotNull PsiElement element) { if (element instanceof PsiPackage) return element; if (element instanceof PsiDirectory) { final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element); if (psiPackage != null) return psiPackage; } if (!(element instanceof PsiMember) && element.getParent() instanceof PsiMember) { return element.getParent(); } return null; }