Search in sources :

Example 1 with CompositeNode

use of org.eclipse.xtext.nodemodel.impl.CompositeNode 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 CompositeNode

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

the class SyntheticLinkingLeafNode method getParent.

/**
 * @since 2.10
 */
protected CompositeNode getParent(EObject obj, EReference eRef, String crossRefString, int offset, int length) {
    ICompositeNode node = NodeModelUtils.getNode(obj);
    if (node != null) {
        ICompositeNode rootNode = node.getRootNode();
        if (rootNode instanceof CompositeNode)
            return (CompositeNode) rootNode;
    }
    Resource resource = obj.eResource();
    if (resource instanceof XtextResource) {
        IParseResult parseResult = ((XtextResource) resource).getParseResult();
        if (parseResult != null) {
            ICompositeNode rootNode = parseResult.getRootNode();
            if (rootNode instanceof CompositeNode)
                return (CompositeNode) rootNode;
        }
    }
    return null;
}
Also used : CompositeNode(org.eclipse.xtext.nodemodel.impl.CompositeNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 3 with CompositeNode

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

the class SyntheticLinkingLeafNode method createCrossReferenceNode.

/**
 * @since 2.10
 */
protected INode createCrossReferenceNode(EObject obj, EReference eRef, String crossRefString, int offset, int length) {
    CompositeNode parent = getParent(obj, eRef, crossRefString, offset, length);
    EObject grammarElement = getGrammarElement(obj, eRef, crossRefString, offset, length);
    return new SyntheticLinkingLeafNode(obj, crossRefString, offset, length, grammarElement, parent);
}
Also used : CompositeNode(org.eclipse.xtext.nodemodel.impl.CompositeNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) EObject(org.eclipse.emf.ecore.EObject)

Example 4 with CompositeNode

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

the class LazyURIEncoderTest method testNodePath.

@Test
public void testNodePath() throws Exception {
    NodeModelBuilder builder = new NodeModelBuilder();
    ICompositeNode n = new CompositeNode();
    ICompositeNode n1 = new CompositeNode();
    builder.addChild(n, (AbstractNode) n1);
    ICompositeNode n2 = new CompositeNode();
    builder.addChild(n, (AbstractNode) n2);
    ILeafNode l1 = new LeafNode();
    builder.addChild(n2, (AbstractNode) l1);
    ILeafNode l2 = new LeafNode();
    builder.addChild(n2, (AbstractNode) l2);
    assertEquals(n, find(n, n));
    assertEquals(n1, find(n, n1));
    assertEquals(n2, find(n, n2));
    assertEquals(l1, find(n, l1));
    assertEquals(l2, find(n, l2));
}
Also used : CompositeNode(org.eclipse.xtext.nodemodel.impl.CompositeNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) NodeModelBuilder(org.eclipse.xtext.nodemodel.impl.NodeModelBuilder) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 5 with CompositeNode

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

the class HiddenAndTokenNodeIteratorTest method setUp.

@Before
public void setUp() throws Exception {
    nodes = new INode[NUM_NODES];
    NodeModelBuilder builder = new NodeModelBuilder();
    nodes[0] = new CompositeNode();
    nodes[1] = new CompositeNode();
    nodes[2] = new HiddenLeafNode();
    nodes[3] = new LeafNode();
    nodes[4] = new HiddenLeafNode();
    nodes[5] = new CompositeNode();
    nodes[6] = new LeafNode();
    nodes[7] = new CompositeNode();
    nodes[8] = new HiddenLeafNode();
    nodes[9] = new LeafNode();
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[1]);
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[5]);
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[7]);
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[9]);
    builder.addChild((ICompositeNode) nodes[1], (AbstractNode) nodes[2]);
    builder.addChild((ICompositeNode) nodes[1], (AbstractNode) nodes[3]);
    builder.addChild((ICompositeNode) nodes[1], (AbstractNode) nodes[4]);
    builder.addChild((ICompositeNode) nodes[5], (AbstractNode) nodes[6]);
    builder.addChild((ICompositeNode) nodes[7], (AbstractNode) nodes[8]);
}
Also used : CompositeNode(org.eclipse.xtext.nodemodel.impl.CompositeNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) HiddenLeafNode(org.eclipse.xtext.nodemodel.impl.HiddenLeafNode) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) NodeModelBuilder(org.eclipse.xtext.nodemodel.impl.NodeModelBuilder) HiddenLeafNode(org.eclipse.xtext.nodemodel.impl.HiddenLeafNode) Before(org.junit.Before)

Aggregations

ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)7 CompositeNode (org.eclipse.xtext.nodemodel.impl.CompositeNode)7 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)3 LeafNode (org.eclipse.xtext.nodemodel.impl.LeafNode)3 NodeModelBuilder (org.eclipse.xtext.nodemodel.impl.NodeModelBuilder)3 AbstractNode (org.eclipse.xtext.nodemodel.impl.AbstractNode)2 SyntheticCompositeNode (org.eclipse.xtext.nodemodel.impl.SyntheticCompositeNode)2 Before (org.junit.Before)2 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 HiddenLeafNode (org.eclipse.xtext.nodemodel.impl.HiddenLeafNode)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 Test (org.junit.Test)1