<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 declaration to a class</xd:short>
    
<xd:detail>
      
<ul> 
        
<li>srcML element:     <code>src:private, src:protected, src:public</code></li>
        
<li>advice type:       <code>add</code></li>
        
<li>codeModifier type: <code>declaration</code></li>
      
</ul>
      
<p>This template is used as by <a href="class_add_declaration.xsl.xd.html">class_add_declaration.xsl</a>
      It is not intended to use directly from an aspect.
</p>
    
</xd:detail>
    
<xd:cvsId>$Id$</xd:cvsId>
    
<xd:author>ibirrer</xd:author>
    
<xd:copyright>2004, P&amp;P Software GmbH</xd:copyright>
  
</xd:doc>

  
  
<!-- Preserve Whitespaces -->
  
<xsl:preserve-space elements="*" />
  
  
     <xd:doc>
    Adds a declaration to an access modifier block
  
</xd:doc>

  
<xsl:template match="src:private[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='declaration']] | src:protected[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='declaration']] | src:public[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='declaration']]" mode="weaving">
    
    
<!-- Current advice -->
    
<xsl:variable name="advice" select="ax:advice[1]" />
    
    
<!-- Compute access modifier string (e.g. 'public:') -->
    
<xsl:variable name="accessModifierString">
      
<xsl:choose>
        
<xsl:when test="@type='default'" />
        
<xsl:otherwise>
          
<xsl:value-of select="concat(local-name(.), ':')" />
        
</xsl:otherwise>
      
</xsl:choose>
    
</xsl:variable>
    
    
<!-- Block indent -->
    
<xsl:variable name="blockIndent" select="util:repeatString($defaultIndentation, count(ancestor::src:block))" />
    
    
<!-- Weave -->
    
<xsl:copy>
      
<xsl:copy-of select="@*" />
      
<!-- Copy unprocessed advices -->
      
<xsl:copy-of select="ax:advice[position() != 1]" />
      
<xsl:choose>
        
<xsl:when test="count(*[not(self::ax:advice)]) = 0">
          
<!-- Access modifier block is empty  -->
          
<!-- Add everything before the modifier -->
          
<xsl:value-of select="substring-before(text(), $accessModifierString)" />
          
<!-- Add the modifier and a newline -->
          
<xsl:value-of select="concat($accessModifierString, ' ')" />
          
<!-- Add new declarations -->
          
<xsl:value-of select="util:indentText(xw:getCodeModifierContent($advice/ax:codeModifier), $blockIndent)" />
          
<!-- Add rest -->
          
<xsl:value-of select="substring-after(text(), $accessModifierString)" />
        
</xsl:when>

        
<xsl:otherwise>
          
<!-- Public block contains at least one element (declaration) -->
          
          
<!-- Add all elements contained in the access modifier block, except the last element, 
               but only if the last element is a text node. 
-->
          
<xsl:apply-templates mode="weaving" select="node()[not(position() = last() and self::text()) and not(self::ax:advice)]" />
          
          
<!-- Add newline -->
          
<xsl:text>
</xsl:text>
          
<!-- Add new declarations -->
          
<xsl:value-of select="util:indentText(xw:getCodeModifierContent($advice/ax:codeModifier), $blockIndent)" />
          
<!-- Add the last node if it is a text element -->
          
<xsl:apply-templates select="node()[position() = last() and self::text()]" mode="weaving" />
        
</xsl:otherwise>
      
</xsl:choose>
    
</xsl:copy>
  
</xsl:template>
</xsl:stylesheet>






































v