Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » generate property from referenced object
generate property from referenced object [message #1293652] Sat, 12 April 2014 21:08 Go to next message
Chris Klein is currently offline Chris KleinFriend
Messages: 3
Registered: April 2014
Junior Member
Hi,

my first adventures in xtext were very positive. The plugin was working in an instant and its a pleasure to use ones own language using an inteligent editor.

But now i got stuck using referenced rules. Taking the 15 minutes example i would like to do something like:

Entity :
  'entity' name = ID 
;

Entity2 :
  'entity2' name = [Entity] 
;


The rule Entity2 doesnt work as expected. I think its because [Entity] returns the referenced object but not a string.

The Objects of entity2 should have the same name as the referenced Entity object. In other languages i'd use a statement like

Entity2 :
  'entity2' name = [Entity].name
;

But, of course, this doesnt work too.

I hope i have made my point clear. Does XText allow to do something like this in grammar only? Or do I have to change some java internals of the editor?

Thanks in advance for your help,

chris
Re: generate property from referenced object [message #1294839 is a reply to message #1293652] Sun, 13 April 2014 21:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi you have to adapt the iqualifiednameprovider (subxlassing
DefaultDeclarativeQualifiedNameProvider) and use NodeModelUtil
(findNodesForFeature) to extract the cross referenced name string


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: generate property from referenced object [message #1296048 is a reply to message #1294839] Mon, 14 April 2014 19:41 Go to previous messageGo to next message
Chris Klein is currently offline Chris KleinFriend
Messages: 3
Registered: April 2014
Junior Member
Hi christian,

thanks for the pointers. Using your keywords i found your blog post under

christiandietrich.wordpress.com/2011/07/16/iqualifiednameproviders-in-xtext-2-0/

that shows how to use the DefaultDeclarativeQualifiedNameProvider

I implemented qualifiedName as follows

     QualifiedName qualifiedName(Entity2 e) {
    	 List<INode> nl=NodeModelUtils.findNodesForFeature(e,
	e.eClass().getEStructuralFeature(skoL.dsl.impl.DslPackageImpl.ENTITY2__REF));
    	INode node=nl.get(0);
    	 String vName=node.getText();
    	 
    	 EObject temp = e;
		while (temp.eContainer() != null) {
			temp = temp.eContainer();
			QualifiedName parentsQualifiedName = getFullyQualifiedName(temp);
			if (parentsQualifiedName != null)
				return parentsQualifiedName.append(vName);
		}
        return QualifiedName.create(vName);
    }


this makes Entity2 visible in the global object list (under ctrl+shift+f3).

But I still have one problem: Entity2 Objects dont show up in auto-completion.(ctrl+space) I suspect this is due to entity2 objects having no attribute called "name". How can I make the objects appear in auto-complete?
Re: generate property from referenced object [message #1296064 is a reply to message #1296048] Mon, 14 April 2014 19:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Please share a complete reproducible example. I can't follow your
problem

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: generate property from referenced object [message #1296747 is a reply to message #1296064] Tue, 15 April 2014 07:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P:S: if they are in the global index the shall occury locally too (if your grammar is correct)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: generate property from referenced object [message #1307704 is a reply to message #1296747] Mon, 21 April 2014 18:42 Go to previous messageGo to next message
Chris Klein is currently offline Chris KleinFriend
Messages: 3
Registered: April 2014
Junior Member
i solved the problem:

following instructions on

malubu.wordpress.com/2012/05/07/post-processing-vs-post-initialization/

i added a "name" property to my Entity2 object and now it shows up in auto-completion
Re: generate property from referenced object [message #1307743 is a reply to message #1307704] Mon, 21 April 2014 19:10 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi++QualifiedName qualifiedName(Entity2 e) {
should already have done that


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Disabling auto-insertion of quotes
Next Topic:Rule written for DSL in xtext, It is not working as expected
Goto Forum:
  


Current Time: Fri Apr 19 02:25:05 GMT 2024

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

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

Back to the top