Search in sources :

Example 1 with ChangeSerializer

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

the class ChangeSerializerWithEmfTest method testChangeRefToXML.

@Test
public void testChangeRefToXML() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#21 MyPackage.MyClass1");
    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=\"#//MyClass2\"/>");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass2\"/>");
    _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 EClassRef model = this._changeSerializerTestHelper.<EClassRef>contents(rs, "inmemory:/file1.pstl", EClassRef.class);
    final ChangeSerializer serializer = this.serializerProvider.get();
    final IChangeSerializer.IModification<EClassRef> _function = (EClassRef it) -> {
        EClassifier _get = model.getRef().getEPackage().getEClassifiers().get(1);
        model.setRef(((EClass) _get));
    };
    serializer.<EClassRef>addModification(model, _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("#21 <4:18|MyPackage.MyClass2>");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("4 18 \"MyPackage.MyClass1\" -> \"MyPackage.MyClass2\"");
    _builder_2.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : EClassRef(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.EClassRef) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 2 with ChangeSerializer

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

the class ChangeSerializerWithEmfTest method testChangeInXML.

@Test
public void testChangeInXML() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#21 MyPackage.MyClass1");
    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\"/>");
    _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 EPackage model = this._changeSerializerTestHelper.<EPackage>contents(rs, "inmemory:/file2.ecore", EPackage.class);
    final ChangeSerializer serializer = this.serializerProvider.get();
    final IChangeSerializer.IModification<EPackage> _function = (EPackage it) -> {
        EClassifier _head = IterableExtensions.<EClassifier>head(model.getEClassifiers());
        ((EClass) _head).setName("NewClass");
    };
    serializer.<EPackage>addModification(model, _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_2 = new StringConcatenation();
    _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=\"NewClass\"/>");
    _builder_2.newLine();
    _builder_2.append("</ecore:EPackage>");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_2.newLine();
    _builder_2.append("#21 <4:18|MyPackage.NewClass>");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("4 18 \"MyPackage.MyClass1\" -> \"MyPackage.NewClass\"");
    _builder_2.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EPackage(org.eclipse.emf.ecore.EPackage) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 3 with ChangeSerializer

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

the class PartialSerializerTest method recordDiff.

private <T extends EObject> ITextRegionAccess recordDiff(final Class<T> modelType, final CharSequence modelText, final IChangeSerializer.IModification<T> modification) {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    String _string = modelText.toString();
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _string);
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final T model = this._changeSerializerTestHelper.<T>contents(rs, "inmemory:/file1.pstl", modelType);
    final ChangeSerializer serializer = this.serializerProvider.get();
    serializer.<T>addModification(model, modification);
    return this._changeSerializerTestHelper.endRecordChangesToTextRegions(serializer);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 4 with ChangeSerializer

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

the class FileAwareTestLanguageImportTest method testNestedPackage.

@Test
public void testNestedPackage() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo ");
    _builder.newLine();
    _builder.append("element X {}");
    _builder.newLine();
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/foo/X.fileawaretestlanguage", _builder.toString());
    this._importTestHelper.operator_add(fs, _mappedTo);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package foo.bar ");
    _builder_1.newLine();
    _builder_1.append("element Y { ref foo.X }");
    _builder_1.newLine();
    Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/foo/bar/Y.fileawaretestlanguage", _builder_1.toString());
    this._importTestHelper.operator_add(fs, _mappedTo_1);
    final ResourceSet rs = this._importTestHelper.createResourceSet(fs);
    final PackageDeclaration model1 = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/foo/X.fileawaretestlanguage", PackageDeclaration.class);
    final PackageDeclaration model2 = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/foo/bar/Y.fileawaretestlanguage", PackageDeclaration.class);
    final ChangeSerializer serializer = this.serializerProvider.get();
    final IChangeSerializer.IModification<PackageDeclaration> _function = (PackageDeclaration it) -> {
        it.setName("foo2");
    };
    serializer.<PackageDeclaration>addModification(model1, _function);
    final IChangeSerializer.IModification<PackageDeclaration> _function_1 = (PackageDeclaration it) -> {
        model2.setName("foo2.bar");
        model2.setName("foo2.bar");
    };
    serializer.<PackageDeclaration>addModification(model2, _function_1);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._importTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("-------- inmemory:/foo/X.fileawaretestlanguage (syntax: <offset|text>) ---------");
    _builder_2.newLine();
    _builder_2.append("package <8:3|foo2> ");
    _builder_2.newLine();
    _builder_2.append("element X {}");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("8 3 \"foo\" -> \"foo2\"");
    _builder_2.newLine();
    _builder_2.append("------ inmemory:/foo/bar/Y.fileawaretestlanguage (syntax: <offset|text>) -------");
    _builder_2.newLine();
    _builder_2.append("package <8:7|foo2.bar> ");
    _builder_2.newLine();
    _builder_2.append("<17:0|import foo2.X");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append(">element Y { ref <33:5|X> }");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append(" ");
    _builder_2.append("8 7 \"foo.bar\" -> \"foo2.bar\"");
    _builder_2.newLine();
    _builder_2.append("17 0 \"\" -> \"import foo2.X\\n\\n\"");
    _builder_2.newLine();
    _builder_2.append("33 5 \"foo.X\" -> \"X\"");
    _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 5 with ChangeSerializer

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

the class FileAwareTestLanguageImportTest method testRenameGlobal1.

@Test
public void testRenameGlobal1() {
    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 pkg2");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import pkg1.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("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 pkg2");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("import <21:8|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("21 8 \"pkg1.Foo\" -> \"newpackage.Foo\"");
    _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)

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