Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Implicit Model Elements
Implicit Model Elements [message #1844565] Thu, 16 September 2021 11:30 Go to next message
Eclipse UserFriend
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 11:32 Go to previous messageGo to next message
Eclipse UserFriend
You might be looking for a feature called IDerivedStateComputer
Re: Implicit Model Elements [message #1844568 is a reply to message #1844566] Thu, 16 September 2021 12:02 Go to previous messageGo to next message
Eclipse UserFriend
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 12:48 Go to previous messageGo to next message
Eclipse UserFriend
You should not store state there
Re: Implicit Model Elements [message #1844603 is a reply to message #1844570] Fri, 17 September 2021 07:26 Go to previous messageGo to next message
Eclipse UserFriend
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 08:37 Go to previous messageGo to next message
Eclipse UserFriend
what kind of state are you talking about?
Re: Implicit Model Elements [message #1844607 is a reply to message #1844604] Fri, 17 September 2021 10:03 Go to previous message
Eclipse UserFriend
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 Apr 27 22:21:17 EDT 2025

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

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

Back to the top