我刚做了一个测试,发现我误解了文档.它为java.lang.Object和接口返回类型为NONE的NoType,而不是隐式扩展Object的内容.傻我.我不需要检查,因为较早的检查是否注释元素是严格意义上的类(不是枚举或接口),如果是,则返回.换句话说,检查规范名称是java.lang.Object还是使用Types.isSameType应该可以解决问题.
对不起,伙计们.我决定不删除,因为其他人可能会带着同样的问题到达.如果您认为合适,请随意投票删除.
编辑:这是我最终去的地方……
boolean superTypeValid = true;
final TypeMirror parent = el.getSuperClass();
if(!parent.getKind().equals(TypeKind.DECLARED)) {
messager.printMessage(Kind.ERROR,"May only inherit from a class; not enums,annotations or other declared kinds.",annotatedElement,mirror);
superTypeValid = false;
} else {
final DeclaredType parentType = (DeclaredType)parent;
final Element parentEl = parentType.asElement();
if(!parentEl.getKind().equals(ElementKind.CLASS)) {
messager.printMessage(Kind.ERROR,mirror);
superTypeValid = false;
}
}
...
if(superTypeValid) {
if(typeUtils.isSameType(parent,elUtils.getTypeElement("java.lang.Object").asType())) {
messager.printMessage(Kind.ERROR,"Inherit must not be set to true if the class doesn't extend.",mirror);
valid = false;
} else {
...
}
}
如果其中一些错误消息看起来很奇怪,那是因为我留下了一些项目特定的东西.