Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Implicit Model Elements
Implicit Model Elements [message #1844565] Thu, 16 September 2021 15:30 Go to next message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 34
Registered: July 2009
Member
I would like to add some elements implicitely to the resulting parsed EMF model.

step Provision {
    input X
}


e.g. add an "input Name" to every step.

Is there a way to pre process the parsed EMF model before it is passed to the Xtext infrastructure e.g. for indexing, linking, ...?

Step:
  'step' name=ID '{'
    inputs+=Input*
  '}';

Input:
  'input' name=ID
;
Re: Implicit Model Elements [message #1844566 is a reply to message #1844565] Thu, 16 September 2021 15:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14104
Registered: July 2009
Senior Member
You might be looking for a feature called IDerivedStateComputer

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Implicit Model Elements [message #1844568 is a reply to message #1844566] Thu, 16 September 2021 16:02 Go to previous messageGo to next message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 34
Registered: July 2009
Member
ok, thanks for the pointer. I have implemented an IDerivedStateComputer and added the following bindings to the Guice module:

 	def Class<? extends IDerivedStateComputer> bindIDerivedStateComputer() {
 		ProcessDslDerivedStateComputer
 	}
 	
 	override bindXtextResource() {
 		DerivedStateAwareResource
 	}
 	
 	def Class<? extends IResourceDescription.Manager> bindIResourceDescriptionManager() {
 		DerivedStateAwareResourceDescriptionManager
 	}


The last two bindings seem to be necessary.

Question: is it save to store state in instance variables of the IDerivedStateComputer? It looks like there is a 1:1 relation between state computer and resource. Is this correct?
Re: Implicit Model Elements [message #1844570 is a reply to message #1844568] Thu, 16 September 2021 16:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14104
Registered: July 2009
Senior Member
You should not store state there

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Implicit Model Elements [message #1844603 is a reply to message #1844570] Fri, 17 September 2021 11:26 Go to previous messageGo to next message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 34
Registered: July 2009
Member
ok. I store the state in a custom Adapter on the resource. This seems to work so far.
Re: Implicit Model Elements [message #1844604 is a reply to message #1844603] Fri, 17 September 2021 12:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14104
Registered: July 2009
Senior Member
what kind of state are you talking about?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Implicit Model Elements [message #1844607 is a reply to message #1844604] Fri, 17 September 2021 14:03 Go to previous message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 34
Registered: July 2009
Member
in installDerivedState I add some state (Input elements, see in initial example) to the Step. If I understand correctly, I have to discard this state in discardDerivedState. However, there is no way for me to know, whether a given Input is "derived" or was added by the user. So, I need to store this information somewhere.

Option one was adding it as instance variables of the derived state computer, which seems to be a bad idea (no Javadoc warns me about that).

Option two was using an EMF adapter.

Option three would be to extend the EMF model with a property "derived" on the "Input" element. Option two seems be cleaner to me and is also the one used in JvmModelAssociator.
Previous Topic:Label Provider not being invoked
Next Topic:Shared utility object for entire project build
Goto Forum:
  


Current Time: Sun Dec 05 05:27:32 GMT 2021

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

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

Back to the top