问题
There is the way to exclude getter and setters from sonar report. Suppose I have 2 "getters":
public int getId(){
return this.id;
}
public int getComplexId(){
int result = 0;
// some complex calculation there
return result;
}
It is possible to exclude getId() and include getComplexId() simultaneously? Can Sonar analyze simple return this.id from complex code?
回答1:
You can use NOPMD comment to avoid Sonar analysis.
public int getId(){ // NOPMD
return this.id;
}
public int getComplexId(){
int result = 0;
// some complex calculation there
return result;
}
Also you can use //NOSONAR or //CHECKSTYLE:OFF comment. More info in http://www.sonarqube.org/sonar-1-12-in-screenshots/
回答2:
@Cherry, out of the box SonarQube already behaves as expected : the first method is considered as a getter and not the second one as this method contains some logic.
来源:https://stackoverflow.com/questions/18587828/how-exclude-simple-getter-and-setter-from-sonar