PsiReferenceContributor for existing language (JAVA)

I am trying to implement a ReferenceContributor for my Java project but for some reason the only PsiElements I receive in `getReferencesByElement` in my provider are comments - I am not getting anything else.

here is my contributor

public class MyReferenceContributor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferenceRegistrar) {
psiReferenceRegistrar.registerReferenceProvider(
PlatformPatterns.psiElement()
,
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {

System.out.println("Received node: " + psiElement.getText());
return new PsiReference[0];
}
});
}
}

and here is what my plugin.xml looks like:

<depends>com.intellij.modules.lang</depends>

<extensions defaultExtensionNs="com.intellij">
<psi.referenceContributor implementation="com.trickyandroid.myplugin.MyReferenceContributor"/>
</extensions>

I tried to pass different PsiElemet types into `psiElement()` method, but no luck - if I specify anything other than PsiComment - I stop receiving nodes completely.. :(

 

Any help is much appreciated!

2 comments
Official comment

Only elements which support pluggable reference contributors will query them. For Java, it's only comments and string literals.

Hi Pavel,

One small advice is to use PsiViewer plugin to help you identify elements tree. Also you can check any other PsiReferenceContributor usages for samples(for ex. PropertiesReferenceContributor).

Best Regards,

Artem

0

Please sign in to leave a comment.