../../AspectXLib/Observability/Base/aspects/AddComplexGetterMethod.ax
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.
Pointcuts | |
class | targetClass |
Points to the target class to which the getter method should be added | |
function | methodImplementation |
Points to all the implementations of the methods of the target class | |
unit | targetUnit |
Points to the unit where the target class is defined | |
comment | targetClassComment |
Points to the comment of the target class where the getter method should be added | |
Advices | |
end | addClassComment |
Add a comment at the end of the comment of the target class | |
add | addMethodDeclaration |
Add the declaration for the getInternalState() method | |
add | addMethodDefinition |
Add the definition for the complex getter method |
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.methodImplementation
pointcut, namely as the unit
that contains the implementation of the method of the target class.targetClass
pointcut. Triplet: comment end comment
Refers to global pointcut: comment targetClassComment
Triplet: class add declaration
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
Triplet: unit add definition
Refers to global pointcut: unit targetUnit