AddComplexGetterMethod Aspect
[Observability Group]

This aspect is defined in file: ../../AspectXLib/Observability/Base/aspects/AddComplexGetterMethod.ax

Aspect Description

Sample aspect program to add a method to a class. The added method return a more complex function of the inner state of the object than the simple getter method defined in aspect AddGetterMethod.

This aspect is implemented through three advices. The first advice modifies the comment of the target class to include a statement that the class has been modified by an aspect weaver. The second advice adds the method declaration (inclusive of its comment). The third advice adds the method implementation.

The name of target class is Derived and the name of the getter method is getInternalState(). This method does not return a value of some single member variable but it combines values of several member variables together thus it returns the aggregated value representing the part of the state of the object in which we are intrested.
Author:
A. Pasetti, O. Rohlik

Pointcuts

classtargetClass
 Points to the target class to which the getter method should be added
functionmethodImplementation
 Points to all the implementations of the methods of the target class
unittargetUnit
 Points to the unit where the target class is defined
commenttargetClassComment
 Points to the comment of the target class where the getter method should be added

Advices

endaddClassComment
 Add a comment at the end of the comment of the target class
addaddMethodDeclaration
 Add the declaration for the getInternalState() method
addaddMethodDefinition
 Add the definition for the complex getter method

Pointcut Documentation

class targetClass (source)
Points to the target class to which the getter method should be added.
function methodImplementation (source)
Points to all the implementations of the methods of the target class. The identification of the methods in the target class is done as follows. A pointcut is defined that captures all method implementations. This pointcut is then restricted to include only methods that belong to the target class. The implementation of the restriction relies on the fact that in srcML the element 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.
unit targetUnit (source)
Points to the unit where the target class is defined. In srcML, the file that contains the definition part of a class is a "unit". This pointcut identifies the desired unit as the unit that contains a methodImplementation pointcut, namely as the unit that contains the implementation of the method of the target class.
comment targetClassComment (source)
Points to the comment of the target class where the getter method should be added. that must be modified. The comment that must be modified is the comment that is followed by the targetClass pointcut.

Advice Documentation

end addClassComment (source)

Triplet: comment end comment

Add a comment at the end of the comment of the target class. The comment thus inserted states that the class was modified by an aspect program and describes the nature of the modification. The HTML tags in the comment are expressed using escape sequences.

Refers to global pointcut: comment targetClassComment

add addMethodDeclaration (source)

Triplet: class add declaration

Add the declaration for the getInternalState() method. Note that the code modifier must include an accessModifier subelement to specify the access protection level of the new method. Note also that the declaration statements are written without indentation. The indentation is automatically inserted by the weaver to be compatible with the indentation of other parts of the declaration file.

Refers to global pointcut: class targetClass

add addMethodDefinition (source)

Triplet: unit add definition

Add the definition for the complex getter method.

Refers to global pointcut: unit targetUnit