Java 类org.eclipse.xtext.nodemodel.impl.CompositeNode 实例源码

项目:xtext-extras    文件:LookAheadPreservingNodeModelBuilder.java   
@Override
public void replaceAndTransferLookAhead(INode oldNode, INode newRootNode) {
    Iterator<AbstractNode> oldNodes = ((AbstractNode) oldNode).basicIterator();
    Iterator<AbstractNode> newNodes = ((AbstractNode) newRootNode).basicIterator();
    newNodes.next(); // basicGetFirstChild to skip that one
    while(oldNodes.hasNext()) {
        AbstractNode nextOld = oldNodes.next();
        AbstractNode nextNew = newNodes.next();
        if (nextOld instanceof CompositeNode) {
            setLookAhead((CompositeNode) nextNew, ((CompositeNode) nextOld).getLookAhead());
        }
    }
    if (newNodes.hasNext()) {
        throw new RuntimeException();
    }
    super.replaceAndTransferLookAhead(oldNode, newRootNode);
}
项目:xtext-core    文件:PartialParsingHelper.java   
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;
}
项目:xtext-core    文件:ParseResult.java   
@Override
public Iterable<INode> getSyntaxErrors() {
    if (rootNode == null || !hasSyntaxErrors())
        return Collections.emptyList();
    return new Iterable<INode>() {
        @Override
        @SuppressWarnings("unchecked")
        public Iterator<INode> iterator() {
            Iterator<? extends INode> result = Iterators.filter(((CompositeNode) rootNode).basicIterator(),
                    new Predicate<AbstractNode>() {
                @Override
                public boolean apply(AbstractNode input) {
                    return input.getSyntaxErrorMessage() != null;
                }
            });
            return (Iterator<INode>) result;
        }
    };
}
项目:xtext-core    文件:HiddenAndTokenNodeIteratorTest.java   
@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]);
}
项目:xtext-core    文件:LazyURIEncoderTest.java   
@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));
}
项目:dsl-devkit    文件:FixedPartialParsingHelper.java   
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;
}
项目:Gauge-Eclipse    文件:SpecHyperlinkHelper.java   
@Override
public IHyperlink[] createHyperlinksByOffset(XtextResource resource,
        int offset, boolean createMultipleHyperlinks) {

    EObject eObject = helper.resolveElementAt(resource, offset);
    if (eObject instanceof StepDefinition || 
            eObject instanceof StaticParam || 
            eObject instanceof DynamicParam) {
        IParseResult parseResult = resource.getParseResult();
        INode node = NodeModelUtils.findLeafNodeAtOffset(
                parseResult.getRootNode(), offset);
        while (!(node instanceof CompositeNode && node.getSemanticElement() instanceof StepDefinition)) {
            node = node.getParent();
        }
        String description = StepUtil.getStepText(node);
        if (!openConceptDefinition(eObject, description)) {
            openStepDefinition(description);
        }
    }
    return null;
}
项目:xtext-core    文件:SyntheticLinkingSupport.java   
public SyntheticLinkingLeafNode(EObject semanticElement, String text, int offset, int length, EObject grammarElement, CompositeNode parent) {
    this.text = text;
    this.semanticElement = semanticElement;

    basicSetTotalOffset(offset);
    basicSetTotalLength(length);
    basicSetGrammarElement(grammarElement);
    basicSetParent(parent);
}
项目:xtext-core    文件:NodeIteratorTest.java   
@Before
public void setUp() throws Exception {
    NodeModelBuilder builder = new NodeModelBuilder();
    nodes = new INode[NUM_NODES];
    nodes[0] = new CompositeNode();
    nodes[1] = new LeafNode();
    nodes[2] = new CompositeNode();
    nodes[3] = new CompositeNode();
    nodes[4] = new LeafNode();
    nodes[5] = new LeafNode();
    nodes[6] = new LeafNode();
    nodes[7] = new CompositeNode();
    nodes[8] = new LeafNode();
    nodes[9] = new LeafNode();
    nodes[10]= new CompositeNode();

    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[1]);
    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[2]);
    builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[3]);
    builder.addChild((ICompositeNode)nodes[3], (AbstractNode)nodes[4]);
    builder.addChild((ICompositeNode)nodes[3], (AbstractNode)nodes[5]);
    builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[6]);
    builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[7]);
    builder.addChild((ICompositeNode)nodes[2], (AbstractNode)nodes[8]);
    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[9]);
    builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[10]);
}
项目:xtext-core    文件:SyntheticLinkingSupport.java   
/**
 * @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);
}
项目:xtext-core    文件:LeafNode.java   
@Override
protected CompositeNode basicGetParent() {
    return super.basicGetParent();
}
项目:xtext-core    文件:LeafNode.java   
@Override
protected void basicSetParent(CompositeNode parent) {
    super.basicSetParent(parent);
}