how can I add reference to PsiMethod or find usages?


Hi there,

I am developing a plugin for a JSON-like DSL

       "componentName": "AutoTask",
       "id": "node_ockn610kx9m",
       "docId": "doclr917eni",
       "props": {
         "name": "sendEmail",
         "type": "spring-bean",
         "bean": "org.example.action.Action3",
         "method": "execute",
         "enums": []

as the code snippet showing, there is an method name ‘execute’ in the DSL which is located in the class Action3, here is the code of class Action3,

public class Action3 {
    public String execute(String arg) {"param of "+ this.getClass().getName() +" is "+ arg);
        return this.getClass().getName();

now, I want the DSL file name  displayed in the usage list of this method when I press Ctrl+Click on the method name and also when I ctrl+click in the DSL, I can navigate to the java file.

I tried to register ReferenceProvider in the PsiReferenceContributor for Java language:

  PsiElementPattern.Capture<PsiMethod> pattern = PlatformPatterns.psiElement(PsiMethod.class);
  registrar.registerReferenceProvider(pattern, provider);

but it the provider does not called.

Then, I tried to configure the PsiReferenceContributor for my custom language,

<psi.referenceContributor language="BPM"

but the PsiReferenceContributor does not even initialized at all.

please help, thanks.



References are resolved from the occurrence to the definition, so in your case, you should register them for your language, not Java.

Also, please make sure you implemented your elements according to the information from PsiReferenceContributor's Javadoc:

Note that, if you're implementing a custom language, it won't by default support references registered through PsiReferenceContributor. If you want to support that, you need to call com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry.getReferencesFromProviders(PsiElement) from your implementation of PsiElement.getReferences().


Thanks for your big help!

I modified the code as your suggestion, I can navigate to the java code from my JSON-LIKE DSL ;)


Please sign in to leave a comment.