Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross Reference and Value in the same time
Cross Reference and Value in the same time [message #1719940] Wed, 13 January 2016 11:22 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 25
Registered: February 2010
Junior Member
Hi guys,

I am trying something tricky, may be for experience people not so tricky but it is for me Smile

I have the following definition

Transition:
	'transition' name=ID
	'=>' target = [State]
	'{'
		('trigger' '{' trigger = Event '}')
	'}';

Event:
	'event' name=ID;


and the following snippet from the model.

state CUSTOMERSEARCH_RUNNING {
                transition CustomerFound => CUSTOMER_FOUND {
                    trigger {
                        event onCustomerFound
                    }
                }
            }
state CUSTOMER_FOUND {
                transition CustomerFound => CUSTOMER_AUTHENTICATED {
                    trigger {
                        event onCustomerAuthenticated
                    }
                }
            }
state CUSTOMER_AUTHENTICATED {
                transition CustomerJoined => CUSTOMER_JOINED {
                    trigger {
                        event onCustomerJoined
                    }
                }
                transition OrdersLoading => ORDERS_LOADING {
                    trigger {
                        event onCustomerJoined
                    }
                }
            }


If you look to the CustomerAuthenticated State, you will see that it has 2 transition objects and they are both react to the same trigger event 'onCustomerJoined' (later in the full implementation they will distinguish them selfs with guard conditions) so when I model this way, later XTend complains that 'onCustomerJoined' Event is already created, which is completely valid while I use same ID twice.

Now what I want to achieve is that if an Event object is first time defined in the model, first time should create the object, 2nd time should reference the object.

Of course, I can create the Event objects some other place and reference them explicitly later on but I don't find this intuitive, I rather prefer that and user defines its events and system should be clever enough to figure out it is a reference or a new creation.

To reach this goal I change the grammar little bit,

Transition:
	'transition' name=ID
	'=>' target = [State]
	'{'
		('trigger' '{' trigger = EventBase '}')
	'}';

EventReference:
	typeRef=[Event]
;

EventCreation:
	event=Event;

Event:
	'event' name=ID;


and the notation at the model also (actually I don't want to but I don't see any other way, if someone can point me a way to do this without changing the notation I will be grateful).

state CUSTOMER_AUTHENTICATED {
                transition CustomerJoined => CUSTOMER_JOINED {
                    trigger {
                        event onCustomerJoined
                    }
                }
                transition OrdersLoading => ORDERS_LOADING {
                    trigger {
                       onCustomerJoined
                    }
                }
            }


but now it complains about 'Couldn't resolve reference to Event 'onCustomerJoined'.' , I am guessing the notation 'event onCustomerJoined' created the event but it can still not find the 'onCustomerJoined' to reference.

Can anybody give me tips about whats going or better how would you solve this problem?
Re: Cross Reference and Value in the same time [message #1720048 is a reply to message #1719940] Thu, 14 January 2016 07:15 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

If you want to treat the first appearance as the declaration and the following as references to that, you need to

1) use a cross reference in the grammar
2) turn off cross reference validation for the given EReference (special implementation of LinkingDiagnosticMessageProvider)
3) Implement a QualifiedName provider and use the node model to get the text from the model.

Note that language-design wise this is not a good idea, as every little typo will create a new declaration instead of a linking error.
To improve this a bit, it may be a good idea, to have very different syntax coloring fro declarations and links.
Avoiding this kind of design is the best solution Smile

Cheers,
Sven
Re: Cross Reference and Value in the same time [message #1720063 is a reply to message #1720048] Thu, 14 January 2016 08:22 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 25
Registered: February 2010
Junior Member
Thx for the answer, I am not quite experienced with XText and trying to get the ropes.

I agree what I am trying to do is not that elegant but I saw this problem and got curious, there is no better way to learn then the problems Smile

What I was trying to achieve is something like below.

String a = new String();

or
b= "3242342423";
a=b;

I was just surprised with 'couldn't not resolve reference'

[Updated on: Fri, 15 January 2016 09:26]

Report message to a moderator

Re: Cross Reference and Value in the same time [message #1720190 is a reply to message #1720063] Fri, 15 January 2016 06:31 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

I am not sure if there is a question implied in your post.
But I understood that you want to make no syntactic difference between the declaration of a local variable and an assignment of a value.
Previous Topic:Regarding Configuring Content assist in XText UI
Next Topic:Multiline comments with new api
Goto Forum:
  


Current Time: Thu Apr 25 22:49:46 GMT 2024

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

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

Back to the top