Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#120) TCC: advancing implementation #182

Merged
merged 5 commits into from
Feb 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ _[A] new metric [...] yielding meaningful values [...] more sensitive than those
International Journal "Information Theories & Applications", Volume 13, 2006,
[PDF](http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=55D08270F99333F15E0937AF137F4468?doi=10.1.1.84.1506&rep=rep1&type=pdf).

[`bieman95`]
Tight Class Cohesion (**TCC**).<br/>
James M. Bieman et al.,<br/>
Cohesion and Reuse in an Object-Oriented System,<br/>
Department of Computer Science, Colorado State University, 1995,
[PDF](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.2683).

## How it works?

First, `Skeleton` parses Java bytecode using Javaassit and ASM, in order to produce
Expand Down
Binary file added papers/bieman95.pdf
Binary file not shown.
37 changes: 26 additions & 11 deletions src/main/resources/org/jpeek/metrics/TCC.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,57 @@ SOFTWARE.
</metric>
</xsl:template>
<xsl:template match="class">
<xsl:variable name="methods" select="methods/method"/>
<!--
@todo #120:30min TCC: inclusion of inherited attributes and methods in the analysis
should be configurable. Come back here after #187 is fixed and adjust the xpath
for `attrs` and `methods` accordingly.
-->
<xsl:variable name="attrs" select="attributes/attribute[@static='false']/text()"/>
<!--
@todo #120:30min TCC: this metric needs to exclude private methods from the analysis.
Adjust the xpath for `methods` accordingly after #188 is fixed.
-->
<xsl:variable name="methods" select="methods/method[@abstract='false' and @ctor='false']"/>
<xsl:variable name="methods_count" select="count($methods)"/>
<xsl:variable name="NC" select="$methods_count * ($methods_count - 1) div 2"/>
<xsl:variable name="directly-related-pairs">
<xsl:for-each select="$methods">
<!--
@todo #9:30min `directly-related-pairs` currently don't take into account cases when two methods are
directly related through calling the third one. This could be possible to take into account only when
skeleton will be able to provide method-method relation information (issue #106)
@todo #120:30min TCC: need to come back and refactor the following after
#156 is fixed. The ops for fields must be properly filtered to ensure
that they belong to the enclosing class.
-->
<xsl:variable name="i" select="position()"/>
<xsl:variable name="left" select="."/>
<xsl:variable name="left_ops" select="$left/ops/op[@code='get' or @code='put']"/>
<xsl:variable name="left_attrs" select="$attrs[. = $left/ops/op/text()]"/>
<xsl:for-each select="$methods">
<xsl:if test="position() &gt; $i">
<xsl:variable name="right" select="."/>
<xsl:variable name="right_ops" select="$right/ops/op[@code='get' or @code='put']"/>
<pair>
<xsl:value-of select="count($left_ops[.=$right_ops])"/>
</pair>
<xsl:variable name="right_attrs" select="$attrs[. = $right/ops/op/text()]"/>
<xsl:if test="exists($left_attrs[. = $right_attrs])">
<pair/>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="NDC" select="count($directly-related-pairs)"/>
<xsl:variable name="NDC" select="count($directly-related-pairs/pair)"/>
<xsl:copy>
<xsl:attribute name="value">
<xsl:choose>
<xsl:when test="$methods_count le 1"><xsl:text>0</xsl:text>0</xsl:when>
<xsl:when test="$methods_count le 1">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$NDC div $NC"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="@*"/>
<vars>
<var id="attributes">
<xsl:value-of select="count($attrs)"/>
</var>
<var id="methods">
<xsl:value-of select="count($methods)"/>
</var>
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/org/jpeek/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ public static Collection<Object[]> targets() {
new Object[] {"OneVoidMethodWithoutParams", "LCOM3", 1.0d},
new Object[] {"OverloadMethods", "LCOM3", 0.25d},
new Object[] {"TwoCommonAttributes", "LCOM3", 1.0d},
new Object[] {"WithoutAttributes", "LCOM3", 0.0d}
new Object[] {"WithoutAttributes", "LCOM3", 0.0d},
new Object[] {"Foo", "TCC", 1.0d},
new Object[] {"MethodsWithDiffParamTypes", "TCC", 0.2d}
);
}

Expand Down