Reference/resolve classes/methods to/from Java Follow
When developing custom JVM language support, what is the proper way to register new Java classes and methods? For instance, in Frege, we might have a file like this -
module foo.bar.Baz where
data Quux a = Quux a
spam = "eggs"
The module declaration introduces the class `foo.bar.Baz`, the class `foo.bar.Baz.TQuux`, (yes TQuux, not Quux) and the static method `foo.bar.Baz.spam`.
I can obtain the elements via the Psi tree; however, it's not clear how to tell IntelliJ about these new classes and methods so they can be used from Java code without it reporting the error "Cannot resolve symbol".
Please sign in to leave a comment.
To make your Frege declarations visible from Java sources located in the same project, you can extend com.intellij.psi.search.PsiShortNamesCache (EP "java.elementFinder") and com.intellij.psi.PsiElementFinder (EP "java.shortNamesCache"). These will make your own PsiClass and PsiMethod available in JavaPsiFacade.
I have been able to get this to work when referencing a class by its FQN or importing it. However, this doesn't seem to work for package-local classes. For instance, if I have a `PsiClass` with an FQN of `foo.Quux`, should it be resolved when used unqualified from a Java class source `foo.Bar`?
Here are two data files which demonstrate a failing test case - Module00003/foo
Here is the failing test case.
I'm guessing that there's just something wrong with my implementation.
For convenience, here are the implementations of the interfaces you mentioned -
It seems that I just needed to override the PsiElementFinder.getClasses(), which was, by default, returning an empty array.
Thank you for your help!