Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to make references to composite elements?(How to make references to composite elements? Do I need to extend DefaultDeclarativeQualifiedNameProvider?)
How to make references to composite elements? [message #726864] Mon, 19 September 2011 18:27 Go to next message
R.M. Morrien is currently offline R.M. MorrienFriend
Messages: 9
Registered: July 2009
Junior Member
How to make references to composite elements? Do I need to extend DefaultDeclarativeQualifiedNameProvider?

Example xtext model:
Model:
	elements+=Table*;

Table:
	'table' name=ID '{'
		columns+=Column*
		primaryKey=PrimaryKey
		foreignKey+=ForeignKey*
	'}';

Column:
	'column' name=ID;

ForeignKey:
	'foreignKey' name=ID '{'
		columns+=[Column]*
		references=[PrimaryKey]
	'}';

PrimaryKey:
	'primaryKey' name=ID '{'
		columns+=[Column]*
	'}';


I want to model:
table HideOut {
	column Name
	column Location
	primaryKey hideoutKey {
		Name
	}
}

table Gangster {
	column Name
	primaryKey gangsterKey {
		Name
	}
	foreignKey hideOuts {
		HideOut.hideoutKey
	}
}


But the reference in foreignKey hideOuts to HideOut.hideoutKey is not picked up.
The editor message is: Couldn't resolve reference to PrimaryKey 'HideOut'
I tried writing a DefaultDeclarativeQualifiedNameProvider, but it did not seem to help. I followed http christiandietrich.wordpress.com/2011/07/16/iqualifiednameproviders-in-xtext-2-0/

Could someone help me in the right direction? My goal is to have two seperate model files with references between them. Making reference works for root elements like 'Table' in my model, but I do not want to use root elements only.

Thank you, Martijn
Re: How to make references to composite elements? [message #726874 is a reply to message #726864] Mon, 19 September 2011 18:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this question comes up twice a week Wink
references=[PrimaryKey] is short for references=[PrimaryKey|ID]
and means ref to a PrimaryKey and parse an id.
but you want to parse a qualifiedname.
so this will work

ForeignKey:
	'foreignKey' name=ID '{'
		columns+=[Column]*
		references=[PrimaryKey|FQN]
	'}';
FQN: ID ("." ID)*;


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to make references to composite elements? [message #726879 is a reply to message #726874] Mon, 19 September 2011 18:57 Go to previous message
R.M. Morrien is currently offline R.M. MorrienFriend
Messages: 9
Registered: July 2009
Junior Member
Wow thank you it works! Super service!

I kept hitting issues like: http://www.eclipse.org/forums/index.php/m/724201 and already implemented the qualified name provider and the scope provider to no avail.

The 15 minute tutorial http://www.eclipse.org/Xtext/documentation/2_0_0/020-domainmodel-step-by-step.php also contains this solution but I didn't see the "entity Post extends my.company.common.HasAuthor" as a 'reference'.
Previous Topic:download.itemis.com is down
Next Topic:EGIT plugin in eclipse
Goto Forum:
  


Current Time: Tue Apr 23 16:50:15 GMT 2024

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

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

Back to the top