I am using the Eclipse Checkstyleplugin (v5.5). I want JavaDoc comments on all public methods except getters and setters. I know there is the option “allowMissingPropertyJavadoc” which does exactly what I want. But in some cases it works and in some it does not.
This works, no JavaDoc required on gettes and setters:
public class Test {
private String name;
private int number;
public Test() {
System.out.println("Test");
}
public String getName() {
return this.name;
}
public int getNumber() {
return this.number;
}
public void setName(String name){
this.name = name;
}
public void setNumber(int number) {
this.number = number;
}
}
And this does not, JavaDoc required on setters:
public class Test2 {
private Test test;
public Test2() {
System.out.println("Test2");
this.test = new Test();
this.test.setName("thename");
this.test.setNumber(1337);
}
public String getName() {
return this.test.getName();
}
public int getNumber() {
return this.test.getNumber();
}
public void setName(String name) {
this.test.setName(name);
}
public void setNumber(int number) {
this.test.setNumber(number);
}
}
It seems as if setters without an assignment are not recognized as setters. Is how can I fix this?
That’s because it requires the body to be exactly “this.name = name;”
You can see the exactly line here:
http://checkstyle.hg.sourceforge.net/hgweb/checkstyle/checkstyle/file/a485366ec8c3/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java#l819
Dumb, I know.