I\'ve tried the Metrics plugin and although it\'s nice and all, it\'s not what my boss is looking for. It counts a line with just one }
as a line and he doesn\'t wa
Install the Eclipse Metrics Plugin. To create a HTML report (with optional XML and CSV) right-click a project -> Export -> Other -> Metrics
.
You can adjust the Lines of Code metrics by ignoring blank and comment-only lines or exclude Javadoc if you want. To do this check the tab at Preferences -> Metrics -> LoC
.
That's it. There is no special option to exclude curly braces {}
.
The plugin offers an alternative metric to LoC called Number of Statements. This is what the author has to say about it:
This metric represents the number of statements in a method. I consider it a more robust measure than Lines of Code since the latter is fragile with respect to different formatting conventions.
Edit:
After you clarified your question, I understand that you need a view for real-time metrics violations, like compiler warnings or errors. You also need a reporting functionality to create reports for your boss. The plugin I described above is for reporting because you have to export the metrics when you want to see them.
Another way would by to use another loc utility, like LocMetrics for instance.
It also lists many other loc tools.
The integration with Eclipse wouldn't be always there (as it would be with Metrics2, which you can check out because it is a more recent version than Metrics), but at least those tools can reason in term of logical lines (computed by summing the terminal semicolons and terminal curly braces).
You can also check with eclipse-metrics is more adapted to what you expect.
There's always the "brute force":
Search->File
Type the following in "Containing text" -> ^.*$
. Then check the "Regular Expression" checkbox
Type the following in "File name patterns" -> *.java
Click "Search"
Check the number of matches in the "Search" Tab.
For static analysis, I've used and recommend SonarQube which runs just about all the metrics you could possibly want on a wide range of languages, and is free in the basic version (you have to pay to analyse the sorts of languages I'd only code in with a gun to my head).
You have to install it as a web-app running the analysis off your source code repository, but it also has an Eclipse plugin.
It's overkill if you just want to know, as a one-off, how many lines of code there are in your project. If you want to track metrics through time, compare across projects, fire warnings when a threshold is exceeded, etc., it's fantastic.
Disclosure: I have no financial relationship with SonarSource.
I created a Eclipse plugin, which can count the lines of source code. It support Kotlin, Java, Java Script, JSP, XML, C/C++, C#, and many other file types.
Please take a look at it. Any feedback would be appreciated!
the git-hub repository is here
If on OSX or *NIX use
Get all actual lines of java code from *.java files
find . -name "*.java" -exec grep "[a-zA-Z0-9{}]" {} \; | wc -l
Get all lines from the *.java files, which includes empty lines and comments
find . -name "*.java" -exec cat | wc -l
Get information per File, this will give you [ path to file + "," + number of lines ]
find . -name "*.java" -exec wc -l {} \;