A prototype implementation of aspects for MOFScript is in place. This is preliminary implementation and by no means complete. For example, there is not a lot of semantics checking of an aspect.
The MOFScript aspects works by inserting transformation code into (a copy of) the target transformation, which is stored as a new transformation. I.e. the weaving is all done compile time, not run time.An aspect is a specialization of a transformation. It contains pointcuts and advices, and may also define ordinary MOFScript rules.
An aspect is defined as a separate aspect transformation, identified by the keyword ‘aspect’
aspect JavaAspect {
…
}
Pointcuts identify points of execution in the MOFScript transformation (joinpoints).
A pointcut has a name and may have a type specification. Currently, two types of pointcuts are defined in MOFScript:
- call: Refers to the calling of a specific set of rules
- execute: Refers to the rules themselves.
A pointcut further defines a match critera in terms of a regular expression (as a string literal). The match critera defines what rules are matched by the pointcut.
pointcut classPrivateAttributeCall(Class) call ("classPrivateAttribute");
pointcut propertyNamedCall call ("property.*");
pointcut propertySetterExecute execute ("propertySetter")
Currently, there is no type checking of
the aspects. The type passed as parameter for a pointcut must be a model type
name without any prefix.
Advice describes the actions to be executed at when specific joinpoints (specified by the pointcuts) occur. An advice refers to one pointcut and has three possible modifiers: before, after, and around, which gives the semantics of what happens to the advice actions.
- Before: Inserts the advice code before the code identified by the pointcut.
- After: Inserts the advice code after the code identified by the pointcut.
- Around: Replaces the code identified by the pointcut.
aspect JavaAspect {
pointcut propertyGetterCall call ("propertyGetter");
pointcut propertySetterExecute execute ("propertySetter")
pointcut propertyNamedCall call ("property.*");
before propertyNamedCall {
log ("\n calling a property function")
}
before propertyGetterCall {
‘code inserted before call to property getter’
}
around propertySetterExecute {
'
public void set ' self.name 'Replaced('self.type.name') {
}
'
}
}
An aspect is executed (in the Eclipse IDE) by running just as an ordinary MOFScript transformation. As input for the aspect is another MOFScript transformation.
The implementation of the aspect transformation is itself as a MOFScript transformation.