Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 212765

Summary: implementation of association generalization & properties redefinitions
Product: [Modeling] MDT.UML2 Reporter: Javi <jfbriones_tech>
Component: CoreAssignee: Kenn Hussey <Kenn.Hussey>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P2 CC: ed, Kenn.Hussey
Version: 2.1.0Keywords: plan
Target Milestone: M7Flags: Kenn.Hussey: kepler+
Hardware: PC   
OS: Windows XP   
Whiteboard: Community Support

Description Javi CLA 2007-12-12 10:21:11 EST
This bug is result of two newsgroup posts:
- subject: "uml2ecore, ecore attributes marked as volatile"
http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.uml2/msg01540.html
- subject: "Generalization of an Aggregation"
http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.modeling.mdt.uml2/msg01632.html

To implement association generalizations in EMF, the use of properties redefinitions is needed. The implementation of this redefinitions may have some defects that could be fixed.

The bug has to do with the following attributes of redefined/redefining properties:
 - names (redefined name equal/different to the redefining one)
 - multiplicities
 - derived


3 test cases (3 different models):

For the 3 test cases there is a base model with two generalizations
AParent             <|---         AChild
BParent             <|---         BChild

1. (add 4 properties and 2 associations to the base model)
AParent.refB[0..*]  redefinedBy   AChild.refB[0..1]
BParent.refA[0..1]  redefinedBy   BChild.refA[1]

2. (add 4 properties and 2 associations to the base model)
AParent.refB[0..*]  redefinedBy   AChild.refBChild[0..1]
BParent.refA[0..1]  redefinedBy   BChild.refAChild[1]

3. (add 4 properties and 2 associations to the base model)
AParent.refB[0..*]  redefinedBy   AChild.refBChild[0..1]
BParent.refA[0..1]  redefinedBy   BChild.refA[1]

Possible issues:

Test case 1. (I cannot see the answer from the generated code)
 - Do "AChild.getRefB():EList" and "BChild.getRefA():EList" limit the number of elements? These methods override the parents' ones using the parents' fields (ELists). Although the parent's fields are used, the returned lists NEED to internally limit the number of elements. (Note that in this test case there are no methods: "AChild.getRefBChild():BChild" neither "BChild.getRefAChild():AChild")

Test case 2.
 - Four get methods need to be created in the children: "AChild.getRefB():EList", "BChild.getRefA():EList", "AChild.getRefBChild():BChild", and "BChild.getRefAChild():AChild". The question for test case 1 is applicable to the methods returning EList which override the parents' ones (the returned lists NEED to internally limit the number of elements).

Test case 3.
 - Three get methods need to be created "AChild.getRefBChild():BChild", "AChild.getRefB():EList", and "BChild.getRefA():EList". If I remember correctly the three methods need to be implemented, some generated code could be done though. But the generated code should be aware of the potential issue of the previous test cases.
 - Yes, my question was whether a field in AChild called refBChild of type BChild could be created. This field must be an end of an association and should behave as such. This is a tentative implementation, there could be others, as using the field (of type EList) of the parent BUT limiting the size.


Notice I described here potential issues for the get methods but there could be similar issues for the *set* and *isSet* methods.

I noticed as well some issues happening when the property to be redefined or/and the property redefining were derived. This caused generated code of derived properties to have an associated field, what I do not consider correct.
 - redefined derived, redefining not derived
 - redefined not derived, redefining derived
 - redefined not derived, redefining not derived
I cannot precise right now which of the 3 cases was wrong.
Comment 1 Kenn Hussey CLA 2012-06-20 22:33:59 EDT
We would need to revisit how redefinition is supported for each of these use cases and determine what can be corrected and/or improved (doing so could be helpful in implementing changes for bug 297216). This could perhaps be done during the upcoming Keppler release cycle.
Comment 2 Kenn Hussey CLA 2013-03-07 10:40:53 EST
Preliminary changes to support preservation and retrieval of redefinition details (lower bound, upper bound, and type) have been committed/pushed to the 'master' branch in git. These changes will be leveraged by fixes in code generation to follow after M6.
Comment 3 Kenn Hussey CLA 2013-03-24 22:06:08 EDT
I have committed/pushed changes to the 'master' branch in git which provide better code generation support for redefined types and multiplicities. With these changes, more specific type constraints are enforced in redefining classes and narrower multiplicities are enforced via overrides in the generated validator. All of the concerns in test case 1 are now addressed (and the same/similar issues in test case 2 are as well).
Comment 4 Kenn Hussey CLA 2013-03-24 22:23:06 EDT
I have also looked into the various combinations of derived and not derived and found that fields were only generated when expected (for supported combinations). Note that some combinations, e.g., where a derived property is redefined by a non-derived property or where one end of an association is derived while the other is not (which are considered unsupported) result in an invalid Ecore model for some test cases; in such cases, no code could be generated (obviously).

Next, I'll be looking to round out test case 2 and see what, if anything, can be done about test case 3. Note that, since it's essentially a mix of test cases 1 and 2, it's questionable how easy it will be (or, indeed, whether it's even possible) to arrive at a code generation pattern which will properly capture the desired intent.
Comment 5 Kenn Hussey CLA 2013-03-28 21:27:05 EDT
I have committed/pushed changes to the 'master' branch in git which provide better codegen support for explicit redefinitions. With these changes, all of the concerns in test case 2 are now addressed.

I also looked carefully at *set* and *isSet* methods and found eIsSet wasn't being correctly overridden to delegate to *isSet* methods for redefined features; this is now fixed.

The better codegen support (for redefined types and multiplicities and for explicit redefinitions) for the issues in test cases 1 and 2 also help in test case 3. However, due the the "mixed" nature of test case 3, some methods (only two of them now) will still need to be implemented by hand. I'm afraid this is the best that can be done for now, especially since it's questionable whether such a case should even be supported.
Comment 6 Kenn Hussey CLA 2013-04-01 10:09:20 EDT
An integration build (for UML2 4.1) containing the changes is now available.
Comment 7 Ed Willink CLA 2013-06-29 15:18:17 EDT
Unfortunately these changes create nested EAnnotations that reveal a bug in EMF codegen. See Bug 411945.