I have a class:
public class StartPagePresenter extends AbstractPresenter<String> {
...
}
Using Java Annotation Processing I got the TypeElement
of the class:
TypeElement startPagePresenterType = // get the TypeElement of StartPagePresenter
Now I need to get the super class which is done with:
startPagePresenterType.getSuperclass();
Then I tried to check if the super class has the correct type with:
if ( !startPagePresenterType.getSuperclass().toString().equals(
AbstractPresenter.class.getCanonicalName()) ) {
...
}
Here is the problem: AbstractPresenter.class.getCanonicalName()
leads to:
core.mvp.AbstractPresenter
and startPagePresenterType.getSuperclass().toString()
leads to:
core.mvp.AbstractPresenter<java.lang.String>
When you compare these Strings they are never equal although the super classes are the same.
How can I get the super class from startPagePresenterType.getSuperclass()
without the generic block?
I found the answer:
TypeMirror superClassTypeMirror = startPagePresenterType.getSuperclass();
TypeElement superClassTypeElement =
(TypeElement)((DeclaredType)superClassTypeMirror).asElement();
That's it! superClassTypeElement
then is the TypeElement
of the super class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With