Question

In a code sample containing many getters and setters, the following CHECKSTYLE notations exist:

/* CHECKSTYLE:OFF */
public void setDisplayName(final String displayName) {
    this.displayName = displayName;
}
/* CHECKSTYLE:ON */

/* CHECKSTYLE:OFF */
public String getDisplayName() {
    return displayName;
}
/* CHECKSTYLE:ON */

I find that this muddies the code, making it more difficult to read.

Is there a simpler way to add these notations so that they are not at the beginning and end of every method definition as in this example?

Was it helpful?

Solution

The notation you refer to is called a SuppressionCommentFilter which uses pairs of comments to suppress audit events. Instead of having these suppressions in the code you could maintain them in a separate file as is explained in this link: SuppressionFilter

However there are reasons for maintaining it in the code, depending on your circumstance:

When this is a matter of the code in question and not personal preference, the best place to override the policy is in the code itself. Semi-structured comments can be associated with the check. This is sometimes superior to a separate suppressions file, which must be kept up-to-date as the source file is edited.

OTHER TIPS

Have you tried updating your Javadoc method Checkstyle configuration to not require javadoc on getters and setters by using the allowMissingPropertyJavadoc property?

Depending on if you're after just filtering the getter and setter javadoc or something more complicated, this may be a better, cleaner solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top