Search in sources :

Example 16 with IChangeSerializer

use of org.eclipse.xtext.ide.serializer.IChangeSerializer in project xtext-core by eclipse.

the class ChangeSerializerTest method testAddChildElement.

@Test
public void testAddChildElement() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content = "#22 {\n" + "	child1\n" + "	children1 {\n" + "		child2 child3\n" + "	}\n" + "}";
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file-move.pstl", content));
    ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
    TwoChildLists model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file-move.pstl", TwoChildLists.class);
    IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
    serializer.addModification(model.eResource(), (Resource it) -> {
        MandatoryValue newMandatoryValue = fac.createMandatoryValue();
        newMandatoryValue.setName("newChild");
        model.getDirectChildren().add(newMandatoryValue);
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "--------------- inmemory:/file-move.pstl (syntax: <offset|text>) ---------------\n" + "#22 {\n" + "	child1<13:0| newChild>\n" + "	children1 {\n" + "		child2 child3\n" + "	}\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "13 0 \"\" -> \" newChild\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) TwoChildLists(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists) 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 17 with IChangeSerializer

use of org.eclipse.xtext.ide.serializer.IChangeSerializer in project xtext-core by eclipse.

the class ChangeSerializerTest method testMoveElement.

@Test
public void testMoveElement() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content = "#22 {\n" + "	child1\n" + "	children1 {\n" + "		child2 jumper\n" + "	}\n" + "}";
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file-move1.pstl", content));
    ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
    TwoChildLists model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file-move1.pstl", TwoChildLists.class);
    IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
    serializer.addModification(model.eResource(), (Resource it) -> {
        model.getDirectChildren().add(IterableExtensions.findFirst(model.getChildsList().getChildren(), (MandatoryValue v) -> "jumper".equals(v.getName())));
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "-------------- inmemory:/file-move1.pstl (syntax: <offset|text>) ---------------\n" + "#22 {\n" + "	child1<13:0| jumper>\n" + "	children1 {\n" + "		child2 <36:6|>\n" + "	}\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "13 0 \"\" -> \" jumper\"\n" + "36 6 \"jumper\" -> \"\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) TwoChildLists(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists) 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 18 with IChangeSerializer

use of org.eclipse.xtext.ide.serializer.IChangeSerializer in project xtext-core by eclipse.

the class ChangeSerializerTest method testInsertBeforeComment.

@Test
public void testInsertBeforeComment() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content = "#1 root {\n" + "	/**/ \n" + "	child1;\n" + "}\n";
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", content));
    ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
    Node model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", Node.class);
    IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
    serializer.addModification(model.eResource(), (Resource it) -> {
        Node newNode = fac.createNode();
        newNode.setName("bazz");
        model.getChildren().add(0, newNode);
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root {<9:0| bazz;>\n" + "	/**/ \n" + "	child1;\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "9 0 \"\" -> \" bazz;\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
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) 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 19 with IChangeSerializer

use of org.eclipse.xtext.ide.serializer.IChangeSerializer in project xtext-core by eclipse.

the class ChangeSerializerTest method testAddElements.

@Test
public void testAddElements() {
    String uri = "inmemory:/file-add.pstl";
    InMemoryURIHandler fs = new InMemoryURIHandler();
    changeSerializerTestHelper.operator_add(fs, Pair.of(uri, "#23"));
    ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
    ChildWithSubChilds model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, uri, ChildWithSubChilds.class);
    IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
    serializer.addModification(model.eResource(), (Resource it) -> {
        ChildWithSubChild newChildWithSubChild = fac.createChildWithSubChild();
        SubChild newSubChild1 = fac.createSubChild();
        newSubChild1.setName("A");
        newChildWithSubChild.getSubChilds().add(newSubChild1);
        model.getChildren().add(newChildWithSubChild);
        SubChild newSubChild = fac.createSubChild();
        newSubChild.setName("A2");
        model.getChildren().get(0).getSubChilds().add(newSubChild);
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "--------------- inmemory:/file-add.pstl (syntax: <offset|text>) ----------------\n" + "<0:3|#23 subs A A2>\n" + "--------------------------------------------------------------------------------\n" + "0 3 \"#23\" -> \"#23 subs A A2\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : ChildWithSubChild(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.ChildWithSubChild) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Resource(org.eclipse.emf.ecore.resource.Resource) ChildWithSubChild(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.ChildWithSubChild) SubChild(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.SubChild) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ChildWithSubChilds(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.ChildWithSubChilds) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 20 with IChangeSerializer

use of org.eclipse.xtext.ide.serializer.IChangeSerializer in project xtext-core by eclipse.

the class ChangeSerializerTest method testInsertTwoChild.

@Test
public void testInsertTwoChild() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#1 root { child1 { foo1; } }"));
    ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
    Node model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", Node.class);
    IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
    serializer.addModification(model.eResource(), (Resource it) -> {
        Node newNode1 = fac.createNode();
        newNode1.setName("bazz1");
        model.getChildren().get(0).getChildren().add(newNode1);
        Node newNode2 = fac.createNode();
        newNode2.setName("bazz2");
        model.getChildren().get(0).getChildren().add(newNode2);
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root { child1 { foo1; <25:0|bazz1; bazz2; >} }\n" + "--------------------------------------------------------------------------------\n" + "25 0 \"\" -> \"bazz1; bazz2; \"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
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) 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)

Aggregations

IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)26 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)23 Resource (org.eclipse.emf.ecore.resource.Resource)19 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)19 Test (org.junit.Test)19 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)18 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)11 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)5 EObject (org.eclipse.emf.ecore.EObject)4 TwoChildLists (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists)4 SubMonitor (org.eclipse.core.runtime.SubMonitor)3 RenameChange (org.eclipse.xtext.ide.refactoring.RenameChange)3 RenameContext (org.eclipse.xtext.ide.refactoring.RenameContext)3 IProject (org.eclipse.core.resources.IProject)2 URI (org.eclipse.emf.common.util.URI)2 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)2 IRenameStrategy2 (org.eclipse.xtext.ide.refactoring.IRenameStrategy2)2 ResourceRelocationContext (org.eclipse.xtext.ide.refactoring.ResourceRelocationContext)2 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2