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

在sonarqube中,关于文档方面的度量有如下方面:java


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


Absolute number of comment lines. This metric is calculated differently for.net

each programming language.code

For instance, in Java, all Javadocs (class, method, property) plus all singleip

or multicomment lines and all commented-out code are counted as commentci

lines. Other comments, such as empty comment lines and headerrem

comments, aren’t counted.文档

 也就是说,comment lines包括全部的类,方法,属性上的注释,包括单行或者多行的,get

以及注释调的代码行,而空的注释行和头文件注释,是不算的it


  注释的密度(Density of

Comment Lines))

   

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


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%

相关文章
相关标签/搜索