The purpose of PsiReferenceContributor

Hi,

I do have a quick question about the PsiReferenceContributor's purpose.
Imagine I have an annotation and I want to establish a reference relationship like the following:

@Annotation("foo.Bar")
void foo();

...

class Bar {}


I do get the behavior of a GotoDeclarationHandler for the literal "foo.Bar" but what baffels me is:

  • If the reference is invalid, no error is shown, contrary to what I read elsewhere
  • Bar is marked as unused although the reference exists


The question is if those components in question have to be developed as individual extensions.
In that case, I don't understand why the GotoDeclarationHandler / completion via variants
part is already handled via reference contributor.

Did I simply implement the PsiReferenceContributor wrong or is this expected?


Best,
Joa

2 comments
Comment actions Permalink

Hi Joa,

For the first question: what does the isSoft() method of your reference return? The reference won't be highlighted if isSoft() returns true.
For the second one: you probably need to implement a searcher (an extension for the referencesSearch extension point) so that your "foo.Bar" string will be found as a usage of the Bar class.

0
Comment actions Permalink

Hi Dmitry,

thanks for the reply. The isSoft() method returns false. Attached is a screenshot of how it looks.
Also: if I type @Delegate("ErrorsErrorsErrors") I see that the class (which is in the same Editor) is highlighted.

Source code is also available at https://github.com/defrac/defrac-plugin-intellij/tree/master/src/defrac/intellij/psi

I will implement the searcher as suggested. Thanks!


Best,
Joa



Attachment(s):
linkage.png
0

Please sign in to leave a comment.