PsiElement (PsiElement element) { if (element instanceof PsiClass) { final PsiDirectory containingDirectory = element.getContainingFile().getContainingDirectory(); return containingDirectory != null ? JavaDirectoryService.getInstance().getPackage(containingDirectory) : null; } return ((PsiPackage)element).getParentPackage(); }