Checkstyle 冗长的解决方案?
在包含许多 getter 和 setter 的代码示例中,存在以下 CHECKSTYLE 表示法:
/* CHECKSTYLE:OFF */
public void setDisplayName(final String displayName) {
this.displayName = displayName;
}
/* CHECKSTYLE:ON */
/* CHECKSTYLE:OFF */
public String getDisplayName() {
return displayName;
}
/* CHECKSTYLE:ON */
我发现这会使代码变得混乱,使其更难以阅读。
是否有更简单的方法来添加这些符号,以便它们不会像本示例中那样出现在每个方法定义的开头和结尾?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过更新 Javadoc 方法 Checkstyle 配置,以便在 getter 和 setter 上不需要 javadoc使用allowMissingPropertyJavadoc 属性?
根据您是否只是过滤 getter 和 setter javadoc 还是更复杂的东西,这可能是一个更好、更干净的解决方案。
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.
您引用的符号称为 SuppressionCommentFilter,它使用成对的注释来抑制审核事件。您可以将它们维护在单独的文件中,而不是在代码中进行这些抑制,如以下链接中所述: SuppressionFilter
但是,根据您的具体情况,有理由在代码中维护它:
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: