PsiDirectory (final PsiElement psiElement) { if (psiElement instanceof PsiPackage) { final PsiDirectory[] directories = ((PsiPackage)psiElement).getDirectories(); return directories.length == 1 ? directories[0] : null; //?? } if (psiElement instanceof PsiDirectory) { return (PsiDirectory)psiElement; } if (psiElement != null) { return psiElement.getContainingFile().getContainingDirectory(); } return null; }