Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Need suggestion on how to create unique ids for tokens (or rules)
Need suggestion on how to create unique ids for tokens (or rules) [message #650927] Thu, 27 January 2011 08:22 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 13
Registered: December 2010
Junior Member
I was wondering if there was a best practice or a generic way to cause unique ids to be associated with tokens.

Like in the fowler example:
Statemachine:
	{Statemachine}
	'events' (events+=Event)* 'end'
	'commands' (commands+=Command)* 'end'
	(states+=State)*;


Let us say that we use xpand to generate java code, we need events, commands, and states to have unique ids. That the ids are unique accross all three types, meaning that an event with unique id "1" cannot have a command with the id "1".
I want these unique ids generated in xpand and be able to be passed around in the defines/templates.

Is there an example of how to do this?

I know one can iterate events and then commands and add a large number to the iterator index in the case of events to make it unlikely to have the same id for commands.

But I want to be able to assign a unique id to an event when it is first detected and for it have that id in the java code that is created through out.

As in I don't want a unique id generated for them every time they are iterated. If this is not clear I will respond to questions to clarify.

[Updated on: Thu, 27 January 2011 08:26]

Report message to a moderator

Re: Need suggestion on how to create unique ids for tokens (or rules) [message #650929 is a reply to message #650927] Thu, 27 January 2011 08:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi

in the xpand / xtend stdlib you find extensions that give you an uid for an object.

http://help.eclipse.org/helios/topic/org.eclipse.xpand.doc/h elp/ch04s02.html?path=62_1_2_1_9#N1269E

~Christian



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Need suggestion on how to create unique ids for tokens (or rules) [message #650987 is a reply to message #650927] Thu, 27 January 2011 11:22 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Just a sidenote: In textual modeling you usually avoid such technical
IDs but use qualified names to refer to elements instead. As technical
IDs are not persisted they might change if the model changes, probably
causing static references using that ID to point to nothing or something
completely different. Finding a robust strategy to derive these IDs can
be difficult.

Am 27.01.11 09:22, schrieb ocean5h@gmail.com:
> I was wondering if there was a best practice or a generic way to cause
> unique ids to be associated with tokens.
>
> Like in the fowler example:
>
> Statemachine:
> {Statemachine}
> 'events' (events+=Event)* 'end'
> 'commands' (commands+=Command)* 'end'
> (states+=State)*;
>
>
> Let us say that we use xpand to generate java code, we need events,
> commands, and states to have unique ids. That the ids are unique accross
> all three types, meaning that an event with unique id "1" cannot have an
> event with the id "1".
> I want these unique ids generated in xpand and be able to be passed
> around in the defines/templates.
>
> Is there an example of how to do this?
>
> I know one can iterate events and then commands and add a large number
> to the iterator index in the case of events to make it unlikely to have
> the same id for commands.
>
> But I want to be able to assign a unique id to an event when it is first
> detected and for it have that id in the java coded that is created
> through out.
>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:[XTEXT] Set lines containing an error to a comment automatically
Next Topic:dependency cycle in plugins
Goto Forum:
  


Current Time: Fri Apr 26 22:09:00 GMT 2024

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

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

Back to the top