Eclipse plugin for measuring lines of code
Asked Answered
C

4

10

I'm running Eclipse Helios (3.6) and was wondering if there is a nice plugin out there that will count the number of logical lines of code in a java source file. By logical, I mean

if (j > 6) {
   j--;
}

In other words, 2 logical lines of code (2 statements) will be counted instead of 3 physical lines of code.

Curst answered 8/8, 2011 at 18:26 Comment(0)
M
3

Metrics2 is an updated version of the Metrics plug-in described by js3v that should do what you need. It can also aggregate some of the measurements (e.g. add up the LOC of classes in a package to give you the LOC of the package). This page explains some of its capabilities and mentions that it counts logical lines of code, not physical ones.

Maiden answered 8/8, 2011 at 19:18 Comment(2)
It doesn't mention anything about counting logical lines of code. What it does mention is McCabe Cyclomatic Complexity, which counts the number of flows through each statement, including logical operators. Logical lines of code is a different matter.Curst
@Curst My mistake. It counts "TLOC: Total lines of code that will counts non-blank and non-comment lines", which isn't quite the same.Maiden
C
2

I have been using checkstyle-cs, a free Eclipse plug-in. Besides logical lines of code, it will also compute cyclomatic and N-path complexity (which may be a better indicator of code problems).

While I don't know if it will generate a report on every module, you might try setting the threshold very low, (like 2). Checkstyle should give you a yellow highlight at the start of every method, telling you how many lines of code it found.

Incidentally, there was some disagreement on our team as to whether

a[i++] = 7;

was one statement or two. There was no disagreement that

a[i] = 7;
i++; 

counted as two statements.

Clavier answered 8/8, 2011 at 19:21 Comment(1)
To the downvoter: this answer has been around almost five years when you discovered it. Did you have a reason to downvote it? After all, it is useful (as the OP himself agrees), it demonstrates research, and it has a reference link (which still works). If it's not your favorite tool, then I suggest upvoting your favorite (instead of downvoting the one that is not your favorite.)Clavier
V
1

Here's one that I've used... works pretty well. http://sourceforge.net/projects/metrics/

Visage answered 8/8, 2011 at 19:2 Comment(0)
S
0

ProjectCodeMeter can be integrated as eclipse external metrics tool, counts many source code metrics such as logical lines of code, complexity, arithmetic intricacy, strings, numeric constants, even estimates development time in hours.

Look at the "integrating into eclipse" section (about half way through the page)

Semele answered 6/10, 2011 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.