Search in sources :

Example 6 with ChangeSerializer

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

the class FileAwareTestLanguageImportTest method testMoveToNewPackage.

@Test
public void testMoveToNewPackage() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package pkg1");
    _builder.newLine();
    _builder.newLine();
    _builder.append("element Foo {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.fileawaretestlanguage", _builder.toString());
    this._importTestHelper.operator_add(fs, _mappedTo);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package pkg1");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("element Bar {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("ref Foo");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.fileawaretestlanguage", _builder_1.toString());
    this._importTestHelper.operator_add(fs, _mappedTo_1);
    final ResourceSet rs = this._importTestHelper.createResourceSet(fs);
    final PackageDeclaration model = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/file1.fileawaretestlanguage", PackageDeclaration.class);
    final ChangeSerializer serializer = this.serializerProvider.get();
    final IChangeSerializer.IModification<PackageDeclaration> _function = (PackageDeclaration it) -> {
        model.setName("newpackage");
    };
    serializer.<PackageDeclaration>addModification(model, _function);
    Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._importTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("-------- inmemory:/file1.fileawaretestlanguage (syntax: <offset|text>) ---------");
    _builder_2.newLine();
    _builder_2.append("package <8:4|newpackage>");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("element Foo {");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("8 4 \"pkg1\" -> \"newpackage\"");
    _builder_2.newLine();
    _builder_2.append("-------- inmemory:/file2.fileawaretestlanguage (syntax: <offset|text>) ---------");
    _builder_2.newLine();
    _builder_2.append("package pkg1");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("<14:0|import newpackage.Foo");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append(">element Bar {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("ref Foo");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("14 0 \"\" -> \"import newpackage...\"");
    _builder_2.newLine();
    this._importTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 7 with ChangeSerializer

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

the class FileAwareTestLanguageImportTest method testMoveIntoLocalPackage.

@Test
public void testMoveIntoLocalPackage() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package other");
    _builder.newLine();
    _builder.newLine();
    _builder.append("element Foo {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.fileawaretestlanguage", _builder.toString());
    this._importTestHelper.operator_add(fs, _mappedTo);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package pkg1");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import other.Foo");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("element Bar {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("ref Foo");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.fileawaretestlanguage", _builder_1.toString());
    this._importTestHelper.operator_add(fs, _mappedTo_1);
    final ResourceSet rs = this._importTestHelper.createResourceSet(fs);
    final PackageDeclaration model = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/file1.fileawaretestlanguage", PackageDeclaration.class);
    final ChangeSerializer serializer = this.serializerProvider.get();
    final IChangeSerializer.IModification<PackageDeclaration> _function = (PackageDeclaration it) -> {
        model.setName("pkg1");
    };
    serializer.<PackageDeclaration>addModification(model, _function);
    Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._importTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("-------- inmemory:/file1.fileawaretestlanguage (syntax: <offset|text>) ---------");
    _builder_2.newLine();
    _builder_2.append("package <8:5|pkg1>");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("element Foo {");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("8 5 \"other\" -> \"pkg1\"");
    _builder_2.newLine();
    _builder_2.append("-------- inmemory:/file2.fileawaretestlanguage (syntax: <offset|text>) ---------");
    _builder_2.newLine();
    _builder_2.append("package pkg1");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("<14:18|>element Bar {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("ref Foo");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("14 18 \"import other.Foo\\n\\n\" -> \"\"");
    _builder_2.newLine();
    this._importTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 8 with ChangeSerializer

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

the class ChangeSerializerWithEmfTest method testChangeInDSL.

@Test
public void testChangeInDSL() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#20 DslEClass");
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    _builder_1.newLine();
    _builder_1.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\" eSuperTypes=\"inmemory:/file1.pstl#//@clazz.0\"/>");
    _builder_1.newLine();
    _builder_1.append("</ecore:EPackage>");
    _builder_1.newLine();
    Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.ecore", _builder_1.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo_1);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final Model model = this._changeSerializerTestHelper.<Model>contents(rs, "inmemory:/file1.pstl", Model.class);
    final ChangeSerializer serializer = this.serializerProvider.get();
    final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
        EClass _get = model.getClazz().get(0);
        _get.setName("ChangedName");
        EList<EClass> _clazz = model.getClazz();
        EClass _createEClass = EcoreFactory.eINSTANCE.createEClass();
        final Procedure1<EClass> _function_1 = (EClass it_1) -> {
            it_1.setName("NewName");
        };
        EClass _doubleArrow = ObjectExtensions.<EClass>operator_doubleArrow(_createEClass, _function_1);
        _clazz.add(0, _doubleArrow);
        Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    };
    serializer.<Resource>addModification(model.eResource(), _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_2.newLine();
    _builder_2.append("#20 <4:0|NewName ><4:9| ChangedName>");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("4 0 \"\" -> \"NewName \"");
    _builder_2.newLine();
    _builder_2.append("4 9 \"DslEClass\" -> \" ChangedName\"");
    _builder_2.newLine();
    _builder_2.append("---------------------------- inmemory:/file2.ecore -----------------------------");
    _builder_2.newLine();
    _builder_2.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    _builder_2.newLine();
    _builder_2.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
    _builder_2.newLine();
    _builder_2.append("    ");
    _builder_2.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
    _builder_2.newLine();
    _builder_2.append("  ");
    _builder_2.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\" eSuperTypes=\"file1.pstl#//@clazz.1\"/>");
    _builder_2.newLine();
    _builder_2.append("</ecore:EPackage>");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EClass(org.eclipse.emf.ecore.EClass) 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) Model(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Model) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 9 with ChangeSerializer

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

the class ChangeSerializerWithImports method testRenameGlobal1.

@Test
public void testRenameGlobal1() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#1 root1 { child1; }");
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("#1 import root1.child1 refs child1;");
    Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.pstl", _builder_1.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo_1);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final Node model = this._changeSerializerTestHelper.<Node>contents(rs, "inmemory:/file1.pstl", Node.class);
    final ChangeSerializer serializer = this.serializerProvider.get();
    final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
        Node _get = model.getChildren().get(0);
        _get.setName("newchild");
        Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    };
    serializer.<Resource>addModification(model.eResource(), _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_2.newLine();
    _builder_2.append("#1 root1 { <11:6|newchild>; }");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("11 6 \"child1\" -> \"newchild\"");
    _builder_2.newLine();
    _builder_2.append("----------------- inmemory:/file2.pstl (syntax: <offset|text>) -----------------");
    _builder_2.newLine();
    _builder_2.append("#1 import <10:12|root1.newchild> refs <28:6|newchild>;");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("10 12 \"root1.child1\" -> \"root1.newchild\"");
    _builder_2.newLine();
    _builder_2.append("28  6 \"child1\" -> \"newchild\"");
    _builder_2.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) 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)

Aggregations

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)9 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)9 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)9 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)8 Test (org.junit.Test)8 PackageDeclaration (org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)4 EClassifier (org.eclipse.emf.ecore.EClassifier)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 EList (org.eclipse.emf.common.util.EList)1 EClass (org.eclipse.emf.ecore.EClass)1 EPackage (org.eclipse.emf.ecore.EPackage)1 EClassRef (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.EClassRef)1 Model (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Model)1 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1