[英]Checkstyle - Method with annotation must be before constructor
如何定义Checkstyle验证以确保所有带有特定注释的方法都出现在 java class 的构造函数之前?
验证应接受以下内容:
class User {
@Injected // -> [OK]: method with @Injected is before the constructor.
public void setName(String name) {
this.name = name;
}
public User(String name) {
this.name = name;
}
}
以下应该导致 Checkstyle 违规:
class User {
public User(String name) {
this.name = name;
}
@Injected // -> [NOK]: method should be before the constructor
public void setName(String name) {
this.name = name;
}
}
是否有开箱即用的 Checkstyle Check可以配置来检查这个,或者需要一个自定义的 Check 实现来实现这个?
不,没有开箱即用的 Checkstyle Check。
为此需要实现自定义 Checkstyle Check,并且必须通过将其添加到验证配置 xml 中来触发此自定义验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.