Search in sources :

Example 86 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ChangeSerializerTest method testDeleteTwoChildren.

@Test
public void testDeleteTwoChildren() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#1 root { child1; child2; }");
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final Node model = this._changeSerializerTestHelper.<Node>contents(rs, "inmemory:/file1.pstl", Node.class);
    final IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
    final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
        EcoreUtil.remove(model.getChildren().get(1));
        EcoreUtil.remove(model.getChildren().get(0));
    };
    serializer.<Resource>addModification(model.eResource(), _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_1.newLine();
    _builder_1.append("#1 root { <10:7|> <18:7|> }");
    _builder_1.newLine();
    _builder_1.append("--------------------------------------------------------------------------------");
    _builder_1.newLine();
    _builder_1.append("10 7 \"child1;\" -> \"\"");
    _builder_1.newLine();
    _builder_1.append("18 7 \"child2;\" -> \"\"");
    _builder_1.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_1);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 87 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ChangeSerializerTest method testTwoChildren.

@Test
public void testTwoChildren() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#1 root { foo1; foo2; }");
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final Node model = this._changeSerializerTestHelper.<Node>contents(rs, "inmemory:/file1.pstl", Node.class);
    final IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
    final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
        Node _get = model.getChildren().get(0);
        _get.setName("bazz4");
        Node _get_1 = model.getChildren().get(1);
        _get_1.setName("bazz5");
    };
    serializer.<Resource>addModification(model.eResource(), _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_1.newLine();
    _builder_1.append("#1 root { <10:4|bazz4>; <16:4|bazz5>; }");
    _builder_1.newLine();
    _builder_1.append("--------------------------------------------------------------------------------");
    _builder_1.newLine();
    _builder_1.append("10 4 \"foo1\" -> \"bazz4\"");
    _builder_1.newLine();
    _builder_1.append("16 4 \"foo2\" -> \"bazz5\"");
    _builder_1.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_1);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 88 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ChangeSerializerTest method testInsertBeforeComment.

@Test
public void testInsertBeforeComment() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#1 root {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/**/ ");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("child1;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final Node model = this._changeSerializerTestHelper.<Node>contents(rs, "inmemory:/file1.pstl", Node.class);
    final IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
    final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
        EList<Node> _children = model.getChildren();
        Node _createNode = this.fac.createNode();
        final Procedure1<Node> _function_1 = (Node it_1) -> {
            it_1.setName("bazz");
        };
        Node _doubleArrow = ObjectExtensions.<Node>operator_doubleArrow(_createNode, _function_1);
        _children.add(0, _doubleArrow);
    };
    serializer.<Resource>addModification(model.eResource(), _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_1.newLine();
    _builder_1.append("#1 root {<9:0| bazz;>");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("/**/ ");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("child1;");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("--------------------------------------------------------------------------------");
    _builder_1.newLine();
    _builder_1.append("9 0 \"\" -> \" bazz;\"");
    _builder_1.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_1);
}
Also used : InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 89 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ChangeSerializerTest method testRenameFqn1ValueConversion.

@Test
public void testRenameFqn1ValueConversion() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#1 r {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("X refs ^a1.^a2 ^X.^a1.^a2 ^r.^X.^a1.^a2 { a1 { a2 refs ^a2 { a3 { ref ^a3 } } } }");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("Y refs ^b1.^b2 ^Y.^b1.^b2 ^r.^Y.^b1.^b2 { b1 { b2 { ref b2 } } }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final Node model = this._changeSerializerTestHelper.<Node>contents(rs, "inmemory:/file1.pstl", Node.class);
    final IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
    final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
        Node _head = IterableExtensions.<Node>head(IterableExtensions.<Node>head(IterableExtensions.<Node>head(model.getChildren()).getChildren()).getChildren());
        _head.setName("b");
    };
    serializer.<Resource>addModification(model.eResource(), _function);
    Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_1.newLine();
    _builder_1.append("#1 r {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("X refs <15:7|a1.b> <23:10|a1.b> <34:13|a1.b> { a1 { <55:2|b> refs <63:3|b> { a3 { ref ^a3 } } } }");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("Y refs ^b1.^b2 ^Y.^b1.^b2 ^r.^Y.^b1.^b2 { b1 { b2 { ref b2 } } }");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("--------------------------------------------------------------------------------");
    _builder_1.newLine();
    _builder_1.append("15  7 \"^a1.^a2\" -> \"a1.b\"");
    _builder_1.newLine();
    _builder_1.append("23 10 \"^X.^a1.^a2\" -> \"a1.b\"");
    _builder_1.newLine();
    _builder_1.append("34 13 \"^r.^X.^a1.^a2\" -> \"a1.b\"");
    _builder_1.newLine();
    _builder_1.append("55  2 \"a2\" -> \"b\"");
    _builder_1.newLine();
    _builder_1.append("63  3 \"^a2\" -> \"b\"");
    _builder_1.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_1);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 90 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ChangeSerializerTest method testInsertOneChild.

@Test
public void testInsertOneChild() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#1 root { child1 { foo1; } }");
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final Node model = this._changeSerializerTestHelper.<Node>contents(rs, "inmemory:/file1.pstl", Node.class);
    final IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
    final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
        EList<Node> _children = model.getChildren().get(0).getChildren();
        Node _createNode = this.fac.createNode();
        final Procedure1<Node> _function_1 = (Node it_1) -> {
            it_1.setName("bazz");
        };
        Node _doubleArrow = ObjectExtensions.<Node>operator_doubleArrow(_createNode, _function_1);
        _children.add(_doubleArrow);
    };
    serializer.<Resource>addModification(model.eResource(), _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_1.newLine();
    _builder_1.append("#1 root { child1 { foo1; <25:0|bazz; >} }");
    _builder_1.newLine();
    _builder_1.append("--------------------------------------------------------------------------------");
    _builder_1.newLine();
    _builder_1.append("25 0 \"\" -> \"bazz; \"");
    _builder_1.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_1);
}
Also used : InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Aggregations

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)71 Test (org.junit.Test)51 EObject (org.eclipse.emf.ecore.EObject)34 URI (org.eclipse.emf.common.util.URI)32 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)32 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)21 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)21 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)17 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)17 XtextResource (org.eclipse.xtext.resource.XtextResource)16 EPackage (org.eclipse.emf.ecore.EPackage)12 IFile (org.eclipse.core.resources.IFile)10 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)10 ArrayList (java.util.ArrayList)9 EClass (org.eclipse.emf.ecore.EClass)9 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)9 IOException (java.io.IOException)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8