Using references in custom languages *to* expression literals

I'm writing a plugin for a custom language. Java code is generated from these files and they contain calls to Spring services which are identified by the Service annotation. So for example a line


would later call a service with the Service annotation value "doSomethingService".

I've successfully added references in my language files to the service's anotation literal expression. I also managed to inject references into the literal expression itself using PsiReferenceContributor. Unfortunately this doesn't work properly as whenever a service is called from multiple files and I search for its usages I first have to select for which reference I want to search usages for. I think the problem is that I have references in both directions (from language files to classes and from classes to language files). But when I disable the PsiReferenceContributor IntelliJ will not recognize that the annotation's literal expression is a reference target for my language files. I can jump from my language file to the service but not back.

So how do I solve this problem? I didn't find any cases where the literal expression marks the definition and something else the reference. All the examples I found are used to inject a reference into the literal expression, not the other way around.

I was able to get it to work properly with references to enum values and to methods, the former simply by implementing PsiReference, the latter by implementing a MethodReferencesSearch.


Thank you.


Update: Shortly after I posted this I tried to see it it works by plugging into the ReferencesSearch and using the class as reference target - and it does! Unfortunately now refactoring is a lot harder as I don't actually want to rename the class but change the literal expression's content.

Please sign in to leave a comment.