Skip to content

Commit

Permalink
#22 skip interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 25, 2017
1 parent 27a971f commit 33078a9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
28 changes: 17 additions & 11 deletions src/main/java/org/jpeek/metrics/JavassistClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand All @@ -44,7 +43,9 @@
import org.xembly.Directives;

/**
* Lack of Cohesion in Methods (LCOM).
* Classes parsed by Javassist.
*
* <p>We take into account only classes. Interfaces are ignored.</p>
*
* <p>There is no thread-safety guarantee.
*
Expand Down Expand Up @@ -97,7 +98,7 @@ public Iterable<Directive> xembly() throws IOException {
.add("app")
.attr("id", this.base.toString())
.append(
new Joined<>(
new Joined<Directive>(
new Mapped<>(
this.metrics(),
ent -> new Directives()
Expand All @@ -121,9 +122,17 @@ private Iterable<Map.Entry<String, Directives>> metrics()
final Map<String, Directives> map = new HashMap<>(0);
final Iterable<Map.Entry<String, Directives>> all = new Mapped<>(
new Filtered<>(
this.base.files(),
path -> Files.isRegularFile(path)
&& path.toString().endsWith(".class")
new Mapped<>(
new Filtered<>(
this.base.files(),
path -> Files.isRegularFile(path)
&& path.toString().endsWith(".class")
),
path -> this.pool.makeClassIfNew(
new FileInputStream(path.toFile())
)
),
ctClass -> !ctClass.isInterface()
),
this::metric
);
Expand All @@ -136,15 +145,12 @@ private Iterable<Map.Entry<String, Directives>> metrics()

/**
* Calculate metrics for a single .class file.
* @param file The .class file
* @param ctc The class
* @return Metrics
* @throws IOException If fails
*/
private Map.Entry<String, Directives> metric(
final Path file) throws IOException {
final CtClass ctc = this.pool.makeClassIfNew(
new FileInputStream(file.toFile())
);
final CtClass ctc) throws IOException {
final double cohesion = this.func.apply(ctc);
ctc.defrost();
String pkg = ctc.getPackageName();
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/org/jpeek/index.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
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" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="2.0">
<xsl:template match="/">
<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html&gt;</xsl:text>
<html lang="en">
Expand All @@ -45,7 +45,7 @@ SOFTWARE.
<xsl:template match="metrics">
<p>
<a href="http://www.jpeek.org">
<img src="http://www.jpeek.org/logo.svg" style="height:60px"/>
<img alt="logo" src="http://www.jpeek.org/logo.svg" style="height:60px"/>
</a>
</p>
<h1>
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/org/jpeek/jpeek.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
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" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="2.0">
<xsl:template match="/">
<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html&gt;</xsl:text>
<html lang="en">
Expand All @@ -33,7 +33,7 @@ SOFTWARE.
<meta name="author" content="jpeek.org"/>
<link rel="shortcut icon" href="http://www.jpeek.org/logo.png"/>
<link rel="stylesheet" href="http://cdn.rawgit.com/yegor256/tacit/gh-pages/tacit-css-1.1.1.min.css"/>
<script src="http://cdnjs.cloudflare.com/ajax/libs/sortable/0.8.0/js/sortable.min.js">&#xA0;</script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/sortable/0.8.0/js/sortable.min.js">&#xA0;</script>
<title>
<xsl:value-of select="app/@title"/>
</title>
Expand All @@ -52,7 +52,7 @@ SOFTWARE.
<body>
<p>
<a href="http://www.jpeek.org">
<img src="http://www.jpeek.org/logo.svg" style="height:60px"/>
<img alt="logo" src="http://www.jpeek.org/logo.svg" style="height:60px"/>
</a>
</p>
<p>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jpeek/metrics/cohesion/CAMCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void createsBigXmlReport() throws IOException {
),
XhtmlMatchers.hasXPaths(
"/app/package/class[@id='CAMCTest']",
"//class[@id='Base' and @value='1.0000']"
"//class[@id='DefaultBase' and @value='0.3333']"
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jpeek/metrics/cohesion/LCOMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void createsBigXmlReport() throws IOException {
),
XhtmlMatchers.hasXPaths(
"/app/package/class[@id='LCOMTest']",
"//class[@id='Base' and @value='0.0000']"
"//class[@id='DefaultBase' and @value='0.0000']"
)
);
}
Expand Down

0 comments on commit 33078a9

Please sign in to comment.