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