public static @NotNull Group createCorrectedGroup(@NotNull ActionGroup actionGroup,
                                                    @NotNull @NlsActions.ActionText String groupName,
                                                    @NotNull List<? super String> path,
                                                    @NotNull List<ActionUrl> actionUrls) {
    path.add(groupName);

    ActionManager actionManager = ActionManager.getInstance();
    String groupId = actionManager.getId(actionGroup);
    Group group = new Group(groupName, groupId, getTemplatePresentation(actionGroup).getIcon());
    List<AnAction> children = new ArrayList<>(Arrays.asList(getActions(actionGroup, actionManager)));

    for (ActionUrl actionUrl : actionUrls) {
      Object component = actionUrl.getComponent();
      if (component instanceof Group correctedGroup && Objects.equals(correctedGroup.getId(), groupId)) {
        group.setForceShowAsPopup(correctedGroup.isForceShowAsPopup());
      }
      // the actual path is shorter when we use custom root
      if (areEqual(path, actionUrl)) {
        AnAction componentAction = actionUrl.getComponentAction();
        if (componentAction != null) {
          if (actionUrl.getActionType() == ActionUrl.ADDED) {
            if (children.size() > actionUrl.getAbsolutePosition()) {
              children.add(actionUrl.getAbsolutePosition(), componentAction);
            }
            else {
              children.add(componentAction);
            }
          }
          else if (actionUrl.getActionType() == ActionUrl.DELETED && children.size() > actionUrl.getAbsolutePosition()) {
            AnAction anAction = children.get(actionUrl.getAbsolutePosition());
            String actionText = getTemplatePresentation(anAction).getText();
            String componentActionText = getTemplatePresentation(componentAction).getText();
            if (actionText == null && componentActionText != null && !componentActionText.isEmpty() ||
                actionText != null && !actionText.equals(componentActionText)) {
              continue;
            }
            children.remove(actionUrl.getAbsolutePosition());
          }
        }
      }
    }

    for (AnAction action : children) {
      if (action instanceof ActionGroup) {
        group.addGroup(createCorrectedGroup((ActionGroup)action, getName(action), path, actionUrls));
      }
      else if (action instanceof Separator) {
        group.addSeparator();
      }
      else {
        String id = actionManager.getId(action);
        if (id != null) {
          group.addActionId(id);
        }
      }
    }

    path.remove(path.size() - 1);

    return group;
  }
public static @NotNull Group createCorrectedGroup(@NotNull ActionGroup actionGroup,
                                                    @NotNull @NlsActions.ActionText String groupName,
                                                    @NotNull List<? super String> path,
                                                    @NotNull List<ActionUrl> actionUrls)