Search in sources :

Example 51 with ICompositeNode

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

the class ParseErrorHandlingTest method testTrailingRecoverableError.

@Test
public void testTrailingRecoverableError() throws Exception {
    with(TreeTestLanguageStandaloneSetup.class);
    String model = "parent ('Teststring') { \n" + "	child ('Teststring'){};\n" + "	child ('Teststring'){};\n" + "};\n" + "};\n" + "\n";
    Resource res = getResourceFromStringAndExpect(model, 1);
    assertEquals(res.getErrors().size(), 1, res.getErrors().size());
    Diagnostic diag = res.getErrors().get(0);
    assertNotNull(diag);
    assertEquals(5, diag.getLine());
    Model parsedModel = (Model) res.getContents().get(0);
    assertNotNull(parsedModel);
    ICompositeNode composite = NodeModelUtils.getNode(parsedModel);
    assertNotNull(composite);
    List<ILeafNode> leafs = Lists.newArrayList(composite.getLeafNodes());
    ILeafNode lastWs = leafs.get(leafs.size() - 1);
    assertTrue(lastWs.isHidden());
    assertNull(lastWs.getSyntaxErrorMessage());
    ILeafNode lastNode = leafs.get(leafs.size() - 2);
    assertFalse(lastNode.isHidden());
    assertNotNull(lastNode);
    assertEquals("};", lastNode.getText());
    assertNotNull(lastNode.getSyntaxErrorMessage());
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Model(org.eclipse.xtext.testlanguages.treeTestLanguage.Model) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 52 with ICompositeNode

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

the class ParseErrorHandlingTest method testLexerError_02.

@Test
public void testLexerError_02() throws Exception {
    with(ReferenceGrammarTestLanguageStandaloneSetup.class);
    String model = "spielplatz 100 '}";
    EObject object = getModelAndExpect(model, 1);
    ICompositeNode node = NodeModelUtils.getNode(object).getRootNode();
    assertEquals(1, Iterables.size(allSyntaxErrors(node)));
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 53 with ICompositeNode

use of org.eclipse.xtext.nodemodel.ICompositeNode 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)

Example 54 with ICompositeNode

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

the class PartialParserTest method testPartialParseConcreteRuleFirstToken_02.

@Test
public void testPartialParseConcreteRuleFirstToken_02() throws Exception {
    with(PartialParserTestLanguageStandaloneSetup.class);
    String model = "container c1 {\n" + "  children {\n" + "    -> C ( ch1 )\n" + "  }" + "}";
    XtextResource resource = getResourceFromString(model);
    assertTrue(resource.getErrors().isEmpty());
    ICompositeNode root = resource.getParseResult().getRootNode();
    ILeafNode children = findLeafNodeByText(root, model, "children");
    // change the model and undo the change
    resource.update(model.indexOf("n {") + 2, 1, " {");
    resource.update(model.indexOf("n {") + 2, 2, "{");
    assertSame(root, resource.getParseResult().getRootNode());
    assertNotSame(children, findLeafNodeByText(root, model, "children"));
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 55 with ICompositeNode

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

the class PartialParserTest method testPartialParseConcreteRuleFirstInnerToken_01.

@Test
public void testPartialParseConcreteRuleFirstInnerToken_01() throws Exception {
    with(PartialParserTestLanguageStandaloneSetup.class);
    String model = "container c1 {\n" + "  children {\n" + "    -> C ( ch1 )\n" + "  }" + "}";
    XtextResource resource = getResourceFromString(model);
    assertTrue(resource.getErrors().isEmpty());
    ICompositeNode root = resource.getParseResult().getRootNode();
    ILeafNode childrenLeaf = findLeafNodeByText(root, model, "children");
    ILeafNode arrowLeaf = findLeafNodeByText(root, model, "->");
    resource.update(model.indexOf("->"), 2, "->");
    resource.update(model.indexOf("->"), 2, "->");
    assertSame(root, resource.getParseResult().getRootNode());
    assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
    assertSame(arrowLeaf, findLeafNodeByText(root, model, "->"));
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)263 Test (org.junit.Test)87 INode (org.eclipse.xtext.nodemodel.INode)79 EObject (org.eclipse.emf.ecore.EObject)70 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)57 XtextResource (org.eclipse.xtext.resource.XtextResource)41 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)24 ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)20 Resource (org.eclipse.emf.ecore.resource.Resource)19 Model (org.eclipse.xtext.valueconverter.bug250313.Model)15 IParseResult (org.eclipse.xtext.parser.IParseResult)14 ParserRule (org.eclipse.xtext.ParserRule)12 ITextRegion (org.eclipse.xtext.util.ITextRegion)12 RuleCall (org.eclipse.xtext.RuleCall)11 CrossReference (org.eclipse.xtext.CrossReference)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)8 AbstractRule (org.eclipse.xtext.AbstractRule)8 Keyword (org.eclipse.xtext.Keyword)8