PsiElementFinder analogue for Kotlin
Answered
What would be the analogue of PsiElementFinder for Kotlin files?
As per documentation,
PsiElementFinder allows extending the mechanism of locating classes and packages by full-qualified name ... to be picked up by JavaPsiFacade.
The class I want to resolve by FQN is KtClass. PsiElementFinder method signature wouldn't suit since KtClass is not instance of PsiClass. Any suggestions what would be similar mechanism that will allow returning KtClasses?
public abstract PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope);
Please sign in to leave a comment.
If you want to lookup class written in Kotlin via FQN, just use JavaPsiFacade.findClass().
Oh, no. I’m asking because I implemented custom PsiElementFinder to locate classes out of project scope by full-qualified name.
It worked well, but now we’re adding Kotlin support. I want to return Kotlin class instead of Java class, but PsiElementFinder allows only returning PsiClass (not KtClass).
What could I use to implement same mechanism but be able to return KtClass?
You can use Kotlin directly by `org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex`.
Example:
Thank you! I tried using "light class wrappers" approach.
(Side note: `psiClass = ktClass.toLightClass()` returns null, but this one work
---
Now, that PsiElementFinder successfully returns PsiClass, I see symbols in Java files are recognized (🎉), but in Kotlin files are not (😞).
In logs, I noticed this error, which happens only for kotlin file
What could I do for PsiElementFinder to support symbols recognition in Kotlin files, same way as it works for Java files?
---
Full stack trace: