我正在玩Java(javax)注解处理。
假设我有一个注释的方法:
@Target(ElementType.METHOD)
public @interface MethodAnnotation { }
现在我想使用带注释的方法来处理从类型中覆盖的所有方法:
interface MyInterface() {
@MethodAnnotation
void f()
}
class MyClass implements MyInterface {
override void f() { } //
}
@Inherited元注释在这里似乎不合适:
Note that this meta-annotation type has no effect if the annotated type is used to annotate anything other than a class.
另外,是否可以处理一个未被子类覆盖的继承类方法?喜欢这个:
class MyClass {
@MethodAnnotation
void f() { }
}
class MySubClass extends MyClass { } //
// or at least to find out that it doesn't
// override the method
如何在AbstractProcessor中访问某种方法的覆盖方法?
我想,为了实现这一点,我需要找到eclosing类的子类,但是我还没有找到一个方法来做到这一点。
UPD:我想可以使用RoundEnvironment.getRootElements(),但仍然没有找到正确的方法。