如何定义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可以配置为检查此功能,或者需要自定义 Check 实现来实现此功能?
摇曳的蔷薇
相关分类