`

sonarqube笔记之--代码注释行的量度

 
阅读更多
  在sonarqube中,关于文档方面的度量有以下方面:

1 sonarqube中的代码注释行的概念(comment lines):

Absolute number of comment lines. This metric is calculated differently for
each programming language.
For instance, in Java, all Javadocs (class, method, property) plus all single
or multicomment lines and all commented-out code are counted as comment
lines. Other comments, such as empty comment lines and header
comments, aren’t counted.
也就是说,comment lines包括所有的类,方法,属性上的注释,包括单行或者多行的,
以及注释调的代码行,而空的注释行和头文件注释,是不算的

2
  注释的密度(Density of
Comment Lines))
  
Comment Lines / ( Lines of Code + Comment Lines ) * 100 也就是注释的代码行/注释的代码行和总的代码行

3
Public API: 不同语言不同计算方法,其中java中
   Public Classes + Public Methods + Public Properties,就是上面三者上的注释数量,但不包括final static的
4 Public Undocumented API,就是应该在public api上写注释,但没写的数量了;

5 文档API注释密度:(public api-public undocument api)/public api*100
  下面看一个例子:
 
public class InternationalOrder {
private InternationalCustomer customer;
/** Add – remove order line code omitted */
public List<OrderLine> orderlines = new ArrayList<OrderLine>();
/**
* Calculates total amount of an order.
* @return total amount as a BigDecimal number
*/
public BigDecimal getTotal() {
BigDecimal total = BigDecimal.valueOf(0);
for (OrderLine orderLine : orderlines) {
total = total.add(orderLine.getOrderLineTotal());
}
BigDecimal discount = total.multiply(getDiscount());
total = total.subtract(discount);
// Multiply with tax number
BigDecimal tax = total.multiply(getVat());
total = total.add(tax); // total = total.add(tax);
return total; }
private BigDecimal getTax() {
return (BigDecimal.valueOf(customer.getCountry().getVat()));
}
private BigDecimal getDiscount() {
return BigDecimal.valueOf(0.10);
}
}
  
在上面的代码中,代码的注释行为5个; 而public api为2个,因为只有类方法和属性
有注解,但类上面没注解,所以
doucment的密度api为=2/3=66.3%
1
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics