Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Get referenced object in another model (cyclic resolution or no corresponding inode)
Get referenced object in another model (cyclic resolution or no corresponding inode) [message #1031541] Mon, 01 April 2013 22:52 Go to next message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
Hi,

I'm trying to override the name provider in such a way that I can define in a model a new object and its parent object, and having its qualified name computed with the referenced object directly in the model.

I provide here a simplified example. Assume in the first grammar, I have rules like:

MyObject:
  'myobject' name=FQN;

FQN:
  ID('.'ID)*;


in the other grammar:

MyOtherObject:
  'add' name=FQN 'in' referencedObject=[MyObject|FQN];

SomeRefRule:
  'refrule' reference=[MyOtherObject|FQN];


How can I override the name provider to build the fully qualified name of MyOtherObject based on MyObject. Ex. in model1.dsl:

myobject MyObjectName


in model2.dsl:

add ASubObject in MyObjectName

refrule MyObjectName.ASubObject


I roughly tried to retrieve the referenced object by just:

((MyOtherObject) o.eContainer).getReferencedObject()


which leads to a cyclic resolution of lazy links.
I also tried by NodeModelUtils.findNodesForFeature using the eContainer and DslPackage.Literals.My_Other_Object__REFERENCED_OBJECT but, this returns me MyOtherObject rule and not the MyObject.

Could someone help me with this?
Thanks in advance,

Fabian
Re: Get referenced object in another model (cyclic resolution or no corresponding inode) [message #1031738 is a reply to message #1031541] Tue, 02 April 2013 06:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6298
Registered: July 2009
Senior Member
Hi,

you are on the right track (indexing is done before linking so you have to use the node model) but: you should ask NodeModelUtils.findNodesForFeature for its text.
of course you get only a name (String) but this should be enhough to build a FQN
Re: Get referenced object in another model (cyclic resolution or no corresponding inode) [message #1031779 is a reply to message #1031738] Tue, 02 April 2013 07:19 Go to previous messageGo to next message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
Hi Christian,

I don't really get what you mean by "its text". To be more clear, here is what I tried (in a simplified way):

public QualifiedName qualifiedName(MyOtherObject moo) {
   INode n = NodeModelUtils.findNodesForFeature(moo.eContainer(), DslPackage.Literals.MY_OTHER_OBJECT__REFERENCED_OBJECT).get(0);
}


but this gives me the MyOtherObject EObject and I can't find a way to retrieve the node referenced by the ReferencedObject reference.
do I miss something?

thanks again,
Fabian
Re: Get referenced object in another model (cyclic resolution or no corresponding inode) [message #1031793 is a reply to message #1031779] Tue, 02 April 2013 07:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6298
Registered: July 2009
Senior Member
Hi,

as i said: you can only get what is in the file you are and thus the text you have in place at the node model.
=> you will get a node of MyOtherObject (the part of there reference)
Re: Get referenced object in another model (cyclic resolution or no corresponding inode) [message #1031882 is a reply to message #1031793] Tue, 02 April 2013 10:23 Go to previous message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
I couldn't figure out how to retrieve the text value. Did not see it was a simple call to getText() on the right INode.
thanks again!
Previous Topic:Model serialization problem
Next Topic:How to read specific file from configuration?
Goto Forum:
  


Current Time: Wed Sep 17 11:52:17 GMT 2014

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

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