Cant get the merge to work [message #1754929] |
Fri, 24 February 2017 03:01  |
Eclipse User |
|
|
|
Hello there,
i try to merge two of my models. my first model is a normal EMF-Model without references to other ecore-models.
http://imgur.com/WSmfuRo
then i create a new file and try to merge all the differences with the following code:
LocalDateTime localDateTime = LocalDateTime.now();
String uhrZeitDatum = "" + localDateTime.getYear() + localDateTime.getMonth() + localDateTime.getDayOfMonth()
+ localDateTime.getMinute() + localDateTime.getSecond();
URI referenceURI = URI.createPlatformResourceURI("Test/core.ecore", true);
URI targetURI = URI.createPlatformResourceURI("Test/" + uhrZeitDatum + ".ecore", true);
ResourceSet resourceSet = new ResourceSetImpl();
Resource referenceResource = resourceSet.getResource(referenceURI, true);
Resource targetResource = resourceSet.createResource(targetURI);
try {
targetResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
// Instantiate the scopes to compare
IEditableModelScope referenceScope = new FragmentedModelScope(referenceResource, false);
IEditableModelScope targetScope = new FragmentedModelScope(targetResource, false);
IComparison comparison = new EComparisonImpl(targetScope, referenceScope);
ConfigurableMatchPolicy configurableMatchPolicy = new ConfigurableMatchPolicy();
ConfigurableDiffPolicy configurableDiffPolicy = new ConfigurableDiffPolicy();
DefaultMergePolicy defaultMergePolicy = new DefaultMergePolicy();
comparison.compute(configurableMatchPolicy, configurableDiffPolicy, defaultMergePolicy, null);
List<IDifference> differences = comparison.getDifferences(Role.REFERENCE);
comparison.merge(differences, Role.TARGET, true, null);
the result is the following
http://imgur.com/KL2A4Ln
so the supertypes get duplicated. i tryed to change the merge to the following:
for (IDifference iDifference : differences) {
if (iDifference instanceof IElementPresence) {
IElementPresence elementPresenceDifference = (IElementPresence) iDifference;
elementPresenceDifference.mergeTo(Role.TARGET);
} else if (iDifference instanceof IReferenceValuePresence) {
IReferenceValuePresence referenceValuePresence = (IReferenceValuePresence) iDifference;
referenceValuePresence.mergeTo(Role.TARGET);
} else if (iDifference instanceof IAttributeValuePresence) {
IAttributeValuePresence attributeValuePresence = (IAttributeValuePresence) iDifference;
attributeValuePresence.mergeTo(Role.TARGET);
}
}
And the result looks even more strange:
http://imgur.com/74Qfdxf
what am i doing wrong?
[Updated on: Fri, 24 February 2017 03:05] by Moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03200 seconds