use of org.eclipse.xtext.nodemodel.impl.InvariantChecker in project xtext-xtend by eclipse.
the class ParserTest method testAllGrammarElementsUnique.
@Test
public void testAllGrammarElementsUnique() throws Exception {
XtendClass clazz = clazz("class Foo { def m() { newArrayList() } }");
XtextResource resource = (XtextResource) clazz.eResource();
ICompositeNode root = resource.getParseResult().getRootNode();
new InvariantChecker().checkInvariant(root);
assertSame(root, root.getRootNode());
Set<EObject> grammarElements = Sets.newHashSet();
for (INode node : root.getAsTreeIterable()) {
if (node instanceof ICompositeNode) {
if (node.getGrammarElement() == null) {
fail("node without grammar element");
}
if (!grammarElements.add(node.getGrammarElement())) {
fail(node.getGrammarElement().toString());
}
}
}
}
use of org.eclipse.xtext.nodemodel.impl.InvariantChecker in project xtext-core by eclipse.
the class PartialParsingProcessor method assertEqual.
private void assertEqual(String data, String newData, ICompositeNode fromScratch, ICompositeNode reparsed) {
InvariantChecker checker = new InvariantChecker();
checker.checkInvariant(reparsed);
Iterator<INode> scratchIterator = fromScratch.getAsTreeIterable().iterator();
Iterator<INode> reparsedIterator = reparsed.getAsTreeIterable().iterator();
while (scratchIterator.hasNext()) {
Assert.assertTrue(reparsedIterator.hasNext());
assertEqualNodes(data, newData, scratchIterator.next(), reparsedIterator.next());
}
Assert.assertFalse(scratchIterator.hasNext());
Assert.assertFalse(reparsedIterator.hasNext());
}
use of org.eclipse.xtext.nodemodel.impl.InvariantChecker in project xtext-core by eclipse.
the class OffsetInformationTest method testCheckParsing.
@Test
public void testCheckParsing() throws Exception {
String string = "spielplatz 34 'holla' {\n" + " kind (Horst 3)\n" + " erwachsener (Julia 45)\n" + " erwachsener (Herrmann 50)\n" + " erwachsener (Herrmann 50)\n" + " erwachsener (Herrmann 50)\n" + " erwachsener (Herrmann 50)\n" + " erwachsener (Herrmann 50)\n" + "}";
XtextResource resource = getResource(new StringInputStream(string));
ICompositeNode rootNode = resource.getParseResult().getRootNode();
for (int i = 0; i < string.length() / 2; i++) {
String substring = string.substring(i, string.length() - i);
resource.update(i, substring.length(), substring);
ICompositeNode model = resource.getParseResult().getRootNode();
new InvariantChecker().checkInvariant(model);
assertSameStructure(rootNode, model);
}
}
Aggregations