PsiDirectory () { final PsiDirectoryFactory manager = PsiDirectoryFactory.getInstance(myProject); PsiDirectory directory = myDirectory; PsiDirectory parent = directory.getParent(); while (parent != null && manager.isPackage(parent)) { directory = parent; parent = parent.getParent(); } return directory; }