private void computeNext()

in mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/AbstractNodeIterator.java [63:136]


    private void computeNext(Axis axis) {
        CoreNode node = currentNode;
        if (node instanceof CoreChildNode
                && ((CoreChildNode) node).coreGetParent() != currentParent) {
            throw new ConcurrentModificationException(
                    "The current node has been removed using a method other than Iterator#remove()");
        }
        try {
            while (true) {
                // Get to the next node
                switch (axis) {
                    case CHILDREN:
                        if (node == null) {
                            node = startNode.coreGetFirstChild();
                        } else {
                            node = ((CoreChildNode) node).coreGetNextSibling();
                        }
                        break;
                    case DESCENDANTS:
                    case DESCENDANTS_OR_SELF:
                        if (node == null) {
                            if (axis == Axis.DESCENDANTS) {
                                node = startNode.coreGetFirstChild();
                                depth++;
                            } else {
                                node = startNode;
                            }
                        } else {
                            boolean visitChildren = true;
                            while (true) {
                                if (visitChildren
                                        && node instanceof CoreParentNode
                                        && semantics.isParentNode(node.coreGetNodeType())) {
                                    CoreChildNode firstChild =
                                            ((CoreParentNode) node).coreGetFirstChild();
                                    if (firstChild != null) {
                                        depth++;
                                        node = firstChild;
                                        break;
                                    }
                                }
                                if (depth == 0) {
                                    node = null;
                                    break;
                                }
                                CoreChildNode nextSibling =
                                        ((CoreChildNode) node).coreGetNextSibling();
                                if (nextSibling != null) {
                                    node = nextSibling;
                                    break;
                                }
                                depth--;
                                node = ((CoreChildNode) node).coreGetParent();
                                visitChildren = false;
                            }
                        }
                }
                if (node == null) {
                    nextNode = null;
                    break;
                }
                if (type.isInstance(node)) {
                    T candidate = type.cast(node);
                    if (matches(candidate)) {
                        nextNode = candidate;
                        break;
                    }
                }
            }
        } catch (CoreModelException ex) {
            throw semantics.toUncheckedException(ex);
        }
        hasNext = true;
    }