Search in sources :

Example 61 with ICompositeNode

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

the class EmptyModelTest method assertEmptyModel.

private void assertEmptyModel(String model) throws Exception {
    IParseResult parseResult = getResource(new StringInputStream(model)).getParseResult();
    assertNull(parseResult.getRootASTElement());
    ICompositeNode rootNode = parseResult.getRootNode();
    assertNotNull(rootNode);
    assertEquals(model, rootNode.getText());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 62 with ICompositeNode

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

the class SerializeTest method checkSerialize.

private void checkSerialize(String model, int expectedErrors) throws Exception {
    ICompositeNode node = getRootNodeAndExpect(model, expectedErrors);
    String serialize = node.getText();
    assertEquals(model, serialize);
}
Also used : ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 63 with ICompositeNode

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

the class FormatterTest method testBug471212.

@Test
public void testBug471212() throws Exception {
    String model = "test wrappingdt f\nb kw1";
    ICompositeNode node = NodeModelUtils.getNode(getModel(model)).getRootNode();
    AccessibleFormatter formatter = get(AccessibleFormatter.class);
    formatter.setNodeModelStreamer(get(BrokenStreamer.class));
    IFormattedRegion region = formatter.format(node, 0, model.length());
    String actual = region.getFormattedText();
    assertEquals(model, actual);
    assertEqualTokenStreams(model);
    assertPreserved(model);
}
Also used : IFormattedRegion(org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 64 with ICompositeNode

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

the class Bug305397Test method testBug.

@Test
public void testBug() throws Exception {
    with(new Bug305397StandaloneSetup());
    Model model = (Model) getModel("   a element \n   element X end\n element Y end \nend");
    Element outer = model.getElements().get(0);
    Element firstInner = outer.getElements().get(0);
    ICompositeNode outerNode = NodeModelUtils.getNode(outer);
    assertEquals(3, outerNode.getOffset());
    ICompositeNode firstInnerNode = NodeModelUtils.getNode(firstInner);
    assertEquals(17, firstInnerNode.getOffset());
}
Also used : Element(org.eclipse.xtext.parsetree.impl.bug305397.Element) Model(org.eclipse.xtext.parsetree.impl.bug305397.Model) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 65 with ICompositeNode

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

the class CommentAssociationTest method createModel2CommentMap.

protected Multimap<EObject, String> createModel2CommentMap(Model model) {
    ICompositeNode rootNode = NodeModelUtils.getNode(model).getRootNode();
    ICommentAssociater commentAssociater = getInjector().getInstance(ICommentAssociater.class);
    Map<ILeafNode, EObject> map = commentAssociater.associateCommentsWithSemanticEObjects(model, Collections.singleton(rootNode));
    Multimap<EObject, String> multimap = ArrayListMultimap.create();
    for (Map.Entry<ILeafNode, EObject> entry : map.entrySet()) {
        multimap.put(entry.getValue(), entry.getKey().getText());
    }
    return multimap;
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Map(java.util.Map) ICommentAssociater(org.eclipse.xtext.parsetree.reconstr.ICommentAssociater)

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