Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse plugin for measuring lines of code

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.

like image 505
Joeblackdev Avatar asked Aug 08 '11 18:08

Joeblackdev


People also ask

How do I run metrics in Eclipse?

To start collecting metrics for a project, right click on the project and from the popup menu select "Metrics->Enable" (or alternatively, use the properties page ). This will tell Eclipse to calculate metrics every time a compile happens.

How does Eclipse calculate cyclomatic complexity?

So how we check the cyclomatic complexity of those projects? Not an IDE plugin, but SonarQube is pretty useful for static code analysis that includes cyclomatic complexity. Sonar has an Eclipse plugin called SonarLint that also tells if the cyclomatic complexity is too hight.


2 Answers

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.

like image 133
kc2001 Avatar answered Sep 24 '22 09:09

kc2001


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.

like image 33
rajah9 Avatar answered Sep 21 '22 09:09

rajah9