簡體   English   中英

如何從聲納中排除簡單的吸氣劑和吸氣劑?

[英]How exclude simple getter and setter from sonar?

有一種方法可以從聲納報告中排除吸氣劑和吸氣劑。 假設我有兩個“ getters”:

public int getId(){
    return this.id;
}

public int getComplexId(){
    int result = 0;
    // some complex calculation there
    return result;
}

是否可以同時排除 getId()和包含 getComplexId()? Sonar可以分析簡單代碼從復雜代碼返回this.id嗎?

您可以使用NOPMD注釋來避免進行聲納分析。

public int getId(){ // NOPMD
    return this.id;
}

public int getComplexId(){ 
    int result = 0;
    // some complex calculation there
    return result;
}

您也可以使用// NOSONAR或// CHECKSTYLE:OFF注釋。 有關更多信息, 請訪問http://www.sonarqube.org/sonar-1-12-in-screenshots/

@Cherry,開箱即用SonarQube已經表現出預期的效果:第一種方法被認為是一種吸氣劑,而不是第二種,因為該方法包含一些邏輯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM