Search in sources :

Example 1 with NodeIterator

use of org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator in project xtext-core by eclipse.

the class NodeIteratorTest method checkDescending.

protected void checkDescending(int index) {
    int i = index;
    NodeIterator nodeIterator = new NodeIterator(nodes[i]);
    while (nodeIterator.hasPrevious()) {
        assertEquals(nodes[--i], nodeIterator.previous());
    }
}
Also used : NodeIterator(org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator)

Example 2 with NodeIterator

use of org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator in project xtext-core by eclipse.

the class NodeIteratorTest method checkAscending.

protected void checkAscending(int index) {
    int i = index;
    NodeIterator nodeIterator = new NodeIterator(nodes[i]);
    while (nodeIterator.hasNext()) {
        assertEquals("Ascending " + i, nodes[++i], nodeIterator.next());
    }
}
Also used : NodeIterator(org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator)

Example 3 with NodeIterator

use of org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator in project xtext-core by eclipse.

the class EmitterNodeIterator method next.

@Override
public INode next() {
    INode result;
    if (!next.isEmpty()) {
        result = next.get(0);
        next.remove(0);
    } else
        result = null;
    if (next.isEmpty())
        while (iterator.hasNext()) {
            INode next = iterator.next();
            if (next.getOffset() >= end)
                break;
            if (include(next)) {
                if (!passAbsorber && isAbsorber(next))
                    break;
                if (allowHidden && next instanceof ICompositeNode && (GrammarUtil.isDatatypeRuleCall(next.getGrammarElement()) || GrammarUtil.isEnumRuleCall(next.getGrammarElement()) || next.getGrammarElement() instanceof CrossReference)) {
                    NodeIterator ni = new NodeIterator(next);
                    while (ni.hasNext()) {
                        INode next2 = ni.next();
                        if (next2 instanceof ILeafNode && ((ILeafNode) next2).isHidden())
                            this.next.add(next2);
                        else
                            break;
                    }
                }
                iterator.prune();
                this.next.add(next);
                return result;
            }
        }
    return result;
}
Also used : NodeIterator(org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) CrossReference(org.eclipse.xtext.CrossReference)

Example 4 with NodeIterator

use of org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator in project xtext-core by eclipse.

the class HiddenTokenSequencer method getTrailingCommentsIncludingWhitespace.

protected Set<INode> getTrailingCommentsIncludingWhitespace(ILeafNode node) {
    Set<INode> associatedNodes = Sets.newHashSet();
    Set<INode> pendingWhitespace = Sets.newHashSet();
    INode lastLink = node;
    NodeIterator ni = new NodeIterator(lastLink);
    while (ni.hasNext()) {
        INode next = ni.next();
        if (tokenUtil.isCommentNode(next)) {
            if (isTrailingCommentFor(next, lastLink)) {
                lastLink = next;
                associatedNodes.addAll(pendingWhitespace);
                associatedNodes.add(next);
            } else {
                break;
            }
        } else if (tokenUtil.isWhitespaceNode(next)) {
            pendingWhitespace.add(next);
        } else if (next instanceof ILeafNode) {
            break;
        }
    }
    return associatedNodes;
}
Also used : NodeIterator(org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode)

Example 5 with NodeIterator

use of org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator in project xtext-core by eclipse.

the class HiddenTokenSequencer method getRemainingHiddenNodesInContainer.

protected List<INode> getRemainingHiddenNodesInContainer(INode from, INode root) {
    if (from == null || root == null)
        return Collections.emptyList();
    List<INode> out = Lists.newArrayList();
    NodeIterator ni = new NodeIterator(from);
    while (ni.hasNext()) {
        INode next = ni.next();
        if (next.getTotalOffset() > root.getTotalEndOffset())
            return out;
        else if (tokenUtil.isWhitespaceOrCommentNode(next)) {
            out.add(next);
        } else if (tokenUtil.isToken(next))
            return Collections.emptyList();
    }
    return out;
}
Also used : NodeIterator(org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator) INode(org.eclipse.xtext.nodemodel.INode)

Aggregations

NodeIterator (org.eclipse.xtext.parsetree.reconstr.impl.NodeIterator)9 INode (org.eclipse.xtext.nodemodel.INode)5 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)4 CrossReference (org.eclipse.xtext.CrossReference)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 Test (org.junit.Test)2 EObject (org.eclipse.emf.ecore.EObject)1