Walks an AST tree recursively
        :param listener:
        :param tree:
        :return: None
354491
def walk(self, listener: TreeListener, tree: ast.Node) -> None:
        
        name = tree.__class__.__name__
        if hasattr(listener, 'enterEvery'):
            getattr(listener, 'enterEvery')(tree)
        if hasattr(listener, 'enter' + name):
            getattr(listener, 'enter' + name)(tree)
        for child_name in self.order_keys(tree.__dict__.keys()):
            if self.skip_child(tree, child_name):
                continue
            self.handle_walk(listener, tree.__dict__[child_name])
        if hasattr(listener, 'exitEvery'):
            getattr(listener, 'exitEvery')(tree)
        if hasattr(listener, 'exit' + name):
            getattr(listener, 'exit' + name)(tree)
1369125
function callListenersSequentially(i, args) {
    if (!this.events[eventName][i]) {
      // If there is no more listener to execute, we return a promise of the event arguments/result
      // So we are getting out of the recursive function
      return new Promise((resolve, reject) => {
        resolve(args);
      });
    }

    const p = Promise.resolve(this.events[eventName][i].apply(this.events[eventName][i], args));
    return p.then(function propagateArguments() {
      // We cannot use the "=>" notation here because we use `"arguments"
      // When an event listener has been executed, we move to the next one (recursivity)
      if (propagateResponses) {
        // Case the event must pass the result of a listener to the next one
        // This use case allow to transmit and alter primitive (strings, numbers ...)
        return callListenersSequentially.bind(this)(i + 1, arguments[0]);
      }
      // Case the event can pass the arguments to each listener
      // This use case allow a simple syntax for listener, compatible with fireConcurrently()
      // But it is not possible to transmit alterations made on primitive arguments
      return callListenersSequentially.bind(this)(i + 1, args);
    }.bind(this));
  }
1036016
function(node, callback, depth) {
			if (this.isSkipped(node)) {
				return;
			}

			var childNode,
				childNodes = node && node.childNodes || [];

			depth = (depth || 1);

			for (var n = 0, len = childNodes.length; n < len; n++) {
				childNode = childNodes[n];

				// callback can return false to stop recursive
				if (callback(childNode, depth) !== false) {
					this.walk(childNode, callback, depth + 1);
				}
			}
		}
986968
def tree_iterator(self, visited=None, path=None):
        '''
        
        '''
        if visited is None:
            visited = set()

        if self not in visited:
            if path and isinstance(path, list):
                path.append(self)

            visited.add(self)
            yield self

            if not hasattr(self, 'dterms'):
                yield

            for dterm in self.dterms:
                if hasattr(self, dterm):
                    child = getattr(self, dterm)
                    if hasattr(child, 'dterms') or hasattr(child, 'terms'):
                        for node in child.tree_iterator(visited):
                            yield node
737765
public TreeBuilder<T> listen(Listener<T> listener, Path subpath) {
        return TreeBuilder.<T>builder(new ListenerTree<T>(build(), listener, PathUtil.subpathSelector(subpath)));
    }
767381
function traverseRevTree(revs, callback) {
  var toVisit = revs.slice();

  var node;
  while ((node = toVisit.pop())) {
    var pos = node.pos;
    var tree = node.ids;
    var branches = tree[2];
    var newCtx =
      callback(branches.length === 0, pos, tree[0], node.ctx, tree[1]);
    for (var i = 0, len = branches.length; i < len; i++) {
      toVisit.push({pos: pos + 1, ids: branches[i], ctx: newCtx});
    }
  }
}
12617
def _traverse_tree(tree, path):
        """"""
        path_steps = (step for step in path.split('.') if step != '')
        # Special handling for first step, because the first step isn't under 'objects'
        first_step = path_steps.next()
        subtree = tree[first_step]

        for step in path_steps:
            subtree = subtree['children'][step]
        return subtree
384742
def treewalk(self, root, parsed, unparsed):
        
        suggestions = dict()
        if not unparsed:
            logger.debug("no tokens left unparsed. returning %s, %s", parsed, suggestions)
            return parsed, unparsed, suggestions

        token = unparsed.pop().strip()
        logger.debug("begin parsing at %s w/ tokens: %s", root.node, unparsed)
        if root.node == token:
            logger.debug("root node: %s matches next token:%s", root.node, token)
            parsed.append(token)
            if self.peekForOption(unparsed):  # check for localFlags and globalFlags
                logger.debug("option(s) upcoming %s", unparsed)
                parsed_opts, unparsed, suggestions = self.evalOptions(root, list(), unparsed[:])
                if parsed_opts:
                    logger.debug("parsed option(s): %s", parsed_opts)
                    parsed.extend(parsed_opts)
            if unparsed and not self.peekForOption(unparsed):  # unparsed bits without options
                logger.debug("begin subtree %s parsing", root.node)
                for child in root.children:
                    parsed_subtree, unparsed, suggestions = self.treewalk(child, list(), unparsed[:])
                    if parsed_subtree:  # subtree returned further parsed tokens
                        parsed.extend(parsed_subtree)
                        logger.debug("subtree at: %s has matches. %s, %s", child.node, parsed, unparsed)
                        break
                else:
                    # no matches found in command tree
                    # return children of root as suggestions
                    logger.debug("no matches in subtree: %s. returning children as suggestions", root.node)
                    for child in root.children:
                        suggestions[child.node] = child.help
        else:
            logger.debug("no token or option match")
            unparsed.append(token)
        return parsed, unparsed, suggestions
428327
public TreeBuilder<T> listen(Listener<T> listener, PathSelector pathSelector) {
        return TreeBuilder.<T>builder(new ListenerTree<T>(build(), listener, pathSelector));
    }
299797
def add_listener(self, listener):
        
        internal_listener = partial(self._call_in_reactor_thread, listener)
        self._internal_listeners[listener] = internal_listener
        return self._client.add_listener(internal_listener)
174666
function visit(ast, context, visitor) {
  var stack;
  var parent;
  var keys = [];
  var index = -1;

  do {
    index++;
    if (stack && index === keys.length) {
      parent = stack.parent;
      keys = stack.keys;
      index = stack.index;
      stack = stack.prev;
    } else {
      var node = parent ? parent[keys[index]] : getProgram(ast);
      if (node && typeof node === 'object' && (node.type || node.length)) {
        if (node.type) {
          var visitFn = visitor[node.type];
          if (visitFn && visitFn(context, node, ast) === false) {
            continue;
          }
        }
        stack = {parent: parent, keys: keys, index: index, prev: stack};
        parent = node;
        keys = Object.keys(node);
        index = -1;
      }
    }
  } while (stack);
}
100052
private TreeNodeVisitor walkCorruptedPath(TreeLearner model, DataPoint dp, int j, Random rand)
    {
        TreeNodeVisitor curNode = model.getTreeNodeVisitor();
        while(!curNode.isLeaf())
        {
            int path = curNode.getPath(dp);
            int numChild = curNode.childrenCount();
            if(curNode.featuresUsed().contains(j))//corrupt the feature!
            {
                //this gets us a random OTHER path, wont be the same b/c we would need to wrap around 1 farther
                path = (path + rand.nextInt(numChild)) % numChild;
            }
            
            if(curNode.isPathDisabled(path))
                break;
            else
                curNode = curNode.getChild(path);
        }
        return curNode;
    }
175899
def _walk(recursion):
    """"""
    try:
        from scandir import walk as walk_function
    except ImportError:
        from os import walk as walk_function

    if recursion:
        walk = partial(walk_function)
    else:
        def walk(path):  # pylint: disable=C0111
            try:
                yield next(walk_function(path))
            except NameError:
                yield walk_function(path)
    return walk
576693
protected synchronized void fireTreeAddition(Tree<D, ?> tree) {
		if (this.listeners != null) {
			final ForestListener[] list = new ForestListener[this.listeners.size()];
			this.listeners.toArray(list);
			final ForestEvent event = new ForestEvent(this, null, tree);
			for (final ForestListener listener : list) {
				listener.forestChanged(event);
			}
		}
	}
743598
def _dispatch(self, tree):
        ""
        if isinstance(tree, list):
            for t in tree:
                self._dispatch(t)
            return
        meth = getattr(self, "_"+tree.__class__.__name__)
        if tree.__class__.__name__ == 'NoneType' and not self._do_indent:
            return
        meth(tree)
901576
function Cursor(tree, start, end) {
        this.tree = tree;
        this.start = start;
        this.end = end;
        
        var self = this;
        this.walk = function walk(node, iterator) {
            if (node === null) return;
            
            if (start !== undefined && node.key < start) {
                walk(node.right, iterator);
            } else if (end !== undefined && node.key > end) {
                walk(node.left, iterator);
            } else {
                walk(node.left, iterator);
                iterator(node.value, node.key, self.tree);
                walk(node.right, iterator);
            }
        };
    }
434768
function recursiveRemoveListeners(listeners: Object | any[]) {
  if (Array.isArray(listeners)) {
    listeners.forEach((listener, index) =>
      recursiveRemoveListeners(listener)
    );
  } else if (listeners instanceof ListenerTracker) {
    const id = listeners.id;
    const object = listeners.object;
    object._parent
        ? object._parent.removeListener(id)
        : object.removeListener(id);
  } else if (typeof listeners === 'object' && listeners !== null) {
    Object.keys(listeners).forEach(key =>
      recursiveRemoveListeners(listeners[key])
    );
  }
}