Problems to add PsiReferenceContributor
Hallo,
I'm trying to create a custom language. I now wanted to create a ReferenceContributor.
This is the code of the ReferenceContributor:
public class SOLReferenceContributor extends PsiReferenceContributor { @Override public void registerReferenceProviders(PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(PlatformPatterns.psiElement(SOLFeatureValue.class), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { PsiLiteralExpression literalExpression = (PsiLiteralExpression)element; String text = (String)literalExpression.getValue(); if (text != null && text.startsWith("ref:")) { return new PsiReference[] {new SOLReference(element, new TextRange(8, text.length() + 1))}; } return new PsiReference[0]; } }); } }
I added an extension point in plugin.xml:
<psi.referenceContributor implementation="com.sol.SOLReferenceContributor"/>
I set a breakpoint in the registerReferenceProviders-Method. However when I debug the plugin it never stops so I assume the contributor is not registered correctly. Thanks for any help.
Please sign in to leave a comment.
Your reference contributor is from SOLFeatureValue.class. The Javadoc for PsiReferenceContributor states:
Are you doing that in getReferences() in SOLFeatureValue?
Thank you for the help. Now the registerReferenceProviders-Method is executed. I added the following snippet to SOLFeatureValueImpl:
There remain problems. However I can go on now thank you.
No problem. Don't forget to also add the reference from the SOLFeatureValue itself, if any. See for example com.intellij.psi.impl.source.xml.XmlDoctypeImpl#getReferences.
Hallo,
I now changed the ReferenceContributor to the following:
Because FEATURE_VALUE_NAME is a leaf I no longer have a class implementing PsiElement, So I can't override getReference. Now the registerReferenceProviders is not called anymore.
Here is a snippet of my language:
PROPERTY_NAME {
## the FEATURE_VALUE_DEFINITION element
AN_IDENTIFIER {
en {
a term
another term
one more term
}
}
## the FEATURE_VALUE_NAME element
AN_IDENTIFIER
}
The second AN_IDENTIFER is the FEATURE_VALUE_NAME that should reference the FEATURE_VALUE_DEFINITION.
Thanks for any help,
regards Sebastian
Ah! I think this should be added to the sdk doc. This post has saved my life.
I have debugged this issue for more than 1 week. This post has saved my life, too.