How to get kotlin class from UParameter type?

Answered

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?

2 comments
Comment actions Permalink

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

0
Comment actions Permalink

`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

Please sign in to leave a comment.