Thanks, Daniel.
I have thought about this a little more and have realised that
perhaps there's a more general issue here. There may well be other
metamodels with such "non-standard" implementations, which
consequently would require specialised copiers, too. As a result,
it might even make sense to allow the copier to be externally
configured somehow perhaps through some sort of factory method in
EGraphImpl with a default implementation producing the result that
is currently hard-coded in EGraphImpl.copy. So
public class EGraphImpl extends LinkedHashSet<EObject> implements EGraph {
...
public EGraph copy(Map<EObject, EObject> copies) {
if (copies==null) {
Copier copier = createGraphCopier();
copier.copyAll(getRoots());
copier.copyReferences();
copies = copier;
}
...
}
/**
* Create an instance of {@link EcoreUtil.Copier} that can be used to copy the elements in this graph.
* By default produces a copier that can handle standard metamodels and Ecore instances. If your models
* need special treatment when copying, override this method. In particular, make sure that all model
* elements that can be found in the source model have an image in the copier map after copying.
*/
protected Copier createGraphCopier() {
if (packages.contains(EcorePackage.eINSTANCE)) {
return new EcoreCopier();
} else {
return new Copier();
}
}
...
Best regards,
Steffen
On 25/09/2017 09:45, Daniel Strüber
wrote:
Hi Steffen,
thanks! What you describe makes sense. Therefore, I have modified
EGraphImpl.copy() to use your copier in case that the EGraph
contains instances from Ecore: [1] https://git.eclipse.org/r/#/c/105679/
Best regards,
Daniel
Am 21.09.2017 um 12:39 schrieb
Steffen Zschaler:
Hi,
I've been trying to run some transformations over meta-models
(i.e., instances of Ecore). As part of this, I needed to copy
EGraphs and used EGraph.copy. This crashed with an NPE.
I did some digging and found out that the reason is that there
is an issue with how EcoreUtil.Copier works and how types and
generic types are handled in Ecore. Details here:
https://stackoverflow.com/questions/46323548/copying-egenerictype-instances-with-ecoreutil-copier
As a result, when calling EGraph.copy (null), in some cases the
code can then not find copies of the EGenericType instances in
the resulting map and adding them to the new graph crashes.
I have written a slightly extended version of EcoreUtil.Copier
which I attach. I have so far used this like in the code below,
but was wondering whether there's an interest to include this
directly into Henshin instead.
// Given a graph graph1 with some Ecore instances in it
EcoreCopier copier = new EcoreCopier();
copier.copyAll(graph1.getRoots());
copier.copyReferences();
EGraph graph2 = graph1.copy(copier);
Best regards,
Steffen
_______________________________________________
henshin-user mailing list
henshin-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/henshin-user
_______________________________________________
henshin-user mailing list
henshin-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://emea01.safelinks.protection.outlook.com/?url="">
--
Dr. rer. nat. Steffen Zschaler AHEA
Senior Lecturer
King's College London
Department of Informatics
Email szschaler@xxxxxxx
Phone +44 (020) 7848 1513
WWW http://www.steffen-zschaler.de/
|