I just did a test and realized that I misinterpreted the documentation. It returns a NoType with a NONE view for java.lang.Object and interfaces, and not for something implicitly extending Object. I was a fool. I donβt need to check, as it previously checks to see if the annotated element is a class in the strict sense (not an enumeration or an interface) and will return if that is the case. In other words, checking if the canonical name is java.lang.Object or maybe using Types.isSameType
should do the trick.
Sorry people. I decided not to delete, as others may come up with the same question. Feel free to vote if you think it is appropriate.
EDIT: Here I ended up going ...
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, "May only inherit from a class; not enums, annotations or other declared kinds.", annotatedElement, 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.", annotatedElement, mirror); valid = false; } else { ... } }
If some of these error messages seem strange, this is due to the fact that I left some project-specific materials.
source share