../../AspectXLib/CodeInstrumentation/Base/aspects/TraceMethodIntParametersOnly.axprintf instruction that
writes a message to the output device stating the name of the method, the name of the class
to which it belongs and the value of its int parameters.
In this example, the identification of the methods for which tracing is to
be performed (and which therefore must be modified by the aspect) is done using
examination of method's parameters and their types. This aspect defines four advices that describe four separate but related
changes. The first advice inserts the tracing code in the target methods. The second advice
inserts a new include statement to include the stdio library that is
required by the printf method. The third advice modifies the comments of the
classes that are affected by the change to include a statement that the class code has been
automatically modified by an aspect program. The fourth advice modifies the comment of the
methods that are affected by the change to include a description of the type of change that has
been woven into the code.
This sample aspect program targets all methods whose all paramters
are of type int.
Pointcuts | |
| function | targetMethodImplementation |
| Points to the implementations of the methods that must be modified | |
| function_decl | targetMethodDeclaration |
| Points to all declarations of the target methods | |
| comment | targetMethodComment |
| Points to the method comments that must be modified | |
| class | targetClass |
| Points to all classes that contain a target method | |
| comment | targetClassComment |
| Points to the class comments that must be modified | |
| unit | targetImplementationUnit |
| Points to all the units that contain implementations of methods that must be
modified | |
Advices | |
| end | insertClassComment |
| Add a comment at the end of the comment of the classes that are modified by other advices | |
| end | insertMethodComment |
| Add a comment at the end of the comment of the methods that are modified by other advices | |
| begin | insertTrace |
| Insert the tracing instruction in the target methods | |
| add | addInclude |
| Add the #include statement for the stdio library | |
int parameters and no parameters
of other type.
Recall that in srcML, element name contains the whole list of parameters within
parameter_list element. Then count() function can be used to
specify that the numeber of all method parameters has to be equal to number of int
parameters. Note that it is desired to exlude methods that has no parameters.
This pointcut only points to the method implementation. A second pointcut
(targetMethodDeclaration) points to the method declarations.targetMethodImplementation) but note that the srcML element
name in a declaration file may contain specifier virtual.
This specifier means that there is a chance that the method is pure virtual method
i.e. it does not have its implementation and therefore there is nothing woven
in the function body. The pure virtual method can be identified by the assignment sign
that follows the parameter_list element.targetMethodDeclaration pointcut. targetMethodDeclaration pointcut targetClass
pointcut. Triplet: comment end comment
Refers to global pointcut: comment targetClassComment
Triplet: comment end comment
Refers to global pointcut: comment targetMethodComment
Triplet: function begin codeFragment
xsl:for-each
and xsl:value-of. The xsl:for-each instruction access all parameter names
and transforms them to string using xsl:value-of instruction.
Refers to global pointcut: function targetMethodImplementation
Triplet: unit add include
#include statement for the stdio library.
Inclusion of this library is necessary because the code that is woven into the target methods
calls the stdio function printf. Note that the code to be added by this advice is
specified using the CDATA section because otherwise the braces around "stdio" would be
interpreted as XML braces by the XWeaver program.Refers to global pointcut: unit targetImplementationUnit