| Summary: | Code Snippet ignored with derived and refers | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Modeling] EMF | Reporter: | Regent LArcheveque <regent.larcheveque> | ||||
| Component: | Xcore | Assignee: | Ed Merks <Ed.Merks> | ||||
| Status: | CLOSED FIXED | QA Contact: | Ed Merks <Ed.Merks> | ||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | c.keimel, guillez, jreich | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Linux | ||||||
| Whiteboard: | |||||||
| Bug Depends on: | |||||||
| Bug Blocks: | 397324 | ||||||
| Attachments: |
|
||||||
Created attachment 219008 [details]
XCore Meta-Model
If you add keyword 'local' besides the keyword 'refers', then the code is properly generated. A similar problem happens for setting Feature Delegation to Reflective... We can certainly emit the specified logic in the basicGetTest, but its important that such logic does not resolve proxies, but it's written so that it calls getClassB(), which in general would resolve proxies, though in this case it doesn't because that feature isn't declared with the "resolving" keyword; container and containment references are non-resolving by default (unless declared "resolving" whereas cross references are resolving by default (unless declared "local") So it is more correct to specify the "test" feature as "local" given it's derived from another non-proxy resolving reference. And, as you mentioned, that produces the correct result too. It will be good in the future to have a notation for calling the accessor without resolving a proxy, i.e., the equivalent of eGet(XyzPackage.Literals.ABC__DEF, false), i.e., perhaps a notation like "this-><feature-name>". In any case, fixing this properly in the maintenance stream is too disruptive, so I'll defer it to 2.9. Related to this is the following example where the body is also not propagated into the generated code:
@GenModel(featureDelegation="Reflective")
class MyClass {
String name
String firstName
derived String fullName get {
name + ", " + firstName
}
}
The fix for both these cases is committed to master: http://git.eclipse.org/c/emf/org.eclipse.emf.git/commit/?id=9d4d3510c27d12ee13dc82d1939a9afcd137b09d The changes are available in Kepler. Shouldn't this work also for feature delegation = Dynamic ? On Luna, getter bodies are not generated when setting feature delegation to Dynamic, which seems to be a valid use case, specially for derived features. When you specify dynamic reflective calls will never call hand written accessors so that doesn't really make sense. |
Build Identifier: Version: 4.2.0 Build id: I20120608-1400 The xcore get snippet is not propagated into the generated classes when using refers. To reproduce, use the following xcore model. xcore_codegen_bug.xcore ----------------------- package test import org.eclipse.emf.ecore.ENamedElement class ClassA extends ENamedElement{ contains ClassB classB opposite classA } class ClassB extends ENamedElement{ container ClassA classA opposite classB refers readonly volatile transient derived ClassA test get{ return classA } } ----------------------- The code generated does not take into account the body defined in the xcore model. /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public ClassA getTest() { ClassA test = basicGetTest(); return test != null && test.eIsProxy() ? (ClassA)eResolveProxy((InternalEObject)test) : test; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public ClassA basicGetTest() { // TODO: implement this method to return the 'Test' reference // -> do not perform proxy resolution // Ensure that you remove @generated or mark it @generated NOT throw new UnsupportedOperationException(); } Note that if you change 'refers' to 'contains', the codegen propagates the body properly. Thanks ;-) Reproducible: Always Steps to Reproduce: 1.Create a XCore Project and copy the meta-model provided in attachment 2.Open test.impl.ClassBImpl.java 3.Check functions ClassA getTest() and ClassA basicGetTest() 4.The snippet provided in the xcore meta-model body is not propagated