Search in sources :

Example 21 with AbstractNode

use of org.eclipse.xtext.nodemodel.impl.AbstractNode in project xtext-core by eclipse.

the class AbstractNodeTest method testGetPreviousSibling_LastChild.

@Test
public void testGetPreviousSibling_LastChild() {
    ICompositeNode rootNode = builder.newRootNode("input");
    AbstractNode first = createNode();
    AbstractNode second = createNode();
    builder.addChild(rootNode, first);
    builder.addChild(rootNode, second);
    assertTrue(second.hasPreviousSibling());
    assertSame(first, second.getPreviousSibling());
    assertTrue(second.hasSiblings());
}
Also used : AbstractNode(org.eclipse.xtext.nodemodel.impl.AbstractNode) Test(org.junit.Test)

Example 22 with AbstractNode

use of org.eclipse.xtext.nodemodel.impl.AbstractNode in project xtext-core by eclipse.

the class AbstractNodeTest method testTreeIterator_Bidi_NoParent.

@Test
public void testTreeIterator_Bidi_NoParent() {
    AbstractNode node = createNode();
    BidiIterator<INode> iterator = node.iterator();
    assertSame(node, iterator.next());
    assertTrue(iterator.hasPrevious());
    assertSame(node, iterator.previous());
    assertTrue(iterator.hasNext());
}
Also used : AbstractNode(org.eclipse.xtext.nodemodel.impl.AbstractNode) Test(org.junit.Test)

Example 23 with AbstractNode

use of org.eclipse.xtext.nodemodel.impl.AbstractNode in project xtext-core by eclipse.

the class AbstractNodeTest method testTreeIterator_Next.

@Test
public void testTreeIterator_Next() {
    ICompositeNode rootNode = builder.newRootNode("input");
    AbstractNode node = createNode();
    builder.addChild(rootNode, node);
    BidiIterator<INode> iterator = node.iterator();
    assertTrue(iterator.hasNext());
    assertSame(node, iterator.next());
    assertFalse(iterator.hasNext());
    try {
        iterator.next();
        fail("Expected NoSuchElementException");
    } catch (NoSuchElementException e) {
    // ok
    }
}
Also used : AbstractNode(org.eclipse.xtext.nodemodel.impl.AbstractNode) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 24 with AbstractNode

use of org.eclipse.xtext.nodemodel.impl.AbstractNode in project xtext-core by eclipse.

the class AbstractNodeTest method testGetNextSibling_LastChild.

@Test
public void testGetNextSibling_LastChild() {
    ICompositeNode rootNode = builder.newRootNode("input");
    AbstractNode first = createNode();
    AbstractNode second = createNode();
    builder.addChild(rootNode, first);
    builder.addChild(rootNode, second);
    assertFalse(second.hasNextSibling());
    assertNull(second.getNextSibling());
}
Also used : AbstractNode(org.eclipse.xtext.nodemodel.impl.AbstractNode) Test(org.junit.Test)

Example 25 with AbstractNode

use of org.eclipse.xtext.nodemodel.impl.AbstractNode in project dsl-devkit by dsldevkit.

the class FixedPartialParsingHelper method isRangePartOfExceedingLookAhead.

private boolean isRangePartOfExceedingLookAhead(final CompositeNode node, final ReplaceRegion replaceRegion) {
    TreeIterator<AbstractNode> iterator = node.basicIterator();
    int lookAhead = node.getLookAhead();
    if (lookAhead == 0) {
        return false;
    }
    while (iterator.hasNext()) {
        AbstractNode child = iterator.next();
        if (child instanceof CompositeNode) {
            if (child.getTotalOffset() < replaceRegion.getEndOffset()) {
                lookAhead = Math.max(((CompositeNode) child).getLookAhead(), lookAhead);
            }
        } else if (!((ILeafNode) child).isHidden()) {
            lookAhead--;
            if (lookAhead == 0) {
                if (child.getTotalOffset() >= replaceRegion.getEndOffset()) {
                    return false;
                }
            }
        }
    }
    return lookAhead > 0;
}
Also used : CompositeNode(org.eclipse.xtext.nodemodel.impl.CompositeNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) SyntheticCompositeNode(org.eclipse.xtext.nodemodel.impl.SyntheticCompositeNode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) AbstractNode(org.eclipse.xtext.nodemodel.impl.AbstractNode)

Aggregations

AbstractNode (org.eclipse.xtext.nodemodel.impl.AbstractNode)25 Test (org.junit.Test)22 NoSuchElementException (java.util.NoSuchElementException)6 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)3 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 CompositeNode (org.eclipse.xtext.nodemodel.impl.CompositeNode)2 SyntheticCompositeNode (org.eclipse.xtext.nodemodel.impl.SyntheticCompositeNode)2 INode (org.eclipse.xtext.nodemodel.INode)1