Actions

An action is simply a named piece of code which is executed at certain points in the source code, matched by the specified patterns. An aspect can contain many actions, and as in other aspect-oriented languages, there are before, around and after actions.

As shown in Figure 7, an aspect can contain any number of action blocks, which in turn can host multiple actions inside them. Unlike AspectJ, actions in AspectMatlab are named. Besides the name, an action is linked to a named pattern defined in the patterns block. The type of an action specifies the weaving point of an action with respect to the join points against the pattern specified. Just like a regular MATLAB function, an action can have input parameters. These parameters are special context information which is fetched from the static shadow of each join point matched. Context exposure is described in detail in Section 2.3.1.

Figure 7: Syntax of Actions
\begin{figure}\begin{grammar}[(colon){ ::$\Rightarrow$}]
[(semicolon){\\ \hspac...
...}'',$\vert$,''{\tt after}'',$\vert$,''{\tt around}''.
\end{grammar}
\end{figure}

Simple examples of named before and around actions, which correspond to the patterns pCallFoo and pExecutionMain described in Section 2.2.1, are given in Listing 10. The action aCountCall will be weaved in just before each call to function foo. This action simply increments the count property defined in the properties block of the aspect. Now if we want to display the total number of calls made at the end of the program, we can use the aExecution action. Assuming the end of function main as the program exit point, aExecution action will be weaved in just after the whole function body.


\begin{lstlisting}[language=MATLAB, frame=htbp, caption={Before and After Action...
....getCount();
disp(['total calls: ', num2str(total)]);
end
end
\end{lstlisting}



Subsections
Toheed ASLAM 2010-04-24