PsiFile (@NotNull Project project, @NotNull CharSequence text, @NotNull LanguageFileType fileType, @NotNull VirtualFile file, @NotNull String fileName) { final Language language = fileType.getLanguage(); final Language substitutedLanguage = LanguageSubstitutors.getInstance().substituteLanguage(language, file, project); PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText( fileName, substitutedLanguage, text, false, false, false, file ); if (psiFile == null) { throw new IllegalStateException("psiFile is null. language = " + language.getID() + ", substitutedLanguage = " + substitutedLanguage.getID()); } return psiFile; }