@Contract("_ -> new")
  private static AnAction @NotNull [] createIncludeExcludeActions(@NotNull Tree tree) {
    class IncludeExcludeAction extends AnAction {

      private final boolean myExclude;

      private IncludeExcludeAction(@NlsActions.ActionText String name, boolean exclude) {
        super(name);
        myExclude = exclude;
      }

      @Override
      public void update(@NotNull AnActionEvent e) {
        TreePath[] selectionPaths = tree.getSelectionPaths();
        if (selectionPaths == null || selectionPaths.length == 0) return;
        TaintNode[] roots = tree.getSelectedNodes(TaintNode.class, null);
        Deque<TaintNode> nodes = new ArrayDeque<>(Arrays.asList(roots));
        boolean enable = false;
        while (!nodes.isEmpty()) {
          TaintNode node = nodes.poll();
          if (node.myTaintValue == TaintValue.TAINTED) {
            e.getPresentation().setEnabled(false);
            return;
          }
          enable |= node.isExcluded() != myExclude;
          List<TaintNode> children = node.myCachedChildren;
          if (children != null) nodes.addAll(children);
        }
        e.getPresentation().setEnabled(enable);
      }

      @Override
      public @NotNull ActionUpdateThread getActionUpdateThread() {
        // getSelectedNodes used
        return ActionUpdateThread.EDT;
      }

      private static Stream<TaintNode> nodes(TaintNode[] roots) {
        return StreamEx.of(roots)
          .flatMap(root -> StreamEx.ofTree(root, n -> n.myCachedChildren == null ? null : StreamEx.of(n.myCachedChildren)));
      }

      @Override
      public void actionPerformed(@NotNull AnActionEvent e) {
        TaintNode[] roots = tree.getSelectedNodes(TaintNode.class, null);
        nodes(roots).forEach(n -> {
          n.setExcluded(myExclude);
          n.update();
        });
      }
    }

    return new AnAction[]{
      new IncludeExcludeAction(JavaRefactoringBundle.message("type.migration.include.action.text"), false),
      new IncludeExcludeAction(JavaRefactoringBundle.message("type.migration.exclude.action.text"), true)
    };
  }
@Contract("_ -> new")
  private static AnAction @NotNull [] createIncludeExcludeActions(@NotNull Tree tree)