Resolving to a java class name from a custom language

Answered

Hello,

I'm writing a custom language which can have references to Java class names inside of strings. I'm hoping to get code completion of the class names for whatever classpath is available in the current project, sort of like XML does:

After looking through the source code, it seems to me that this is done using the JavaXmlClassListReferenceContributor.java class, registered as a reference contributor in the java-i18n plugin.xml file. But I cannot figure out how to a add a similar reference contributor to my language, so that I could get java class code completion, like this:

Is there a way to leverage this functionality?

0
3 comments

Hi,

You should implement a similar reference contributor but for your language, instead of XML. It should contribute Java class references in your language string literal elements.

More about references: https://plugins.jetbrains.com/docs/intellij/references-and-resolve.html

0

I tried to create a reference contributor, but I don't seem to have access to com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassListReferenceProvider on my classpath in the plugin code. Is there a way for me to contribute java class references using an out-of-the-box solution like this? Maybe there's a dependency I can add to my gradle build to put java-impl classes on my classpath?

I'd rather not have to implement retrieving all the class references from scratch…

0

You most likely need to add a dependency on the Java plugin. See https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html

Please also note that JavaClassListReferenceProvider is not a part of the open API, and may be changed in the future without preserving backward compatibility.

0

Please sign in to leave a comment.