TraceConstructorEntry Aspect
[CodeInstrumentation Group]

This aspect is defined in file: ../../AspectXLib/CodeInstrumentation/Base/aspects/TraceConstructorEntry.ax

Aspect Description

Sample aspect program to insert tracing instructions when a construtor is entered. This aspect program shows an example of how the implementation of class's constructors can be modified to output a tracing message every time the construtor is executed. In this example, the tracing message is output using a printf instruction that writes a message to the output device stating the name of the class to which it belongs. In this example, the identification of the constructors for which tracing is to be performed (and which therefore must be modified by the aspect) is done "by class name". This is probably the simplest approach in AspectX.

This aspect defines four advices that describe four separate but related changes. The first advice inserts the tracing code in the target constructors. 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 comment 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 constructor(s) of all classes in the base code
Author:
A. Pasetti, o. Rohlik
See also:
TraceClassEntry
TraceMethodEntry

Pointcuts

constructortargetConstructorImplementation
 Points to the implementations of the constructors that must be modified
constructor_decltargetConstructorDeclaration
 Points to all declarations of the target constructors
commenttargetConstructorComment
 Points to the constructor comments that must be modified
classtargetClass
 Points to all classes that contain a target constructor
commenttargetClassComment
 <p> Points to the class comments that must be modified
unittargetImplementationUnit
 Points to all the units that contain implementations of constructors that must be modified

Advices

endinsertClassComment
 Add a comment at the end of the comment of the classes that are modified by other advices
endinsertConstructorComment
 Add a comment at the end of the comment of the constructors that are modified by other advices
begininsertTrace
 Insert the tracing instruction in the target constructor
addaddInclude
 Add the #include statement for the stdio library

Pointcut Documentation

constructor targetConstructorImplementation (source)
Points to the implementations of the constructors that must be modified. This particular pointcut targets all constructors in the base code. However, it is possible to restrict pointcut to include only constructors that belong to a target class -- this is shown in another sample aspect: TraceClassEntry.

This pointcut only points to the method implementation. A second pointcut (targetConstructorDeclaration) points to the method declarations.
constructor_decl targetConstructorDeclaration (source)
Points to all declarations of the target constructors. Similarily to the pointcut targetConstructorImplementation it targets all constructors in the base code.
comment targetConstructorComment (source)
Points to the constructor comments that must be modified. The constructor comments that must be modified are those that are followed by a targetConstructorDeclaration pointcut.
class targetClass (source)
Points to all classes that contain a target constructor. The identification is done by taking all the classes that contains a targetConstructorDeclaration pointcut
comment targetClassComment (source)
<p> Points to the class comments that must be modified. The class comments that must be modified are those that are followed by a targetClass pointcut.
unit targetImplementationUnit (source)
Points to all the units that contain implementations of constructors that must be modified. In srcML, a unit is a source file (a definition file, a declaration file, or an inline file). This pointcut therefore identifies all the source files that contain an implementation of the target constructor.

Advice Documentation

end insertClassComment (source)

Triplet: comment end comment

Add a comment at the end of the comment of the classes that are modified by other advices.

Refers to global pointcut: comment targetClassComment

end insertConstructorComment (source)

Triplet: comment end comment

Add a comment at the end of the comment of the constructors that are modified by other advices.

Refers to global pointcut: comment targetConstructorComment

begin insertTrace (source)

Triplet: constructor begin codeFragment

Insert the tracing instruction in the target constructor. This advice inserts a printf instruction at the beginning of the target constructor. The printf instruction prints a message stating the name of the target class. The name of the target class is accessed using XSL instruction value-of with XPath expression that extracts the class name from scrML. See also the pointcut targetConstructorImplementation.

Refers to global pointcut: constructor targetConstructorImplementation

add addInclude (source)

Triplet: unit add include

Add the #include statement for the stdio library. Inclusion of this library is necessary because the code that is woven into the target constructors 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