How to get kotlin class from UParameter type?

已回答

I have some code, that searches for usages of some method first parameter type. The code

(uMethod.uastParameters[0] as UVariable).type

returns `PsiClassType`, that resolves to some `ClsClassImpl`. The last is compiled java class, but actually, the type is kotlin class from the same file and it is not compiled. `(uMethod.uastParameters[0] as UVariable).typeReference` returns null. Is it possible to get KtClassOrObject from UVariable type?

0

Resolved with `com.intellij.psi.PsiElement#getNavigationElement`

0

`PsiClassType` in case of Kotlin will resolve to `KtLightDeclaration<KtClassOrObject, PsiClass>` from which you can take `kotlinOrigin` which will be your `KtClassOrObject`.

 

But actually it is little bit strange to have to know to the language of the type you are resolving to

 

0

请先登录再写评论。