MarkdownFile (@NotNull Project project, @NotNull String text) { final LightVirtualFile virtualFile = new LightVirtualFile("temp.rb", MarkdownLanguage.INSTANCE, text); PsiFile psiFile = ((PsiFileFactoryImpl)PsiFileFactory.getInstance(project)) .trySetupPsiForFile(virtualFile, MarkdownLanguage.INSTANCE, true, true); if (!(psiFile instanceof MarkdownFile)) { throw new RuntimeException("Cannot create a new markdown file. Text: " + text); } return (MarkdownFile)psiFile; }