Search in sources :

Example 1 with AbstractNode

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

the class PartialParsingHelper method isRangePartOfExceedingLookAhead.

private boolean isRangePartOfExceedingLookAhead(CompositeNode node, 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)

Example 2 with AbstractNode

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

the class AbstractNodeTest method testGetRootNode_NoRoot.

@Test
public void testGetRootNode_NoRoot() {
    AbstractNode node = createNode();
    ICompositeNode parent = new CompositeNode();
    builder.addChild(parent, node);
    assertNull(node.getRootNode());
}
Also used : AbstractNode(org.eclipse.xtext.nodemodel.impl.AbstractNode) Test(org.junit.Test)

Example 3 with AbstractNode

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

the class AbstractNodeTest method testGetPreviousSibling_SingleChild.

@Test
public void testGetPreviousSibling_SingleChild() {
    ICompositeNode rootNode = builder.newRootNode("input");
    AbstractNode node = createNode();
    builder.addChild(rootNode, node);
    assertFalse(node.hasPreviousSibling());
    assertNull(node.getPreviousSibling());
    assertFalse(node.hasSiblings());
}
Also used : AbstractNode(org.eclipse.xtext.nodemodel.impl.AbstractNode) Test(org.junit.Test)

Example 4 with AbstractNode

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

the class AbstractNodeTest method testGetParent_NoParent.

@Test
public void testGetParent_NoParent() {
    AbstractNode node = createNode();
    assertNull(node.getParent());
}
Also used : AbstractNode(org.eclipse.xtext.nodemodel.impl.AbstractNode) Test(org.junit.Test)

Example 5 with AbstractNode

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

the class AbstractNodeTest method testTreeIterator_Next_NoParent.

@Test
public void testTreeIterator_Next_NoParent() {
    AbstractNode node = createNode();
    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)

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