private static List<AnAction> flattenActionGroups(final @NotNull ActionGroup action) {
    final ArrayList<AnAction> groups = new ArrayList<>();
    for (AnAction anAction : action.getChildren(null)) {
      if (anAction instanceof ActionGroup actionGroup) {
        var elementsToAdd = getActionChildrenToAddInsteadOfAction(actionGroup);
        if (elementsToAdd != null) {
          // Some GroupActions shouldn't be added directly, but children must be added instead
          groups.addAll(Arrays.asList(elementsToAdd));
          continue;
        }
      }
      // Collapse groups and regular actions
      groups.add(anAction);
    }
    return groups;
  }
private static List<AnAction> flattenActionGroups(final @NotNull ActionGroup action)