Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [xcore] Code Snippet ignored with derived and refers references(The xcore get snippet is not propagated into the generated classes when using refers.)
[xcore] Code Snippet ignored with derived and refers references [message #896746] Thu, 19 July 2012 14:57 Go to next message
Regent LArcheveque is currently offline Regent LArchevequeFriend
Messages: 94
Registered: May 2010
Member
Hi Ed,

I really like the new way to create meta-model. So far, it is going well. Just a little question. I have the following model

class EVariable extends ENamedElement{
container EVariables eVariables opposite eVariables
refers EClass eClass

@GenModel(children="false", property="Readonly")
refers readonly volatile transient derived EProgram eProgram get{
if (EVariables == null) return null else return EVariables.EProgram
}
}

The code generated is the following:
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EProgram getEProgram()
{
EProgram eProgram = basicGetEProgram();
return eProgram != null && eProgram.eIsProxy() ? (EProgram)eResolveProxy((InternalEObject)eProgram) : eProgram;
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EProgram basicGetEProgram()
{
// TODO: implement this method to return the 'EProgram' reference
// -> do not perform proxy resolution
// Ensure that you remove @generated or mark it @generated NOT
throw new UnsupportedOperationException();
}

Is it normal? I tested with contains instead of refers and the snippet is generated properly. In my case, it is really a weak container.

Thanks
Re: [xcore] Code Snippet ignored with derived and refers references [message #896845 is a reply to message #896746] Fri, 20 July 2012 06:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Comments below.

On 19/07/2012 4:57 PM, Régent L Archevêque wrote:
> Hi Ed,
>
> I really like the new way to create meta-model.
It's a look more awesome. :-P
> So far, it is going well. Just a little question. I have the
> following model
>
> class EVariable extends ENamedElement{
> container EVariables eVariables opposite eVariables
Usually I don't like pluralized names for classes. It makes it hard to
write well formed English sentences with the. E.g., "I used the
generated factory to create an EVariables."
> refers EClass eClass
> @GenModel(children="false", property="Readonly")
> refers readonly volatile transient derived EProgram eProgram get{
It seemed so common for a derived feature to be readonly, transient, and
volatile that this is implied by "derived". We'll need to look at
keyword to specify otherwise.
> if (EVariables == null) return null else return EVariables.EProgram
You should be able to use EVariables?.EProgram. (I'm not so happy with
Xbase's initial upper case letter here.)
> }
> }
>
> The code generated is the following:
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public EProgram getEProgram()
> {
> EProgram eProgram = basicGetEProgram();
> return eProgram != null && eProgram.eIsProxy() ?
> (EProgram)eResolveProxy((InternalEObject)eProgram) : eProgram;
> }
I would have expected the body you specified. Please open a bugzilla.
I'll address this in the maintenance stream. We've just set up builds
for that so builds will be available soon.
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public EProgram basicGetEProgram()
> {
> // TODO: implement this method to return the 'EProgram' reference
> // -> do not perform proxy resolution
> // Ensure that you remove @generated or mark it @generated NOT
> throw new UnsupportedOperationException();
> }
If you added the keyword "local" before or right after the "refers" to
specify that this feature isn't proxy resolving, you shouldn't get this
method. I tested and it actually solves the problem above as well. I
suppose to be fully general we'd have to allow you to specify the logic
for this as well.
>
> Is it normal?
No.
> I tested with contains instead of refers and the snippet is generated
> properly. In my case, it is really a weak container.
I expect container is handled a bit differently (wrongly in this case)
because it essence it's always a derived feature, i.e., derived for
EObject.eContainer(). And in fact, I think the logic you're specifying
for this produces an inconsistency because I assume you have something
like this:

package org.example.foo

import org.eclipse.emf.ecore.ENamedElement
import org.eclipse.emf.ecore.EClass

class EVariable extends ENamedElement{
container EVariables eVariables opposite eVariables
refers EClass eClass
@GenModel(children="false", property="Readonly")
local refers readonly volatile transient derived EProgram eProgram get{
EVariables?.EProgram
}
}

class EProgram
{
contains EVariables eVariables opposite eProgram

}
class EVariables
{
container EProgram eProgram opposite eVariables
contains EVariable eVariables opposite eVariables
}

I.e., the container for the variable is really an (sic) EVariables, not
an EProgram. So I really don't think you should be specifying a
derived container as you have. You should define a derived reference...

And you shouldn't be extending Ecore!!!
>
> Thanks


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [xcore] Code Snippet ignored with derived and refers references [message #896987 is a reply to message #896845] Fri, 20 July 2012 16:45 Go to previous messageGo to next message
Regent LArcheveque is currently offline Regent LArchevequeFriend
Messages: 94
Registered: May 2010
Member
Thanks for your explanations. I'll raise a bug report about the code snippet not generated.
Re: [xcore] Code Snippet ignored with derived and refers references [message #897025 is a reply to message #896987] Fri, 20 July 2012 19:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Régent,<br>
<br>
Please consider carefully my comment about the fact that you're
defining a container reference that is <b>not  </b>properly a
container reference.  It's not properly the opposite of the
containment reference.  I.e., the object will not be among the
container's eContents() and that container's  eContainmentFeature()
will not return the expected container reference.  What you're
defining is simply a derived reference.<br>
<br>
<div class="moz-cite-prefix">On 20/07/2012 6:45 PM, Régent L
Archevêque wrote:<br>
</div>
<blockquote cite="mid:juc1vu$351$1@xxxxxxxxe.org" type="cite">Thanks
for your explanations.  I'll raise a bug report about the code
snippet not generated.
<br>
</blockquote>
<br>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [xcore] Code Snippet ignored with derived and refers references [message #897238 is a reply to message #897025] Mon, 23 July 2012 11:09 Go to previous message
Regent LArcheveque is currently offline Regent LArchevequeFriend
Messages: 94
Registered: May 2010
Member
Copy Wink
Previous Topic:Use EObjectValidator in UpdateValueStrategy
Next Topic:Problem accessing resources in other depending projects
Goto Forum:
  


Current Time: Tue Apr 16 21:51:41 GMT 2024

Powered by FUDForum. Page generated in 0.06424 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top