<!---->
<
xsl:
stylesheet xmlns:src="
http://www.sdml.info/srcML/src"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:xw="
http://www.pnp-software.com/XWeaver"
xmlns:java="
http://www.sdml.info/srcML/java"
xmlns:xd="
http://www.pnp-software.com/XSLTdoc"
xmlns:ax="
http://control.ee.ethz.ch/XWeaver/AspectX"
version="
2.0">
<
xd:
doc type="
stylesheet">
<
xd:
short>
Weaving Rule that adds an import statement to a unit. </
xd:
short>
<
xd:
detail>
<
ul>
<
li>
srcML element: <
code>
src:unit</
code></
li>
<
li>
advice type: <
code>
add</
code></
li>
<
li>
codeModifier type: <
code>
java:import</
code></
li>
</
ul>
Adds imports to the first possible location of the following choices:
<
ol>
<
li>
Directly before other import statements</
li>
<
li>
Before first class definition</
li>
</
ol>
<
h2>
Example</
h2>
<
div class="
source">
<
pre>
import util:*;
public class Inventory {
private int x;
...
}</
pre>
</
div>
<
h3>
Code Modifier</
h3>
<
xd:
xml>
<
codeModifier type="
import">
<
text>
import test.*;</
text>
<
text>
import custom.*;</
text>
</
codeModifier>
</
xd:
xml>
<
h3>
Modified Code</
h3>
<
div class="
source">
<
pre>
import test.*;
import custom.*;
import util:*;
public class Inventory {
private int x;
...
}</
pre>
</
div>
<
xd:
weaverRuleLinks pointcutType="
src:unit"
adviceType="
add"
codeModifierType="
import" />
</
xd:
detail>
<
xd:
cvsId>
$Id$</
xd:
cvsId>
<
xd:
author>
ibirrer</
xd:
author>
<
xd:
copyright>
2004, P&P Software GmbH</
xd:
copyright>
</
xd:
doc>
<!---->
<
xsl:
preserve-space elements="
*" />
<
xd:
doc>
Adds includes to the first possible location of the following choices:
<
ul>
<
li>
Directly before other inlcudes</
li>
<
li>
After a package declaration</
li>
<
li>
At the beginning</
li>
</
ul>
</
xd:
doc>
<
xsl:
template match="
src:unit[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='import']]"
mode="
weaving">
<
xsl:
copy>
<
xsl:
copy-of select="
@*" />
<!---->
<
xsl:
copy-of select="
ax:advice[position() != 1]" />
<
xsl:
choose>
<
xsl:
when test="
java:import">
<!---->
<
xsl:
apply-templates select="
java:import/preceding-sibling::node()"
mode="
weaving" />
<
xsl:
apply-templates select="
java:import"
mode="
weaving" />
<
xsl:
text>
</
xsl:
text>
<
xsl:
copy-of select="
xw:getCodeModifierContent(ax:advice/ax:codeModifier)" />
<
xsl:
apply-templates select="
java:import/following-sibling::node()"
mode="
weaving" />
</
xsl:
when>
<
xsl:
when test="
java:package_decl">
<!---->
<
xsl:
apply-templates select="
java:package_decl/preceding-sibling::node()"
mode="
weaving" />
<
xsl:
apply-templates select="
java:package_decl"
mode="
weaving" />
<
xsl:
text>
</
xsl:
text>
<
xsl:
copy-of select="
xw:getCodeModifierContent(ax:advice/ax:codeModifier)" />
<
xsl:
apply-templates select="
java:package_decl/following-sibling::node()"
mode="
weaving" />
</
xsl:
when>
<
xsl:
otherwise>
<
xsl:
copy-of select="
xw:getCodeModifierContent(ax:advice/ax:codeModifier)" />
<
xsl:
apply-templates mode="
weaving" />
</
xsl:
otherwise>
</
xsl:
choose>
</
xsl:
copy>
</
xsl:
template>
</
xsl:
stylesheet>
v