I'm developing a Intellij Idea plugin,I want to get all fields info of a class.But I meet with difficulties which I can not get generic type of PsiField. Such as:
private String[] stringsArr;
private List<String> stringList;
private List<BeanLog> beanLogList;
How to get the PsiClass of 'BeanLog' from PsiField ?
field.getType()
returns PsiClassType List<BeanLog>
. Its fieldType.getParameters()[0]
will be PsiClassType BeanLog
. If you want to extract a collection component type in a generic way (not only from List
), then you can use PsiUtil.extractIterableTypeParameter(fieldType, false)
. To get PsiClass
from PsiClassType
, you can use type.resolve()
or PsiUtil.resolveClassInClassTypeOnly
.
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