Skip to content

Commit

Permalink
#91 fix XSL codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
vmotsak committed Jan 15, 2018
1 parent df37337 commit 3087dc9
Showing 1 changed file with 64 additions and 69 deletions.
133 changes: 64 additions & 69 deletions src/main/resources/org/jpeek/metrics/MMAC.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,73 +23,68 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="skeleton">
<metric>
<xsl:apply-templates select="@*"/>
<title>MMAC</title>
<description>
Method-Method through Attributes Cohesion (MMAC).
The MMAC is the average cohesion of all pairs of methods.
In simple words this metric shows how much methods have the
same parameters or return types. When class has some number
of methods and most of them operate the same parameters it
assumes better. It looks like class contains overloaded
methods. Preferably when class has only one method with
parameters and/or return type and it assumes that class
do only one thing. Value of MMAC metric is better for these
one classes.
Metric value is in interval [0, 1]. Value closer to 1 is better.
</description>
<xsl:apply-templates select="node()"/>
</metric>
</xsl:template>
<xsl:template match="class">
<xsl:variable name="class" select="."/>
<xsl:variable name="methods_count" select="count($class/methods/method[@ctor='false'])"/>
<xsl:variable name="types"
select="distinct-values($class/methods/method/args/arg[@type!='V']/@type)"/>
<xsl:variable name="types_count" select="count($types)"/>
<xsl:variable name="type_methods">
<xsl:for-each select="$types">
<xsl:variable name="type" select="."/>
<xsl:variable name="count"
select="count($class/methods/method[@ctor='false' and args/arg/@type=$type])"/>
<count>
<xsl:value-of select="$count * ($count - 1)"/>
</count>
</xsl:for-each>
</xsl:variable>
<xsl:copy>
<xsl:attribute name="value">
<xsl:choose>
<xsl:when test="$methods_count = 0 or $types_count = 0">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:when test="$methods_count = 1">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="format-number(sum($type_methods/count)
div ($methods_count * $types_count * ($methods_count - 1)),
'0.####')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="@*"/>
<vars>
<var id="methods">
<xsl:value-of select="$methods_count"/>
</var>
<var id="types">
<xsl:value-of select="$types_count"/>
</var>
</vars>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="skeleton">
<metric>
<xsl:apply-templates select="@*"/>
<title>MMAC</title>
<description>
Method-Method through Attributes Cohesion (MMAC).
The MMAC is the average cohesion of all pairs of methods.
In simple words this metric shows how much methods have the
same parameters or return types. When class has some number
of methods and most of them operate the same parameters it
assumes better. It looks like class contains overloaded
methods. Preferably when class has only one method with
parameters and/or return type and it assumes that class
do only one thing. Value of MMAC metric is better for these
one classes.
Metric value is in interval [0, 1]. Value closer to 1 is better.
</description>
<xsl:apply-templates select="node()"/>
</metric>
</xsl:template>
<xsl:template match="class">
<xsl:variable name="class" select="."/>
<xsl:variable name="methods_count" select="count($class/methods/method[@ctor='false'])"/>
<xsl:variable name="types" select="distinct-values($class/methods/method/args/arg[@type!='V']/@type)"/>
<xsl:variable name="types_count" select="count($types)"/>
<xsl:variable name="type_methods">
<xsl:for-each select="$types">
<xsl:variable name="type" select="."/>
<xsl:variable name="count" select="count($class/methods/method[@ctor='false' and args/arg/@type=$type])"/>
<count>
<xsl:value-of select="$count * ($count - 1)"/>
</count>
</xsl:for-each>
</xsl:variable>
<xsl:copy>
<xsl:attribute name="value">
<xsl:choose>
<xsl:when test="$methods_count = 0 or $types_count = 0">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:when test="$methods_count = 1">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number(sum($type_methods/count) div ($methods_count * $types_count * ($methods_count - 1)), '0.####')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="@*"/>
<vars>
<var id="methods">
<xsl:value-of select="$methods_count"/>
</var>
<var id="types">
<xsl:value-of select="$types_count"/>
</var>
</vars>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 3087dc9

Please sign in to comment.