../../AspectXLib/CodeInstrumentation/Base/aspects/TraceClassEntry.ax
printf
instruction that
writes a message to the output device stating the name of the method and the name of the class
to which it belongs. In this example, the identification of the target class for which tracing
is to be performed (and which therefore must be modified by the aspect) is done "by name". The
aspect only covers the case of a single target class but it could be easily modified to cover
several target classes. This aspect defines four advices that describe four separate but
related changes. The first advice inserts the tracing code in the methods of the target class.
The second advice inserts the tracing code in the constructors of the target class.
The third advice inserts a new include
statement to include the stdio
library that is required by the printf
method. The fourth advice modifies the
comment of the target class to include a statement that the class code has been automatically
modified by an aspect program. This sample aspect program targets a class called
Derived
.
Pointcuts | |
function | targetMethodImplementation |
Points to the implementations of the methods in the target class | |
constructor | targetConstructorImplementation |
Points to the constructors of the target class | |
class | targetClass |
Points to the target class to be modified by this aspect program | |
comment | targetClassComment |
Points to the comment of the target class | |
unit | targetImplementationUnit |
Points to the unit that contains the implementations of the target class | |
Advices | |
begin | insertMethodTrace |
Insert the tracing instruction in the target methods | |
begin | insertConstructorTrace |
Insert the tracing instruction in the target construtors | |
add | addInclude |
Add the #include statement for the stdio library | |
end | insertClassComment |
Add a comment at the end of the comment of the target class |
name
contains two other name
subelements
where the first of them contains the class name and the second contains name of the method.
Therefore to access the name of the class the following expression is used:
src:name/src:name[1]
.
If it were
desired to capture more than one target class, this could be done by modifying the XPath
expression in the constraint to include names whose class part matches several class names.
Note that this pointcut only points to the method implementation. There is no need
to capture the method declarations since this aspect program does not make any modifications
to the method declarations or to their comments.name
contains the fully qualified name of the
constructors and methods. This has the form "CCC::CCC" where "CCC" is the class name.
This pointcut only points to the class constructors. This excludes the class
destructors because srcML treats them
separately. Another dedicated pointcut would be required if it were
desired to insert the tracing message in the destructor.
If it were
desired to capture more than one target class, this could be done by modifying the XPath
expression in the constraint to include names whose class part matches several class names.
targetMethodImplementation
pointcut that points to the implementation of the
methods in the target class.Triplet: function begin codeFragment
Refers to global pointcut: function targetMethodImplementation
Triplet: constructor begin codeFragment
value-of
with XPath expression that extracts the class name
from scrML. See also the pointcut targetConstructorImplementation
.Refers to global pointcut: constructor targetConstructorImplementation
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 class
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
Triplet: comment end comment
Refers to global pointcut: comment targetClassComment