def METHOD_NAME(self, tree):  # pylint: disable=too-many-branches
    root = tree
    if self.delete_tree is not None:
        if eval(self.delete_tree):
            tree.remove()
            return
    if self.delete_tree_if_node is not None:
        for node in tree.descendants:
            if eval(self.delete_tree_if_node):
                tree.remove()
                return
    if self.delete_subtree is not None:
        for node in tree.descendants:
            if eval(self.delete_subtree):
                node.remove()
                continue
    if self.keep_tree is not None:
        if not eval(self.keep_tree):
            tree.remove()
            return
    if self.keep_tree_if_node is not None:
        found = False
        for node in tree.descendants:
            if eval(self.keep_tree_if_node):
                found = True
                if self.mark:
                    node.misc['Mark'] = self.mark
                else:
                    return
        if not found:
            tree.remove()
        return
    if self.keep_subtree is not None:
        kept_subtrees = []
        for node in tree.descendants:
            if eval(self.keep_subtree):
                kept_subtrees.append(node)
        if not kept_subtrees:
            tree.remove()
            return
        else:
            for node in kept_subtrees:
                node.parent = root
            for orig_subroot in [n for n in root.children if n not in kept_subtrees]:
                orig_subroot.remove()
    if self.keep_node is not None:
        nodes_to_delete = [node for node in tree.descendants if not eval(self.keep_node)]
        if nodes_to_delete == tree.descendants:
            tree.remove()
            return
        for node in nodes_to_delete:
            node.remove(children='rehang')