<
aspect xmlns:cpp="
http://www.sdml.info/srcML/cpp"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns="
http://control.ee.ethz.ch/XWeaver/AspectX"
xmlns:src="
http://www.sdml.info/srcML/src"
xsi:schemaLocation="
http://control.ee.ethz.ch/XWeaver/AspectX ../../../../src/xsd/aspectX.xsd"
name="
AddClassField">
<
description>
Sample aspect program to add a field to a target class. The aspect program adds the
declaration of a dummy variable to a target class. The target class identified by name and is
class <
code>
DC_DummyPunctualAction</
code>
. This aspect program shows how aspect transformations
can be used to extend the internal state of a base class. <
author>
A. Pasetti</
author>
</
description>
<
pointcut name="
targetClass"
type="
src:class"
constraint="
src:name='DC_DummyPunctualAction'">
<
description>
Points to the target class where the new field should be added. The target class is
identified through its name.</
description>
</
pointcut>
<
advice type="
add"
name="
addVariableDeclaration">
<
description>
Add the declaration of the dummy variable in the target class. The name of the
dummy variable is <
code>
dummyVariable</
code>
. The dummy variable is declared to be private.
This is expressed through the use of the "accessModifier" element. This element must always be
present in code modifiers that add a declaration (either of a variable or of a method) to a
class. Note that the text that is added to the target class includes a line comment. This can
be done because XWeaver treats the text in the code modifier as a code fragment that is
inserted in the place identified by the pointcut but it does not attempt to parse or interpret
it. The text in the code modifier does not specify any indentation. The XWeaver will
automatically indent the text it inserts in the base code.</
description>
<
pointcutRef ref="
targetClass"
type="
src:class" />
<
codeModifier type="
declaration">
<
accessModifier type="
private" />
<
text>
// This is a dummy variable automatically inserted by an aspect program</
text>
<
text>
unsigned int dummyVariable;</
text>
</
codeModifier>
</
advice>
</
aspect>
v