Returns the order in which the given node's children should be evaluated.

<p>In most cases, this is EvaluationDirection.FORWARD because the AST order matches the actual
evaluation order. A few nodes require reversed evaluation instead.
1817
private static EvaluationDirection getEvaluationDirection(Node node) {
    switch (node.getToken()) {
      case DESTRUCTURING_LHS:
      case ASSIGN:
      case DEFAULT_VALUE:
        if (node.getFirstChild().isDestructuringPattern()) {
          // The lhs of a destructuring assignment is evaluated AFTER the rhs. This is only true for
          // destructuring, though, not assignments like "first().x = second()" where "first()" is
          // evaluated first.
          return EvaluationDirection.REVERSE;
        }
        // fall through
      default:
        return EvaluationDirection.FORWARD;
    }
  }
1277720
public void sortChildrenByContent(Comparator<? super T> comparator) {
		Comparator<TreeNode<T>> byContent = Comparator.comparing(TreeNode::getContent, comparator);
		sortChildrenByNode(byContent);
	}
1180961
@Nullable
  private AvlNode<E> firstNode() {
    AvlNode<E> root = rootReference.get();
    if (root == null) {
      return null;
    }
    AvlNode<E> node;
    if (range.hasLowerBound()) {
      E endpoint = range.getLowerEndpoint();
      node = rootReference.get().ceiling(comparator(), endpoint);
      if (node == null) {
        return null;
      }
      if (range.getLowerBoundType() == BoundType.OPEN
          && comparator().compare(endpoint, node.getElement()) == 0) {
        node = node.succ;
      }
    } else {
      node = header.succ;
    }
    return (node == header || !range.contains(node.getElement())) ? null : node;
  }
130996
public boolean orderByHasSelectOneStepAndForLabelNotInTree() {
        Set<String> labels = new HashSet<>();
        for (ReplacedStep<?, ?> replacedStep : linearPathToLeafNode()) {
            for (String label : labels) {
                labels.add(SqlgUtil.originalLabel(label));
            }
            for (Pair<Traversal.Admin<?, ?>, Comparator<?>> objects : replacedStep.getSqlgComparatorHolder().getComparators()) {
                Traversal.Admin<?, ?> traversal = objects.getValue0();
                if (traversal.getSteps().size() == 1 && traversal.getSteps().get(0) instanceof SelectOneStep) {
                    //xxxxx.select("a").order().by(select("a").by("name"), Order.decr)
                    SelectOneStep selectOneStep = (SelectOneStep) traversal.getSteps().get(0);
                    Preconditions.checkState(selectOneStep.getScopeKeys().size() == 1, "toOrderByClause expects the selectOneStep to have one scopeKey!");
                    Preconditions.checkState(selectOneStep.getLocalChildren().size() == 1, "toOrderByClause expects the selectOneStep to have one traversal!");
                    Preconditions.checkState(
                            selectOneStep.getLocalChildren().get(0) instanceof ElementValueTraversal ||
                                    selectOneStep.getLocalChildren().get(0) instanceof TokenTraversal
                            ,
                            "toOrderByClause expects the selectOneStep's traversal to be a ElementValueTraversal or a TokenTraversal!");
                    String selectKey = (String) selectOneStep.getScopeKeys().iterator().next();
                    if (!labels.contains(selectKey)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
849503
public List<PlanNode> findAllAtOrBelow( Traversal order ) {
        assert order != null;
        LinkedList<PlanNode> results = new LinkedList<PlanNode>();
        LinkedList<PlanNode> queue = new LinkedList<PlanNode>();
        queue.add(this);
        while (!queue.isEmpty()) {
            PlanNode aNode = queue.poll();
            switch (order) {
                case LEVEL_ORDER:
                    results.add(aNode);
                    queue.addAll(aNode.getChildren());
                    break;
                case PRE_ORDER:
                    results.add(aNode);
                    queue.addAll(0, aNode.getChildren());
                    break;
                case POST_ORDER:
                    queue.addAll(0, aNode.getChildren());
                    results.addFirst(aNode);
                    break;
            }
        }
        return results;
    }
370873
@Override
  protected void visitExprNode(ExprNode node) {

    if (!(node instanceof ParentExprNode)) {
      return;
    }
    ParentExprNode nodeAsParent = (ParentExprNode) node;

    // Recurse.
    visitChildren(nodeAsParent);

    // If all children are constants, we attempt to preevaluate this node and replace it with a
    // constant.
    for (ExprNode child : nodeAsParent.getChildren()) {
      if (!isConstant(child)) {
        return; // cannot preevaluate
      }
    }
    attemptPreeval(nodeAsParent);
  }
312119
function getHandleChildrenStrategy(bAsync, fnCallback) {

		// sync strategy ensures processing order by just being sync
		function syncStrategy(node, oAggregation, mAggregations) {
			var childNode,
				vChild,
				aChildren = [];

			for (childNode = node.firstChild; childNode; childNode = childNode.nextSibling) {
				vChild = fnCallback(node, oAggregation, mAggregations, childNode);
				if (vChild) {
					aChildren.push(unwrapSyncPromise(vChild));
				}
			}
			return SyncPromise.resolve(aChildren);
		}

		// async strategy ensures processing order by chaining the callbacks
		function asyncStrategy(node, oAggregation, mAggregations) {
			var childNode,
				pChain = Promise.resolve(),
				aChildPromises = [];

			for (childNode = node.firstChild; childNode; childNode = childNode.nextSibling) {
				pChain = pChain.then(fnCallback.bind(null, node, oAggregation, mAggregations, childNode));
				aChildPromises.push(pChain);
			}
			return Promise.all(aChildPromises);
		}

		return bAsync ? asyncStrategy : syncStrategy;
	}
1346633
function(node, ignoreSelfAndKids) {
    function nextSiblingEl(n) {
      do {
        n = n.nextSibling;
      } while (n && n.nodeType !== n.ELEMENT_NODE);
      return n;
    }
    // First check for kids if those aren't being ignored
    if (!ignoreSelfAndKids && node.children[0]) {
      return node.children[0];
    }
    // Then for siblings...
    var next = nextSiblingEl(node);
    if (next) {
      return next;
    }
    // And finally, move up the parent chain *and* find a sibling
    // (because this is depth-first traversal, we will have already
    // seen the parent nodes themselves).
    do {
      node = node.parentNode;
      if (node)
        next = nextSiblingEl(node);
    } while (node && !next);
    return node && next;
  }
819734
public int compareTo(ExtensionComponent<T> that) {
        double a = this.ordinal();
        double b = that.ordinal();
        if (a>b)    return -1;
        if (a<b)    return 1;

        // make the order bit more deterministic among extensions of the same ordinal
        if (this.instance instanceof Descriptor && that.instance instanceof Descriptor) {
            try {
                return Util.fixNull(((Descriptor)this.instance).getDisplayName()).compareTo(Util.fixNull(((Descriptor)that.instance).getDisplayName()));
            } catch (RuntimeException | LinkageError x) {
                LOG.log(Level.WARNING, null, x);
            }
        }
        return this.instance.getClass().getName().compareTo(that.instance.getClass().getName());
    }
1314323
public int depth(Tree node) {
        Tree p = node.parent(this);
        if (this == node) {
            return 0;
        }
        if (p == null) {
            return -1;
        }
        int depth = 1;
        while (this != p) {
            p = p.parent(this);
            depth++;
        }
        return depth;
    }
1133459
@SuppressWarnings("unchecked") //suppress warnings to return an ADStarNode instead of Node, which is the inherited return type from parent
    @Override
    public ADStarNodeImpl<A, S, C> previousNode() {
        return (ADStarNodeImpl<A, S, C>) previousNode;
    }
865996
public Node<T> getNext(Node<T> node) {
    	if (node.right != null) {
    		node = node.right;
    		while (node.left != null) node = node.left;
    		return node;
    	}
    	// nothing at right, it may be the parent node if the node is at the left
    	if (node == last) return null;
    	return getNext(root, node.value);
    }
1153852
public static <T extends Offset<T>> Ordering<OffsetRange<T>> byEarlierStartLaterEndOrdering() {
    return Ordering.<T>natural().onResultOf(OffsetRange.<T>toStartInclusiveFunction())
        .compound(
            Ordering.<T>natural().onResultOf(OffsetRange.<T>toEndInclusiveFunction()).reverse());
  }
166878
private int getNextChildIndex(InternalQName nameToAdd, InternalQName primaryTypeName, NodeData parentNode,
      NodeDefinitionData def) throws RepositoryException, ItemExistsException
   {
      boolean allowSns = def.isAllowsSameNameSiblings();

      int ind = 1;

      boolean hasSibling = dataManager.hasItemData(parentNode, new QPathEntry(nameToAdd, ind), ItemType.NODE);
      while (hasSibling)
      {
         if (allowSns)
         {
            ind++;
            hasSibling = dataManager.hasItemData(parentNode, new QPathEntry(nameToAdd, ind), ItemType.NODE);
         }
         else
         {
            throw new ItemExistsException("The node " + nameToAdd + " already exists in " + getPath()
               + " and same name sibling is not allowed ");
         }
      };

      return ind;
   }
352426
public Tree getPreviousSibling() {
		if (parent != null && key != null) {
			if (key instanceof Integer) {
				int idx = (int) key;
				if (idx < 1) {
					return null;
				}
				return parent.get(idx - 1);
			}
			Tree previous = null;
			for (Tree child : parent) {
				if (key.equals(child.key)) {
					return previous;
				}
				previous = child;
			}
		}
		return null;
	}
929587
public boolean nextInOrder() {
        if (mNode == null) {
            return false;
        }
        if (firstChild()) {
            return true;
        }
        if (nextSibling()) {
            return true;
        }
        AccessibilityNodeInfoRef tmp = unOwned(mNode);
        while (tmp.parent()) {
            if (tmp.nextSibling()) {
                reset(tmp);
                return true;
            }
        }
        tmp.clear();
        return false;
    }
392999
private int gatherInfo(LblTree aT, int postorder) {
		int currentSize = 0;
		int childrenCount = 0;
		int descSizes = 0;
		int krSizesSum = 0;
		int revkrSizesSum = 0;
		int preorder = preorderTmp;

		int heavyChild = -1;
		int leftChild = -1;
		int rightChild = -1;
		int weight = -1;
		int maxWeight = -1;
		int currentPostorder = -1;
		int oldHeavyChild = -1;

		ArrayList<Integer> heavyRelSubtreesTmp = new ArrayList<>();
		ArrayList<Integer> leftRelSubtreesTmp = new ArrayList<>();
		ArrayList<Integer> rightRelSubtreesTmp = new ArrayList<>();

		ArrayList<Integer> childrenPostorders = new ArrayList<>();

		preorderTmp++;

		// enumerate over children of current node
		for (Enumeration<?> e = aT.children(); e.hasMoreElements(); ) {
			childrenCount++;

			postorder = gatherInfo((LblTree) e.nextElement(), postorder);

			childrenPostorders.add(postorder);

			currentPostorder = postorder;

			// heavy path
			weight = sizeTmp + 1;
			if (weight >= maxWeight) {
				maxWeight = weight;
				oldHeavyChild = heavyChild;
				heavyChild = currentPostorder;
			} else {
				heavyRelSubtreesTmp.add(currentPostorder);
			}
			if (oldHeavyChild != -1) {
				heavyRelSubtreesTmp.add(oldHeavyChild);
				oldHeavyChild = -1;
			}

			// left path
			if (childrenCount == 1) {
				leftChild = currentPostorder;
			} else {
				leftRelSubtreesTmp.add(currentPostorder);
			}

			// right path
			rightChild = currentPostorder;
			if (e.hasMoreElements()) {
				rightRelSubtreesTmp.add(currentPostorder);
			}

			// subtree size
			currentSize += 1 + sizeTmp;

			descSizes += descSizesTmp;

			if (childrenCount > 1) {
				krSizesSum += krSizesSumTmp + sizeTmp + 1;
			} else {
				krSizesSum += krSizesSumTmp;
				nodeType[LEFT][currentPostorder] = true;
			}

			if (e.hasMoreElements()) {
				revkrSizesSum += revkrSizesSumTmp + sizeTmp + 1;
			} else {
				revkrSizesSum += revkrSizesSumTmp;
				nodeType[RIGHT][currentPostorder] = true;
			}
		}

		postorder++;

		// postorder
		aT.setTmpData(postorder);

		int currentDescSizes = descSizes + currentSize + 1;
		info[POST2_DESC_SUM][postorder] =
				(currentSize + 1) * (currentSize + 1 + 3) / 2 - currentDescSizes;
		info[POST2_KR_SUM][postorder] = krSizesSum + currentSize + 1;
		info[POST2_REV_KR_SUM][postorder] = revkrSizesSum + currentSize + 1;

		// POST2_LABEL
		// labels[rootNumber] = ld.store(aT.getLabel());
		info[POST2_LABEL][postorder] = ld.store(aT.getLabel());

		// POST2_PARENT
		for (Integer i : childrenPostorders) {
			info[POST2_PARENT][i] = postorder;
		}

		// POST2_SIZE
		info[POST2_SIZE][postorder] = currentSize + 1;
		if (currentSize == 0) {
			leafCount++;
		}

		// POST2_PRE
		info[POST2_PRE][postorder] = preorder;

		// PRE2_POST
		info[PRE2_POST][preorder] = postorder;

		// RPOST2_POST
		info[RPOST2_POST][treeSize - 1 - preorder] = postorder;

		// heavy path
		if (heavyChild != -1) {
			paths[HEAVY][postorder] = heavyChild;
			nodeType[HEAVY][heavyChild] = true;

			if (leftChild < heavyChild && heavyChild < rightChild) {
				info[POST2_STRATEGY][postorder] = BOTH;
			} else if (heavyChild == leftChild) {
				info[POST2_STRATEGY][postorder] = RIGHT;
			} else if (heavyChild == rightChild) {
				info[POST2_STRATEGY][postorder] = LEFT;
			}
		} else {
			info[POST2_STRATEGY][postorder] = RIGHT;
		}

		// left path
		if (leftChild != -1) {
			paths[LEFT][postorder] = leftChild;
		}
		// right path
		if (rightChild != -1) {
			paths[RIGHT][postorder] = rightChild;
		}

		// heavy/left/right relevant subtrees
		relSubtrees[HEAVY][postorder] = toIntArray(heavyRelSubtreesTmp);
		relSubtrees[RIGHT][postorder] = toIntArray(rightRelSubtreesTmp);
		relSubtrees[LEFT][postorder] = toIntArray(leftRelSubtreesTmp);

		descSizesTmp = currentDescSizes;
		sizeTmp = currentSize;
		krSizesSumTmp = krSizesSum;
		revkrSizesSumTmp = revkrSizesSum;

		return postorder;
	}