|
The total number of lines in a package. Since a package in Java is not
a single unit, but spread over different files, which possibly reside in
different directories, we define the total number of lines in compilation
units that declare themselves to be part of a package.
The count includes everything: code as well as blank space and comments.
One should therefore be careful to use this as a measure of code quality:
other measures like the size of the API defined by a package
are more meaningful.
Pre-packaged Query
Query name = "Metrics/Semmle/Packages/Packages that are large in terms of LOC"
Reports packages that contain more than 1000 lines of code.
from MetricPackage p, int loc
where p.fromSource() and loc = p.getNumberOfLines() and loc > 1000
select p,loc order by loc desc
.QL Source of Metric
This metric is defined in MetricPackage. The definition reads:
int getNumberOfLines() {
result = sum(CompilationUnit cu |
cu.getPackage()=this |
cu.getNumberOfLines())
}
It may appear surprising that we do not use
this.getLocation().getNumberOfLines()
(as that is the way other elements obtain the
number of lines). If you try to write that in
.QL, you will get a type error, because getLocation
does not return a result on packages: a package
does not have a source location, after all. Hence
the need to sum the size of all compilation units
in a package. The .QL typechecker detects such
cases, thus preventing you from writing queries
that are guaranteed to have no results.
References
LocMetrics.
Alternative tools for counting lines of code
2006.
|