Search in sources :

Example 1 with Node

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node in project xtext-core by eclipse.

the class ChangeSerializerTest method testRenameGlobal1.

@Test
public void testRenameGlobal1() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#1 root1;");
    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 root2 { ref root1 }");
    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 IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
    final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
        model.setName("newroot");
    };
    serializer.<Resource>addModification(model.eResource(), _function);
    Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    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 <3:5|newroot>;");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("3 5 \"root1\" -> \"newroot\"");
    _builder_2.newLine();
    _builder_2.append("----------------- inmemory:/file2.pstl (syntax: <offset|text>) -----------------");
    _builder_2.newLine();
    _builder_2.append("#1 root2 { ref <15:5|newroot> }");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("15 5 \"root1\" -> \"newroot\"");
    _builder_2.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
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 2 with Node

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node in project xtext-core by eclipse.

the class ChangeSerializerTest method testRenameFqn1.

@Test
public void testRenameFqn1() {
    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:5|a1.b> <21:7|a1.b> <29:9|a1.b> { a1 { <46:2|b> refs <54:2|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 5 \"a1.a2\" -> \"a1.b\"");
    _builder_1.newLine();
    _builder_1.append("21 7 \"X.a1.a2\" -> \"a1.b\"");
    _builder_1.newLine();
    _builder_1.append("29 9 \"r.X.a1.a2\" -> \"a1.b\"");
    _builder_1.newLine();
    _builder_1.append("46 2 \"a2\" -> \"b\"");
    _builder_1.newLine();
    _builder_1.append("54 2 \"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 3 with Node

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node in project xtext-core by eclipse.

the class PartialSerializerTest method testMoveInList1.

@Test
public void testMoveInList1() {
    final IChangeSerializer.IModification<Node> _function = (Node it) -> {
        it.getChildren().move(0, 1);
    };
    ITextRegionAccess _recordDiff = this.<Node>recordDiff(Node.class, "#1 root { Foo; Bar; }", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0   H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B Node\'root\'           Model");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("0 2    S \"#1\"                 Model:\'#1\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("2 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("3 4    S \"root\"               Node:name=ID");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("7 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("8 1    S \"{\"                  Node:\'{\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("9 1 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("B Node\'Bar\'            Node:children+=Node path:Node\'root\'/children[0]");
    _builder.newLine();
    _builder.append("10 3 1   S \"Bar\"                Node:name=ID");
    _builder.newLine();
    _builder.append("13 0 1   H");
    _builder.newLine();
    _builder.append("13 1 1   S \";\"                  Node:\';\'");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("E Node\'Bar\'            Node:children+=Node path:Node\'root\'/children[0]");
    _builder.newLine();
    _builder.append("14 0 1  H");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("B Node\'Foo\'            Node:children+=Node path:Node\'root\'/children[1]");
    _builder.newLine();
    _builder.append("14 3     S \"Foo\"                Node:name=ID");
    _builder.newLine();
    _builder.append("17 0     H");
    _builder.newLine();
    _builder.append("17 1     S \";\"                  Node:\';\'");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("E Node\'Foo\'            Node:children+=Node path:Node\'root\'/children[1]");
    _builder.newLine();
    _builder.append("18   2  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("   ");
    _builder.append("2    \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("20 1    S \"}\"                  Node:\'}\'");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E Node\'root\'           Model");
    _builder.newLine();
    _builder.append("21 0   H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("9 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("10 3 S \"Foo\"                Node:name=ID");
    _builder.newLine();
    _builder.append("------------ diff 2 ------------");
    _builder.newLine();
    _builder.append("14 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("15 3  S \"Bar\"                Node:name=ID");
    _builder.newLine();
    _builder.append("18 0  H");
    _builder.newLine();
    _builder.append("18 1  S \";\"                  Node:\';\'");
    _builder.newLine();
    _builder.append("19 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 4 with Node

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node in project xtext-core by eclipse.

the class PartialSerializationTestLanguageFormatter method _format.

protected void _format(final Node obj, @Extension final IFormattableDocument document) {
    List<ISemanticRegion> _keywords = this.textRegionExtensions.regionFor(obj).keywords(";");
    for (final ISemanticRegion r : _keywords) {
        final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        document.append(document.prepend(r, _function), _function_1);
    }
    EList<Node> _children = obj.getChildren();
    for (final Node child : _children) {
        document.<Node>format(child);
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 5 with Node

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node in project xtext-core by eclipse.

the class NodeImpl method setRef.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setRef(Node newRef) {
    Node oldRef = ref;
    ref = newRef;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, PartialSerializationTestLanguagePackage.NODE__REF, oldRef, ref));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)

Aggregations

Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)13 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)13 Test (org.junit.Test)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)12 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)12 EList (org.eclipse.emf.common.util.EList)4 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)4 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)1 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)1 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)1 IUpdatableReference (org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference)1 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)1