Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-referencing to plural names?
Cross-referencing to plural names? [message #755998] Thu, 10 November 2011 12:46 Go to next message
Scott Finnie is currently offline Scott FinnieFriend
Messages: 94
Registered: October 2011
Member
I would like to add first class relationships to the example model. For example, given:

entity Blog {
    title: String
    body: String
}

entity Author {
    name: String
}


I want to be able to express the following relationship:

association R1 {
    Each Blog "is written by" exactly one Author
    Each Author "may write" zero or more Blogs
}


I have a working grammar for everything - apart from dealing with the plural ('Blogs' in the example above):

Relationship:
	'Relationship' name=ID '{'
	(roles+=RelRole)*
	'}';

RelRole:
	'Each' class1=[Entity] relPhrase=STRING multiplicity=Multiplicity class2=[Entity] ;

Multiplicity:
	"at most one" | "exactly one" | "zero or more" | "one or more"
;


Right now it works with the entity name. Which is OK but doesn't read right:

Each Author "may write" zero or more Blog


I was thinking of adding a new property to Entity:

'entity' name=ID ('plural' plural=ID)? // ..etc.


However that breaks the auto-cross referencing in the IDE. So: is there an easy way to declare a cross reference to entity.plural instead of entity.name? (Actually it would need to be either to cater for cardinality 1).

Thanks.





Re: Cross-referencing to plural names? [message #756021 is a reply to message #755998] Thu, 10 November 2011 13:57 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I can only give you the general idea. You adapt the scoping in order to make visible the entity objects using the plural name as well. You can do this via the AliasedEObjectDescription. If you don't want to calculate the alias (just append s), but declare the plural form in the entity, you will have to adapt the creation of the EObjectDescription by adding a user data entry that stores that name. That way you can query the original EObjectDescription for the alias to use.

The Xtend2/Xbase source code should do something similar in order to bind the implicit variable "this".

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Cross-referencing to plural names? [message #756087 is a reply to message #756021] Thu, 10 November 2011 20:00 Go to previous messageGo to next message
Scott Finnie is currently offline Scott FinnieFriend
Messages: 94
Registered: October 2011
Member
Thanks Alex, I'll take a look at Xbase.

- S.
Re: Cross-referencing to plural names? [message #756089 is a reply to message #756087] Thu, 10 November 2011 20:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you could customize org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy.createEObjectDescriptions(EObject, IAcceptor<IEObjectDescription>)

to put the object under more than one name into the "index"

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-referencing to plural names? [message #756373 is a reply to message #756089] Sat, 12 November 2011 13:42 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

one excuse for indicating a more complicated solution than Christian is that making the plural name "globally" visible in the index will allow referencing an entity via that name everywhere and not only in the class2-relation of a RelRole.

Alex
Previous Topic:Generating "void" methods using JvmTypesBuilder.toMethod.
Next Topic:Extend javascript grammer
Goto Forum:
  


Current Time: Thu Apr 18 20:33:56 GMT 2024

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

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

Back to the top