What the "TLOC" counts is not specified anywhere, at least that I have found.
Through testing, I've found the following to be true:
Everything about every method and constructor in all classes is counted:
--------
/**
* Javadoc
*/
public TestClass() {
// comment
super(2)
}
--------
The above method counts all lines (8).
Nothing else seems counted, even not field declarations, nor static initializers or instance initializers, nor the class declaration itself.
It seems like the "Total number of method Lines of Code", really.
Here's some suggestions:
*) "TLOC" should be renamed to "Total MLOC", and a definition of what it is should be clearly defined.
"TLOC" is ambigious - I've seen it defined as "Thousand LOCs" (some sites) and "Terra LOCs" (Wikipedia). The only I've seen defining the T as "Total" is Eclipse Metrics?
*) Possibly just drop the current "TLOC" altogether: I would _never_ have guessed the current specification of it: I feel it is rather counter-intuitive in many aspects. Or at least consider the above suggestion regarding name.
*) Another LOC-definition that include /all/ lines that are program code, but excludes /everything/ else (/all/ empty lines, comments, javadocs). Call it "Total LOC"? Include a small definition.
*) A LOSC that just counts _all lines_ in the source code (possibly dropping empty lines at the end of source files) - this to get an idea about the "girt" of the total source would it have been printed ("It would have required 7 x 500-pages packages of printer paper to print, given 125 lines per page). Call it "Total LOSC"? Include a small definition.
*) The total number of statements. Call it "Total NOS"? Include a small definition.
Just to point out the counting: The following class..:
-----
package com.example;
import java.util.ArrayList;
import java.util.List;
/**
* Test.
*/
public class Test {
// Comment
private static int a;
/**
* Another comment.
*/
private List<String> b;
static {
a = 1;
}
{
b = new ArrayList<String>();
}
public Test() {
}
}
-----
.. which is 31 lines of source code, counts as 2 lines (the constructor).
One more thought: I actually thought that "LOC" should not count comments nor empty lines. Thus the current "TLOC" should be renamed to "Total MLOSC": Total Methods' Lines of Source Code.
Indeed, I think neither spacing nor comments inline nor javadocs should not be counted when considering the length of a method - this goes for all places where MLOCs are used. If you thoroughly explain a formula over 10 lines in a javadoc or inline, should this really count towards the "method LOC limit"??
Or one needs two measures, MLOC and MLOSC, having different limits.
Here's from "The Other" Metrics project:
http://metrics.sourceforge.net/
(For interested parties, these projects compute the same type of stuff, but in quite different ways. They can apparently be installed both at the same time in Eclipse 3.4.1 w/o problems. The other has an in-Eclipse view, as well as a dependency grapher, while this project aims for HTML export).
" since version 1.3.6 Lines of code has been changed and separated into:
TLOC: Total lines of code that will counts non-blank and non-comment lines in a compilation unit. usefull for thoses interested in computed KLOC.
MLOC: Method lines of code will counts and sum non-blank and non-comment lines /inside/ method bodies "
Unification for these measures would probably be very good for us consumers/developers.
However, I still miss the "total, all lines of source code", and "total number of statements"
But, I was wrong about the "T". I still don't quite like it, though. Wikipedia states that MLOC is MegaLOC. Oh well.
.. also "# of java source files" would be nice.
For anyone dumping in here based on searches or whatever; here's a shell script for counting the total number of source lines (also prints number of files, and average lines per file. Wow!)
#!/bin/bash
#
# Sums up all the length of files with specified ending, or ".java" if not specified,
# from current dir outwards.
#
# Endre Stølsvik, 2009-01-20, based on:
# http://www.gnulamp.com/awkexamples.html
#
ENDING=".java"
if [ "$1" != "" ]; then
ENDING=$1
fi
echo -e "Files with ending \"$ENDING\"\n"
find -name "*$ENDING" -exec wc -l {} \; | \ awk '{sum+=$1; print "", $1, "\t", $2} END{print "\nSum:", sum, " files:", NR, " average:", sum/NR}'
http://sunset.usc.edu/research/COCOMOII/expert_cocomo/sloc.html
" SLOC is an acronym for Source Line Of Code. The total count of SLOCS is the sum of data declaration statements and executable statements. " .. and more.