Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Appending notifiyObservers call to a XBlockExpression using jvmInferrer(We are creating model objects using a jvmInferrer and they extend Observable. In case a model's method cause side effects, we'd like to notify it's observers adding method call to method's body)
Appending notifiyObservers call to a XBlockExpression using jvmInferrer [message #1137595] Mon, 14 October 2013 15:56 Go to next message
Miguel Carboni is currently offline Miguel CarboniFriend
Messages: 8
Registered: September 2013
Junior Member
Hi all!

We are creating model objects using a jvmInferrer and they extend Observable. In case a model's method cause side effects, we'd like to notify it's observers adding method call to method's body.

Grammar look's something like this:

...
Entity:
       features+=Feature*

Feature:
 Property | Message;

Property:
  name=ValidID ':' type=JvmTypeReference ('=' value=XExpression)?;

Message:
  'op' name=ValidID 
    '('(params+=FullJvmFormalParameter 
      (',' params+=FullJvmFormalParameter)*)?')'
    ':' type=JvmTypeReference 
    body=XBlockExpression;
...

Then, we have an jvm inferrer very similar to the one in the example but with a little tunning:

...
	jvmGenericType.superTypes.add(element.newTypeRef(typeof(Observable)))
...

		for (feature : element.features) {
			switch feature {
				Message: {
...
					if (feature.body.hasSideEffects) {
						// add setHasChanged() and notifyObservers() calls to feature body
					}
					members += feature.toMethod(feature.name, feature.type) [
						documentation = feature.documentation
						for (p : feature.params) {
							parameters += p.toParameter(p.name, p.parameterType)
						}
						body = feature.body
					]
                                }
                       }
...


I'd like to add this.setHasChanged() and this.notifyObservers() at method body's end.

I can't find a proper way.

Any help?

Best regards and thanks in advance!
Miguel

Re: Appending notifiyObservers call to a XBlockExpression using jvmInferrer [message #1137681 is a reply to message #1137595] Mon, 14 October 2013 17:09 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13667
Registered: July 2009
Senior Member
Hi this is currently not possible. You might infer two methods
instead: one that takes the body from the model and another that
calls this method and the notification stuff with a body written as
string

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


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: Appending notifiyObservers call to a XBlockExpression using jvmInferrer [message #1138169 is a reply to message #1137681] Tue, 15 October 2013 01:00 Go to previous message
Miguel Carboni is currently offline Miguel CarboniFriend
Messages: 8
Registered: September 2013
Junior Member
Thanks for the quick answer. It worked.

Best regards,
Miguel
Previous Topic:Strip comments during serialization?
Next Topic:platform:/resource when projects sit outside the workspace?
Goto Forum:
  


Current Time: Thu Dec 03 09:19:33 GMT 2020

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

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

Back to the top