PsiDirectory (PsiElement element) { PsiFile file = InjectedLanguageManager.getInstance(element.getProject()).getTopLevelFile(element); if (file != null) { element = file.getOriginalFile(); } while (element != null && !(element instanceof PsiDirectory)) { element = element.getParent(); } return (PsiDirectory)element; }