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 {
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferenceRegistrar) {
new PsiReferenceProvider() {
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:


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

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!

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,



Please sign in to leave a comment.