private synchronized void buildStubTree(@Nullable PsiElement rootElement, @NotNull String textToParse) {
    if (rootElement == null) {
      myStubTree.setRootVisible(false);
      return;
    }
    if (!(rootElement instanceof PsiFileWithStubSupport)) {
      myStubTree.setRootVisible(false);
      StatusText text = myStubTree.getEmptyText();
      if (rootElement instanceof PsiFile) {
        text.setText("No stubs for " + rootElement.getLanguage().getDisplayName());
      }
      else {
        text.setText("Cannot build stub tree for code fragments");
      }
      return;
    }
    Stub stub = buildStubForElement(myProject, rootElement, textToParse);

    if (stub instanceof PsiFileStub) {
      PsiFileWithStubSupport file = (PsiFileWithStubSupport)rootElement;
      final StubTreeNode rootNode = new StubTreeNode((StubElement<?>)stub, null);
      StructureTreeModel<?> treeModel = new StructureTreeModel<>(new StubTreeStructure(rootNode), myTreeModelDisposable);
      myTreeModel = new AsyncTreeModel(treeModel, myTreeModelDisposable);
      myStubTree.setModel(myTreeModel);
      fillPsiToStubCache(file, (PsiFileStub<?>)stub);
      myStubTree.setRootVisible(true);
      myStubTree.expandRow(0);

      myStubTree.addTreeSelectionListener(new StubTreeSelectionListener());
      treeModel.invalidateAsync();
    }
    else {
      myStubTree.setRootVisible(false);
      StatusText text = myStubTree.getEmptyText();
      text.setText("Cannot build stubs for " + rootElement.getLanguage().getDisplayName());
    }
  }
private synchronized void buildStubTree(@Nullable PsiElement rootElement, @NotNull String textToParse)