Search in sources :

Example 1 with Import

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Import 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)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 EList (org.eclipse.emf.common.util.EList)1 IUpdatableReference (org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference)1 Import (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Import)1 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1