Getting the PsiIdentifier (declaration) from a PsiReference (usage)
Answered
Hi,
Is it possible to get the declaration element from a usage element?
Similar to getting the usages of the element by using the ReferencesSearch.search method, but the other way around.
Thanks,
Jared
Please sign in to leave a comment.
PsiReference#resolve normally returns the declaration element
So we managed to find a method to get the declaration. We noticed that when we used an action to get the element, it would always return the declaration. So we dug into the code and found a method called findTargetElement.
This code snippet will get the declaration from any element from it's offset.
Hope this helps other people!