org.eclipse.xtext.nodemodel.impl.SyntheticCompositeNode Java Examples

The following examples show how to use org.eclipse.xtext.nodemodel.impl.SyntheticCompositeNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreeIteratorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testTreeIteratorForSyntheticNodes_Forward() throws Exception {
	EObject object = getModel("(d - e) / e * d // fasdf s");
	ICompositeNode root = NodeModelUtils.getNode(object).getRootNode();
	INode firstChild = root.getFirstChild();
	INode firstGrandChild = ((ICompositeNode) firstChild).getFirstChild();
	INode firstGrandGrandChild = ((ICompositeNode) firstGrandChild).getFirstChild();
	INode firstGrandGrandGrandChild = ((ICompositeNode) firstGrandGrandChild).getFirstChild();
	INode synthetic = ((ICompositeNode) firstGrandGrandGrandChild).getFirstChild();
	assertTrue(synthetic instanceof SyntheticCompositeNode);
	INode expectedLastChild = ((ICompositeNode)synthetic).getLastChild();
	while(expectedLastChild instanceof ICompositeNode)
		expectedLastChild = ((ICompositeNode)expectedLastChild).getLastChild();
	INode lastChild = null;
	for(INode child: synthetic.getAsTreeIterable())
		lastChild = child;
	assertEquals(expectedLastChild, lastChild);
}
 
Example #2
Source File: TreeIteratorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testTreeIteratorForSyntheticNodes_Backwards() throws Exception {
	EObject object = getModel("d - e / e * d");
	ICompositeNode root = NodeModelUtils.getNode(object).getRootNode();
	INode firstChild = root.getFirstChild();
	INode firstGrandChild = ((ICompositeNode) firstChild).getFirstChild();
	INode sibling = firstGrandChild.getNextSibling().getNextSibling().getNextSibling();
	INode siblingChild = ((ICompositeNode) sibling).getFirstChild();
	INode siblingGrandChild = ((ICompositeNode) siblingChild).getFirstChild();
	INode synthetic = ((ICompositeNode) siblingGrandChild).getFirstChild();
	assertTrue(synthetic instanceof SyntheticCompositeNode);
	INode expectedFirstChild = ((ICompositeNode)synthetic).getFirstChild();
	while(expectedFirstChild instanceof ICompositeNode)
		expectedFirstChild = ((ICompositeNode)expectedFirstChild).getFirstChild();
	INode actualFirstChild = null;
	for(INode child: synthetic.getAsTreeIterable().reverse())
		actualFirstChild = child;
	assertEquals(expectedFirstChild, actualFirstChild);
}
 
Example #3
Source File: NodeModelUtilsTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testFindLeafNodeAtOffset_1() throws Exception {
	String grammarText = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model : (name=ID value=ID);";
	Grammar grammar = (Grammar) getModel(grammarText);
	int equalsSign = grammarText.indexOf('=');
	ICompositeNode grammarNode = NodeModelUtils.getNode(grammar);
	ILeafNode leafNodeAtOffset = NodeModelUtils.findLeafNodeAtOffset(grammarNode, equalsSign);
	assertEquals("=", leafNodeAtOffset.getText());
	boolean syntheticNodeSeen = false;
	INode parent = leafNodeAtOffset.getParent();
	while(parent != null) {
		// walk up the tree to make sure we call #findLeafNodeAtOffset with synthetic nodes, too
		ILeafNode otherLeafNode = NodeModelUtils.findLeafNodeAtOffset(parent, equalsSign);
		assertSame(leafNodeAtOffset, otherLeafNode);
		if (parent instanceof SyntheticCompositeNode)
			syntheticNodeSeen = true;
		parent = parent.getParent();
	}
	assertTrue(syntheticNodeSeen);
}
 
Example #4
Source File: TokenSequencePreservingPartialParsingHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ICompositeNode getReplacedNode(PartialParsingPointers parsingPointers) {
	List<ICompositeNode> validReplaceRootNodes = parsingPointers.getValidReplaceRootNodes();
	ICompositeNode replaceMe = null;
	for (int i = validReplaceRootNodes.size() - 1; i >= 0; --i) {
		replaceMe = validReplaceRootNodes.get(i);
		if (!(replaceMe instanceof SyntheticCompositeNode)) {
			break;	
		}
	}
	return replaceMe;
}
 
Example #5
Source File: TokenSequencePreservingPartialParsingHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isInvalidRootNode(ICompositeNode candidate) {
	if (candidate instanceof SyntheticCompositeNode)
		return true;
	if (candidate.getGrammarElement() instanceof RuleCall) {
		AbstractRule rule = ((RuleCall) candidate.getGrammarElement()).getRule();
		if (!(rule instanceof ParserRule) || GrammarUtil.isDatatypeRule((ParserRule) rule))
			return true;
	}
	if (candidate.getGrammarElement() instanceof Action) {
		return true;
	}
	return false;
}
 
Example #6
Source File: PartialParsingHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isInvalidRootNode(ICompositeNode rootNode, ICompositeNode candidate) {
	int endOffset = candidate.getTotalEndOffset();
	if (candidate instanceof SyntheticCompositeNode)
		return true;
	if (candidate.getGrammarElement() instanceof RuleCall) {
		AbstractRule rule = ((RuleCall) candidate.getGrammarElement()).getRule();
		if (!(rule instanceof ParserRule))
			return true;
		ParserRule casted = (ParserRule) rule;
		if (GrammarUtil.isDatatypeRule(casted) || casted.isFragment() || !casted.getParameters().isEmpty()) {
			return true;
		}
		if (isInvalidDueToPredicates((AbstractElement) candidate.getGrammarElement()))
			return true;
	}
	if (candidate.getGrammarElement() instanceof Action) {
		return true;
	}
	if (endOffset == rootNode.getTotalEndOffset()) {
		INode lastChild = getLastChild(candidate);
		if (lastChild instanceof ICompositeNode) {
			INode lastLeaf = getLastLeaf(candidate);
			if (isInvalidLastChildNode(candidate, lastLeaf)) {
				return true;
			}
		}
		if (isInvalidLastChildNode(candidate, lastChild)) {
			return true;
		}
	}
	return false;
}
 
Example #7
Source File: FixedPartialParsingHelper.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean isInvalidRootNode(final ICompositeNode rootNode, final ICompositeNode candidate) {
  int endOffset = candidate.getTotalEndOffset();
  if (candidate instanceof SyntheticCompositeNode) {
    return true;
  }
  if (candidate.getGrammarElement() instanceof RuleCall) {
    AbstractRule rule = ((RuleCall) candidate.getGrammarElement()).getRule();
    if (!(rule instanceof ParserRule) || GrammarUtil.isDatatypeRule((ParserRule) rule)) {
      return true;
    } else if (isInvalidDueToPredicates((AbstractElement) candidate.getGrammarElement())) {
      return true;
    }
  }
  if (candidate.getGrammarElement() instanceof Action) {
    return true;
  }
  if (endOffset == rootNode.getTotalEndOffset()) {
    INode lastChild = getLastChild(candidate);
    if (lastChild instanceof ICompositeNode) {
      INode lastLeaf = getLastLeaf(candidate);
      if (isInvalidLastChildNode(candidate, lastLeaf)) {
        return true;
      }
    }
    if (isInvalidLastChildNode(candidate, lastChild)) {
      return true;
    }
  }
  return false;
}