Skip to main content


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.Friend
Messages: 60
Registered: May 2010
Location: Christchurch (NZ)
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 DietrichFriend
Messages: 14661
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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.Friend
Messages: 60
Registered: May 2010
Location: Christchurch (NZ)
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 DietrichFriend
Messages: 14661
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)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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.Friend
Messages: 60
Registered: May 2010
Location: Christchurch (NZ)
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: Tue Mar 19 06:11:25 GMT 2024

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

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

Back to the top