Search in sources :

Example 1 with InvariantChecker

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());
            }
        }
    }
}
Also used : InvariantChecker(org.eclipse.xtext.nodemodel.impl.InvariantChecker) INode(org.eclipse.xtext.nodemodel.INode) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 2 with InvariantChecker

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());
}
Also used : InvariantChecker(org.eclipse.xtext.nodemodel.impl.InvariantChecker) INode(org.eclipse.xtext.nodemodel.INode)

Example 3 with InvariantChecker

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);
    }
}
Also used : InvariantChecker(org.eclipse.xtext.nodemodel.impl.InvariantChecker) StringInputStream(org.eclipse.xtext.util.StringInputStream) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

InvariantChecker (org.eclipse.xtext.nodemodel.impl.InvariantChecker)3 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 INode (org.eclipse.xtext.nodemodel.INode)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 Test (org.junit.Test)2 EObject (org.eclipse.emf.ecore.EObject)1 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1