| Home » Modeling » TMF (Xtext) » [Xtext] Bidirectional properties handled incorrectly?
 Goto Forum:| 
| [Xtext] Bidirectional properties handled incorrectly? [message #61030] | Mon, 20 July 2009 06:35  |  | 
| Eclipse User  |  |  |  |  | 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 #61106 is a reply to message #61030] | Mon, 20 July 2009 07:57   |  | 
| Eclipse User  |  |  |  |  | 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 11:07   |  | 
| Eclipse User  |  |  |  |  | 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 11:24   |  | 
| Eclipse User  |  |  |  |  | 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
 |  |  |  |  |  |  | 
| Re: [Xtext] Bidirectional properties handled incorrectly? [message #61602 is a reply to message #61553] | Mon, 20 July 2009 14:57  |  | 
| Eclipse User  |  |  |  |  | Hi Jos, 
 Jos Warmer wrote:
 > Your new createProxy() method works fine for both the example and for the
 > larger languages.
 >
 > The resolve proxies in the ecore file are all "true" already.  It seems
 > that this does not solve the problem.
 >
 
 You actually would have to set it to "false" for those references. Of
 course you would have to check that doesn't cause problems for other
 usages and consumers of the meta model. But it probably wouldn't.
 
 Cheers,
 
 --knut
 |  |  |  | 
 
 
 Current Time: Fri Oct 31 00:30:27 EDT 2025 
 Powered by FUDForum . Page generated in 0.04352 seconds |