private static void processLanguageSubstitution(final @NotNull VirtualFile file,
                                                  @NotNull Language originalLang,
                                                  final @NotNull Language substitutedLang,
                                                  @NotNull Project project) {
    if (file instanceof VirtualFileWindow) {
      // Injected files are created with substituted language, no need to reparse:
      //   com.intellij.psi.impl.source.tree.injected.MultiHostRegistrarImpl#doneInjecting
      return;
    }
    Key<String> projectKey = getOrCreateProjectKey(project);
    Language prevSubstitutedLang = Language.findLanguageByID(projectKey.get(file));
    final Language prevLang = ObjectUtils.notNull(prevSubstitutedLang, originalLang);
    if (!prevLang.is(substitutedLang)) {
      if (file.replace(projectKey, prevSubstitutedLang != null ? prevSubstitutedLang.getID() : null, substitutedLang.getID())) {
        if (prevSubstitutedLang == null) {
          return; // no need to reparse for the first language substitution
        }
        if (ApplicationManager.getApplication().isUnitTestMode()) {
          return;
        }
        requestReparsing(file, prevLang, substitutedLang);
      }
    }
  }
private static void processLanguageSubstitution(final @NotNull VirtualFile file,
                                                  @NotNull Language originalLang,
                                                  final @NotNull Language substitutedLang,
                                                  @NotNull Project project)