|
Re: [xcore] Code Snippet ignored with derived and refers references [message #896845 is a reply to message #896746] |
Fri, 20 July 2012 06:36 |
Ed Merks Messages: 33216 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/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06892 seconds