Skip to main content



      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 11:56 Go to next message
Eclipse UserFriend
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 13:09 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Appending notifiyObservers call to a XBlockExpression using jvmInferrer [message #1138169 is a reply to message #1137681] Mon, 14 October 2013 21:00 Go to previous message
Eclipse UserFriend
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: Wed Jul 16 06:24:09 EDT 2025

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

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

Back to the top