@Nullable
 private static LanguageFileType substituteFileType(
     Language language, VirtualFile vFile, Project project) {
   LanguageFileType fileType = null;
   if (vFile != null && project != null) {
     Language substLanguage =
         LanguageSubstitutors.INSTANCE.substituteLanguage(language, vFile, project);
     if (substLanguage != language) {
       fileType = substLanguage.getAssociatedFileType();
     }
   }
   return fileType;
 }
 @NotNull
 public static PsiFile createFileFromText(
     @NotNull Project project,
     @NotNull CharSequence text,
     @NotNull LanguageFileType fileType,
     @NotNull VirtualFile file,
     @NotNull String fileName) {
   final Language language = fileType.getLanguage();
   final Language substitutedLanguage =
       LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
   return PsiFileFactory.getInstance(project)
       .createFileFromText(fileName, substitutedLanguage, text, false, false, true, file);
 }
  @NotNull
  public static FileType substituteFileType(
      VirtualFile file, @NotNull FileType fileType, Project project) {
    if (project == null) {
      return fileType;
    }
    if (fileType instanceof LanguageFileType) {
      final Language language = ((LanguageFileType) fileType).getLanguage();
      final Language substitutedLanguage =
          LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
      LanguageFileType substFileType = substitutedLanguage.getAssociatedFileType();
      if (!substitutedLanguage.equals(language) && substFileType != null) {
        return new SubstitutedFileType(fileType, substFileType);
      }
    }

    return fileType;
  }