在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
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%