如何定义Checkstyle验证以确保所有带有特定注释的方法出现在java类的构造函数之前?
验证应接受以下内容:
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 available out of the box可以配置为检查此或 custom Check implemenation需要实现这个吗?
最佳答案
不,没有这样的 Checkstyle Check 开箱即用。
为此需要实现自定义 Checkstyle Check,并且必须通过将其添加到验证配置 xml 中来触发此自定义验证。
关于java - Checkstyle - 带注释的方法必须位于构造函数之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58555128/