Search in sources :

Example 6 with Node

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

the class PartialSerializationTestLanguageReferenceUpdater method update.

@Override
public void update(final IReferenceUpdaterContext context) {
    super.update(context);
    final Node node = IterableExtensions.<Node>head(Iterables.<Node>filter(context.getResource().getContents(), Node.class));
    if ((node == null)) {
        return;
    }
    final HashSet<Import> toDelete = CollectionLiterals.<Import>newHashSet();
    final HashSet<QualifiedName> toAdd = CollectionLiterals.<QualifiedName>newHashSet();
    final HashMap<Import, QualifiedName> toChange = CollectionLiterals.<Import, QualifiedName>newHashMap();
    final Function1<Import, QualifiedName> _function = (Import it) -> {
        return this.converter.toQualifiedName(it.getImportedNamespace());
    };
    final Map<QualifiedName, Import> imports = IterableExtensions.<QualifiedName, Import>toMap(node.getImports(), _function);
    List<IUpdatableReference> _updatableReferences = context.getUpdatableReferences();
    for (final IUpdatableReference target : _updatableReferences) {
        {
            final EObjectDescriptionDeltaProvider.Delta delta = this.findContainingDelta(context.getEObjectDescriptionDeltas(), target.getTargetEObject());
            if ((delta != null)) {
                final QualifiedName original = IterableExtensions.<IEObjectDescription>head(delta.getSnapshot().getDescriptions()).getQualifiedName();
                final QualifiedName modified = IterableExtensions.<IEObjectDescription>head(delta.getDescriptions()).getQualifiedName();
                boolean _notEquals = (!Objects.equal(original, modified));
                if (_notEquals) {
                    final Import imp = imports.get(original);
                    if ((imp != null)) {
                        toChange.put(imp, modified);
                    }
                }
            }
        }
    }
    final Runnable _function_1 = () -> {
        for (final Import toDel : toDelete) {
            EcoreUtil.remove(toDel);
        }
        Set<Map.Entry<Import, QualifiedName>> _entrySet = toChange.entrySet();
        for (final Map.Entry<Import, QualifiedName> toCh : _entrySet) {
            {
                final Import imp = toCh.getKey();
                final QualifiedName name = toCh.getValue();
                imp.setImportedNamespace(this.converter.toString(name));
            }
        }
        for (final QualifiedName toA : toAdd) {
            EList<Import> _imports = node.getImports();
            Import _createImport = PartialSerializationTestLanguageFactory.eINSTANCE.createImport();
            final Procedure1<Import> _function_2 = (Import it) -> {
                it.setImportedNamespace(this.converter.toString(toA));
            };
            Import _doubleArrow = ObjectExtensions.<Import>operator_doubleArrow(_createImport, _function_2);
            _imports.add(_doubleArrow);
        }
    };
    context.modifyModel(_function_1);
}
Also used : Import(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Import) IUpdatableReference(org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference) HashSet(java.util.HashSet) Set(java.util.Set) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with Node

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

the class ChangeSerializerTest method testResourceURIChange.

@Test
public void testResourceURIChange() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#1 root { }");
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/f.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:/f.pstl", Node.class);
    final IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
    final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
        Resource _eResource = model.eResource();
        _eResource.setURI(URI.createURI("inmemory:/x.pstl"));
    };
    serializer.<Resource>addModification(model.eResource(), _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("----- renamed inmemory:/f.pstl to inmemory:/x.pstl (syntax: <offset|text>) -----");
    _builder_1.newLine();
    _builder_1.append("(no changes)");
    _builder_1.newLine();
    _builder_1.append("--------------------------------------------------------------------------------");
    _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 8 with Node

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

the class ChangeSerializerTest method testInsertTwoChild.

@Test
public void testInsertTwoChild() {
    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("bazz1");
        };
        Node _doubleArrow = ObjectExtensions.<Node>operator_doubleArrow(_createNode, _function_1);
        _children.add(_doubleArrow);
        EList<Node> _children_1 = model.getChildren().get(0).getChildren();
        Node _createNode_1 = this.fac.createNode();
        final Procedure1<Node> _function_2 = (Node it_1) -> {
            it_1.setName("bazz2");
        };
        Node _doubleArrow_1 = ObjectExtensions.<Node>operator_doubleArrow(_createNode_1, _function_2);
        _children_1.add(_doubleArrow_1);
    };
    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|bazz1; bazz2; >} }");
    _builder_1.newLine();
    _builder_1.append("--------------------------------------------------------------------------------");
    _builder_1.newLine();
    _builder_1.append("25 0 \"\" -> \"bazz1; bazz2; \"");
    _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 9 with Node

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

the class ChangeSerializerTest method testDeleteChild.

@Test
public void testDeleteChild() {
    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) -> {
        EcoreUtil.remove(model.getChildren().get(0).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 { child1 { <19:5|> } }");
    _builder_1.newLine();
    _builder_1.append("--------------------------------------------------------------------------------");
    _builder_1.newLine();
    _builder_1.append("19 5 \"foo1;\" -> \"\"");
    _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 10 with Node

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

the class ChangeSerializerTest method testRenameLocal.

@Test
public void testRenameLocal() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#1 root { foo1; foo2 { ref 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) -> {
        Node _get = model.getChildren().get(0);
        _get.setName("bazz4");
    };
    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>; foo2 { ref <27:4|bazz4> } }");
    _builder_1.newLine();
    _builder_1.append("--------------------------------------------------------------------------------");
    _builder_1.newLine();
    _builder_1.append("10 4 \"foo1\" -> \"bazz4\"");
    _builder_1.newLine();
    _builder_1.append("27 4 \"foo1\" -> \"bazz4\"");
    _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)

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