I want to check if any of annotated classes' ancestors is actually android.support.v4.app.Fragment
.
Currently I wrote a recursive method to do that.
I wonder if any better way of doing this?
The main purpose is to restrain my annotation to be added to any classes.
I also use squareup.javapoet
.
private boolean isSubClass(TypeElement typeElement, ClassName superClassName) {
TypeElement superTypeElement = (TypeElement) ((DeclaredType) typeElement.getSuperclass()).asElement();
if (superTypeElement.toString().equals(Object.class.getName())) {
return false;
} else if (superTypeElement.toString().equals(superClassName.reflectionName())) {
return true;
}
return isSubClass(superTypeElement, superClassName);
}