use of org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference in project xtext-core by eclipse.
the class PartialSerializationTestLanguageReferenceUpdater method update.
@Override
public void update(IReferenceUpdaterContext context) {
super.update(context);
Node node = IterableExtensions.head(Iterables.filter(context.getResource().getContents(), Node.class));
if (node == null) {
return;
}
Set<Import> toDelete = new HashSet<>();
Set<QualifiedName> toAdd = new HashSet<>();
Map<Import, QualifiedName> toChange = new HashMap<>();
Map<QualifiedName, Import> imports = IterableExtensions.toMap(node.getImports(), (Import it) -> converter.toQualifiedName(it.getImportedNamespace()));
for (IUpdatableReference target : context.getUpdatableReferences()) {
EObjectDescriptionDeltaProvider.Delta delta = this.findContainingDelta(context.getEObjectDescriptionDeltas(), target.getTargetEObject());
if (delta != null) {
QualifiedName original = IterableExtensions.head(delta.getSnapshot().getDescriptions()).getQualifiedName();
QualifiedName modified = IterableExtensions.head(delta.getDescriptions()).getQualifiedName();
if (!Objects.equal(original, modified)) {
Import imp = imports.get(original);
if (imp != null) {
toChange.put(imp, modified);
}
}
}
}
context.modifyModel(() -> {
for (Import toDel : toDelete) {
EcoreUtil.remove(toDel);
}
for (Map.Entry<Import, QualifiedName> toCh : toChange.entrySet()) {
Import imp = toCh.getKey();
QualifiedName name = toCh.getValue();
imp.setImportedNamespace(converter.toString(name));
}
for (QualifiedName toA : toAdd) {
Import newImport = PartialSerializationTestLanguageFactory.eINSTANCE.createImport();
newImport.setImportedNamespace(converter.toString(toA));
node.getImports().add(newImport);
}
});
}
Aggregations