PsiDirectory (final PsiElement psiElement) { if (psiElement instanceof PsiDirectory) { return (PsiDirectory)psiElement; } else if (psiElement != null) { PsiFile containingFile = psiElement.getContainingFile(); if (containingFile != null) { return containingFile.getContainingDirectory(); } } return null; }