Number of Lines of a Method

The number of lines of a method includes all source code, comments and blank lines.

Long methods are an indication of poor design, and may have to be split up into smaller logical units.

Pre-packaged Query

Query name = "Semmle/Metrics/Methods/Large methods"

Reports methods (in source) that consist of more than 200 lines, in decreasing order of size, as a bar chart. Methods named "< clinit >" are excluded from the report. Also note that constructors are not reported.

from MetricCallable c, int n
where c.fromSource() 
      and 
      n=c.getNumberOfLines() 
      and 
      n > 200
      and
      not(c.hasName("< clinit >"))
      and
      c instanceof Method
select c, n order by n desc

.QL Source of Metric

This metric is defined in the class MetricCallable. It simply reads off the number of lines from the source location of the callable:

   int getNumberOfLines() {
     result = this.getLocation().getNumberOfLines()
   }

References

Streek. Bad Smells in Code: Long Method . University of California at Berkeley, 2006.

Digg!Reddit!Del.icio.us!Facebook!Slashdot!Technorati!StumbleUpon!Ma.gnolia!

Comments
Only registered users can write comments!
 
< Prev   Next >