<
xsl:
stylesheet xmlns:src="
http://www.sdml.info/srcML/src"
xmlns:cpp="
http://www.sdml.info/srcML/cpp"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:xw="
http://www.pnp-software.com/XWeaver"
xmlns:xd="
http://www.pnp-software.com/XSLTdoc"
xmlns:util="
http://www.pnp-software.com/util"
xmlns:ax="
http://control.ee.ethz.ch/XWeaver/AspectX"
version="
2.0">
<
xd:
doc type="
stylesheet">
<
xd:
short>
Weaving Rule that adds a comment to a declaration (class/method/constructor/destructor/fields) </
xd:
short>
<
xd:
detail>
<
ul>
<
li>
srcML element: <
code>
src:function_decl, src:function, src:class, src:constructor, src:constructor_decl, src:constructor, src:destructor, src:destructor_decl, src:decl_stmt</
code></
li>
<
li>
advice type: <
code>
add</
code></
li>
<
li>
codeModifier type: <
code>
comment</
code></
li>
</
ul>
<
h2>
Example 1</
h2>
<
div class="
source">
<
pre>
int foo();</
pre>
</
div>
<
h3>
Code Modifier</
h3>
<
xd:
xml>
<
codeModifier type="
comment">
<
text>
/** A comment */</
text>
</
codeModifier>
</
xd:
xml>
<
h3>
Modified Code</
h3>
<
div class="
source">
<
pre>
/** A comment */
int foo();</
pre>
</
div>
<
xd:
weaverRuleLinks pointcutType="
src:function_decl"
adviceType="
add"
codeModifierType="
comment" />
</
xd:
detail>
<
xd:
cvsId>
$Id$</
xd:
cvsId>
<
xd:
author>
ibirrer</
xd:
author>
<
xd:
copyright>
2004, P&P Software GmbH</
xd:
copyright>
</
xd:
doc>
<
xd:
doc>
Adds the the comment before the declaration
</
xd:
doc>
<
xsl:
template match="
src:function_decl[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='comment']] | src:function[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='comment']] | src:constructor[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='comment']] | src:constructor_decl[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='comment']] | src:destructor[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='comment']] | src:destructor_decl[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='comment']] | src:class[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='comment']] | src:constructor[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='comment']] | src:decl_stmt[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='comment']]"
mode="
weaving">
<!---->
<
xsl:
variable name="
indent"
select="
util:getIndent(.)" />
<!---->
<
ax:
inserted>
<
xsl:
value-of select="
util:indentText(xw:getCodeModifierContent(ax:advice[1]/ax:codeModifier), $indent, false())" />
</
ax:
inserted>
<
xsl:
value-of select="
concat(' ',$indent)" />
<!---->
<
xsl:
copy>
<
xsl:
copy-of select="
@*" />
<!---->
<
xsl:
copy-of select="
ax:advice[position() != 1]" />
<
xsl:
copy-of select="
node()[not(self::ax:advice)]" />
</
xsl:
copy>
</
xsl:
template>
</
xsl:
stylesheet>
v