Home » Modeling » TMF (Xtext) » [Xtext] Bidirectional properties handled incorrectly?
|
Re: [Xtext] Bidirectional properties handled incorrectly? [message #61106 is a reply to message #61030] |
Mon, 20 July 2009 11:57 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Jos,
this is a know bug.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=282486
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 20.07.2009 12:35 Uhr, schrieb Jos Warmer:
> We use an existing ecore metamodel with Xtext. In the metamodel we make
> use of bidirectional references. When either doing validation checks
> using Checks, or generating using Xpand the opposite side of references
> remains null.
>
> Sofar I have two different cases:
> 1. If an opposite points to its owner, things are ok.
> 2. If an opposite does not point to its owner, it is never set. Only the
> side that is mentioned in the Xtext grammar rule, is set, but the
> opposite remains empty.
>
> I have encountered this while migrating Mod4j, and can reproduce this in
> a small example. I can send the corresponding files, but don't know how
> to add them in this newsgroup.
>
> Is this a known problem that anyone has seen before? I can't find
> anything on this newsgroup.
>
> Regards, Jos Warmer
>
>
>
|
|
| | | |
Re: [Xtext] Bidirectional properties handled incorrectly? [message #61375 is a reply to message #61254] |
Mon, 20 July 2009 15:07 |
Jos Warmer Messages: 66 Registered: July 2009 |
Member |
|
|
Hi Knut,
Thanks for the advice. I see the overriding of the createProxy()
operation, and found the xtext LazyLinking class that I should override.
@Override
protected EObject createProxy(EObject obj, AbstractNode abstractNode,
EReference eRef) {
EReference eOpposite = ((Internal) eRef).getEOpposite();
if (eOpposite != null) {
List<EObject> linkedObjects =
MyLinkingService.INSTANCE
.getLinkedObjects(obj, eRef,
abstractNode);
if (linkedObjects.size() == 1)
return linkedObjects.get(0);
}
return super.createProxy(obj, abstractNode, eRef);
}
What I cannot see is which "MyLinkingService.INSTANCE" the code is
referring to. Should I also change the default XTextLinkingService ?
I think I like the first resolution (set the resolveProxies ...) better,
but I dopn't know where I can get into the Xtext processing to change
these properties. Do you have a pointer for me?
Jos
Knut Wannheden wrote:
> Hi Jos,
> Also note the documented workarounds: Either set the resolveProxies
> property to "false" on the EReferences set by the Xtext parser or
> override the LazyLinker implementation for these references as outlined
> in the bug description.
> Regards,
> --knut
> Jos Warmer wrote:
|
|
|
Re: [Xtext] Bidirectional properties handled incorrectly? [message #61423 is a reply to message #61375] |
Mon, 20 July 2009 15:24 |
Knut Wannheden Messages: 298 Registered: July 2009 |
Senior Member |
|
|
Hi Jos,
Jos Warmer wrote:
> Hi Knut,
>
> Thanks for the advice. I see the overriding of the createProxy()
> operation, and found the xtext LazyLinking class that I should override.
>
> @Override
> protected EObject createProxy(EObject obj, AbstractNode abstractNode,
> EReference eRef) {
> EReference eOpposite = ((Internal) eRef).getEOpposite();
> if (eOpposite != null) {
> List<EObject> linkedObjects =
> MyLinkingService.INSTANCE
> .getLinkedObjects(obj, eRef,
> abstractNode);
> if (linkedObjects.size() == 1)
> return linkedObjects.get(0);
> }
> return super.createProxy(obj, abstractNode, eRef);
> }
>
> What I cannot see is which "MyLinkingService.INSTANCE" the code is
> referring to. Should I also change the default XTextLinkingService ?
>
The method createProxy can actually be overridden in a simpler way. I
think this should work (not tested):
@Override
protected EObject createProxy(EObject obj, AbstractNode
abstractNode, EReference eRef) {
final EObject proxy = super.createProxy(obj, abstractNode, eRef);
if (eRef.getEOpposite() != null) {
return EcoreUtil.resolve(proxy, obj);
}
return proxy;
}
> I think I like the first resolution (set the resolveProxies ...) better,
> but I dopn't know where I can get into the Xtext processing to change
> these properties. Do you have a pointer for me?
>
As you have references with opposites I assumed your Ecore model already
existed and wasn't inferred by Xtext. If that's the case you can set the
resolveProxies attribute in the Ecore file.
Keep in mind that both these approaches are workarounds only.
--knut
|
|
| | |
Goto Forum:
Current Time: Wed Oct 02 02:20:15 GMT 2024
Powered by FUDForum. Page generated in 0.05714 seconds
|