我正在尝试编写自己的声纳规则,但我很难弄清楚如何设置这些规则的范围。
假设我有一个Foo
超类,我想检查每个子类的构造函数和一些方法:
public class SubFoo extends Foo {
private boolean ok;
private boolean evaluate;
private Whatever thing;
/** Compliant: constructor with id argument. */
public SubFoo(Long id) {
super(id);
}
/** Not compliant: no id */
public SubFoo(Whathever thing) {
this.thing = thing;
}
/** Compliant: annotated boolean accessor starts with 'is'. */
@MyAnnotation
public boolean isOk() {
return ok;
}
/** Not compliant: annotated boolean accessor doesn't start with 'is'. */
@MyAnnotation
public boolean hasOk() {
return ok;
}
/** Compliant: not annotated boolean accessor. */
public boolean canEvaluate() {
return evaluate;
}
}
Kind.CONSTRUCTOR
和Kind.METHOD
是否足以作为这些规则的访问节点?我在考虑在visitNode
中进行类型检查的基类,但我想知道是否有其他推荐的方法来实现这一点。
提前致谢。