Added support for containment features with upper bound equal to 1 #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed a bug when a containment feature is defined with a upper bound set to 1. In this case, it is possible to set the feature by using the
set
function of EObject, but the model cannot be serialized. The problem is located here (https://github.com/ghillairet/ecore.js/blob/master/src/xmi.js#L214):Indeed,
eContainer
of theroot
object (in this case, the EObject set in the containment feature) isundefined
(theset
function ofEObject
does not check whether the reference feature is a containment feature or not).You can test with the following model defined using Eclipse:
This (meta)model defines two concepts A and B, with a containment feature A::b (lowerBound = 0, upperBound = 1). If you try to create a model conformed to this metamodel and then serialize it, it will fail.
Commit ac68cd2 fixes this bug.
Commit 6c62f2e adds a test for this bug.
Besides, commit 45fef67 ensures that for a containment feature whose upper bound is equal to 1, if an object is set and then a second object is set, the first one is unset, and its
eContainer
andeContainingFeature
properties are cleared. Commit 1c89e74 adds a test for it.By the way, https://github.com/ghillairet/ecore.js/blob/master/src/ecore.js#L191 checks if the reference feature is a containment feature, by checking its value (
true
orfalse
) and type (boolean
). In case of the above metamodel defined with Eclipse, the containment property is a string soisContainment
is always false (the variable seems to be never used though).