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) {
log.info("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"
implementation="com.example.compileflowdesigner.psi.SimpleReferenceContributor"/>
but the PsiReferenceContributor does not even initialized at all.
please help, thanks.
请先登录再写评论。
Hi,
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:
Thanks for your big help!
I modified the code as your suggestion, I can navigate to the java code from my JSON-LIKE DSL ;)