Standard Analyses

SemmleCode Professional comes with a wide range of pre-packaged analyses, from architectural properties and metrics, to statement-level checks for likely bugs and violations of best practice.


Comment Ratio per Package in Each Project

This query shows the amount of documentation (comments) per package, grouped by project. Red boxes represent packages with little documentation, green boxes represent packages with a lot of documentation. Library packages are not shown.

How to Interpret the Query Results

Running this query on the Alfresco content management system yields the following result, displayed as a tree map:

Every individual box represents a package, with packages within the same project grouped together. The size of a box represents the code size of the corresponding package, and its colour the comment ratio. For a package P with l lines of code and c lines of comments, the ratio computed is c/(l+c+1), i.e. the ratio of comment lines to overall lines. Red represents a low comment ratio, green a high ratio.

Both number of lines of code and comment ratio are displayed on mouse-over:

For example, the package org.alfresco.repo.security.permissions.impl.acegi has 2559 lines of code, and its comment ratio is about 0.09, i.e. roughly 9% of its non-blank lines are comments.

How to Address the Query Results

Carefully examine packages showing up as large, red boxes to determine whether they need additional documentation.

Source Code
import default

from JavaProject project, Package p, int code, int comment
where p = project.getASourcePackage() and 
      code = p.getMetrics().getNumberOfLinesOfCode() and 
      comment = p.getMetrics().getNumberOfCommentLines()
select project as Project, 
       p as Package,
       code as LinesOfCode,
       ((float)comment) / (comment+code+1) as CommentRatio
order by LinesOfCode desc
References