1

I'm trying to count the total lines of code, and most importantly the lines of comments!

I am currently using eclipse, and I have tried metrics2 for eclipse but it only gives total lines of code, which ignores whitespace and comments.

Could anyone suggest how I can get this value please

Thanks

AlanFoster
  • 8,156
  • 5
  • 35
  • 52
  • Do you insist on using Eclipse for this? – Ira Baxter Dec 10 '11 at 17:00
  • @IraBaxter No, I just mentioned it as its my currently preferred IDE. I also have netbeans, but I will try an external program, I just need a quick count it's not a long term requirement. – AlanFoster Dec 10 '11 at 17:02

3 Answers3

1

You can try cloc. It is simple to use and supports a bunch of languages.

Bora Caglayan
  • 151
  • 1
  • 7
1

CodePro Analytix is an Eclipse plug-in that collects Java metrics including counting comments.

KenK
  • 263
  • 2
  • 10
  • +1 Because the link looks really good. I'm not changing the accepted answer until I try it out though! Thanks – AlanFoster Feb 02 '12 at 18:57
0

If you need this only once, and you don't mind it being slightly wrong, you can use a regular expression to hunt for comment start indicators, and simply count the number of hits. My unix is bit rusty, but I think you want something like

grep -r '.*/[\*/]' yourdirectory | wc

This finds lines that apparantly have a comment start in them, and then "counts". wc produces three numbers: line count, word count, character count; the first value is line count and corresponds to the number of hits, therefore the number of comments encountered.

If you want the number of comment lines, this will badly undercount multiline /* ... */ comments; you'll get a lower bound. But then, you wanted a fast answer.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341