Question

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

Était-ce utile?

La solution

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

Autres conseils

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

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top