private static ASTNode @NotNull [] parseFile(@NotNull Language language, Language forcedLanguage,
                                               @NotNull DocumentWindowImpl documentWindow,
                                               @NotNull VirtualFile hostVirtualFile,
                                               @NotNull DocumentEx hostDocument, @NotNull PsiFile hostPsiFile,
                                               @NotNull Project project,
                                               @NotNull CharSequence documentText,
                                               @NotNull List<PlaceInfo> placeInfos,
                                               @NotNull StringBuilder decodedChars,
                                               @NotNull String fileName, @NotNull PsiDocumentManagerBase documentManager) {
    VirtualFileWindowImpl virtualFile = new VirtualFileWindowImpl(fileName, hostVirtualFile, documentWindow, language, decodedChars);
    Language finalLanguage = forcedLanguage == null ? LanguageSubstitutors.getInstance().substituteLanguage(language, virtualFile, project) : forcedLanguage;
    InjectedFileViewProvider viewProvider = InjectedFileViewProvider.create(PsiManagerEx.getInstanceEx(project), virtualFile, documentWindow, finalLanguage);
    Set<Language> languages = viewProvider.getLanguages();
    ASTNode[] parsedNodes = new ASTNode[languages.size()];

    int i = 0;
    for (Language lang : languages) {
      ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
      assert parserDefinition != null : "Parser definition for language " + finalLanguage + " is null";
      PsiFileImpl psiFile = (PsiFileImpl)parserDefinition.createFile(viewProvider);
      if (viewProvider instanceof TemplateLanguageFileViewProvider) {
        IElementType elementType = ((TemplateLanguageFileViewProvider)viewProvider).getContentElementType(lang);
        if (elementType != null) {
          psiFile.setContentElementType(elementType);
        }
      }
      ASTNode parsedNode = keepTreeFromChameleoningBack(psiFile);

      assert parsedNode instanceof FileElement : "Parsed to " + parsedNode + " instead of FileElement";

      assert ((FileElement)parsedNode).textMatches(decodedChars) : exceptionContext("Before patch: doc:\n'" + documentText + "'\n---PSI:\n'" + parsedNode.getText() + "'\n---chars:\n'" +
                                                                                    decodedChars + "'",
                                                                                    finalLanguage, hostPsiFile, hostVirtualFile,
                                                                                    hostDocument, placeInfos, documentManager);
      try {
        patchLeaves(placeInfos, viewProvider, parsedNode, documentText);
      }
      catch (PatchException e) {
        throw new RuntimeException(exceptionContext(e.getMessage()+"'\n---chars:\n'" + decodedChars + "'", finalLanguage, hostPsiFile, hostVirtualFile, hostDocument, placeInfos,
                                                    documentManager));
      }

      try {
        List<InjectedLanguageUtilBase.TokenInfo> tokens = obtainHighlightTokensFromLexer(decodedChars, virtualFile, project, placeInfos);
        InjectedLanguageUtilBase.setHighlightTokens(psiFile, tokens);
      }
      catch (ProcessCanceledException e) {
        throw e;
      }
      catch (RuntimeException e) {
        throw new RuntimeException(exceptionContext("Obtaining tokens error", language, hostPsiFile, hostVirtualFile, hostDocument, placeInfos,
                                                    documentManager), e);
      }
      parsedNodes[i++] = parsedNode;
    }

    return parsedNodes;
  }
private static ASTNode @NotNull [] parseFile(@NotNull Language language, Language forcedLanguage,
                                               @NotNull DocumentWindowImpl documentWindow,
                                               @NotNull VirtualFile hostVirtualFile,
                                               @NotNull DocumentEx hostDocument, @NotNull PsiFile hostPsiFile,
                                               @NotNull Project project,
                                               @NotNull CharSequence documentText,
                                               @NotNull List<PlaceInfo> placeInfos,
                                               @NotNull StringBuilder decodedChars,
                                               @NotNull String fileName, @NotNull PsiDocumentManagerBase documentManager)