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

Bug 385634

Summary: Code Snippet ignored with derived and refers
Product: [Modeling] EMF Reporter: Regent LArcheveque <regent.larcheveque>
Component: XcoreAssignee: 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:
Description Flags
XCore Meta-Model none

Description Regent LArcheveque CLA 2012-07-20 14:06:06 EDT
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
Comment 1 Regent LArcheveque CLA 2012-07-20 14:08:16 EDT
Created attachment 219008 [details]
XCore Meta-Model
Comment 2 Regent LArcheveque CLA 2012-07-20 14:14:39 EDT
If you add keyword 'local' besides the keyword 'refers', then the code is properly generated.
Comment 3 Ed Merks CLA 2012-09-17 01:35:29 EDT
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.
Comment 4 Christoph Keimel CLA 2012-12-14 06:28:05 EST
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
	}
}
Comment 5 Ed Merks CLA 2012-12-14 11:16:25 EST
The fix for both these cases is committed to master:

http://git.eclipse.org/c/emf/org.eclipse.emf.git/commit/?id=9d4d3510c27d12ee13dc82d1939a9afcd137b09d
Comment 6 Ed Merks CLA 2013-07-10 11:26:59 EDT
The changes are available in Kepler.
Comment 7 Guillermo Zunino CLA 2015-01-27 12:44:09 EST
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.
Comment 8 Ed Merks CLA 2015-01-27 12:59:08 EST
When you specify dynamic reflective calls will never call hand written accessors so that doesn't really make sense.