ReferencesSearch & PsiPolyVariantReferences

It seems that PsiPolyVariantReferences are not found and returned by Is this correct? If yes, what's the recommended way to find
such references or is there a better way to implement such "multi-declaration" references?

The better way would indeed be better because currently a PsiPolyVariantReference doesn't
play well together with the Rename refactoring either: The refactoring cannot be triggered
on such a reference, and when triggered on a declaration, the references pointing to it
are not renamed at all :(


Comment actions Permalink

Sorry for the false alarm, it works just fine when PsiReference.isReferenceTo() is
correctly implemented.

In fact, it might be a good idea to correctly implement isReferenceTo() in
com.intellij.psi.PsiReferenceBase.Poly with something like

public boolean isReferenceTo(PsiElement element) {
final ResolveResult[] results = multiResolve(false);
for (ResolveResult result : results) {
if (element.getManager().areElementsEquivalent(result.getElement(), element)) {
return true;
return false;


Comment actions Permalink

hello Sascha
I'm aware this thread has been dead for quite a while but I'm still going to give it a shot.
Is your 'isReferenceTo' method implementation (I see it has been included into IDEA's codebase) supposed to play well with the standard java method rename refactoring ?
I'm using a custom reference provider to inject psi references into ELStringLiteral elements in a facelet-enabled XHTML file and if I'm correct, rename refactoring should just work since both 'find usages' and 'go to declaration' are handled properly.
But when I press shift + F6 on a target Java method, change its name and press Enter to save the modified value - a PsiInvalidElementAccessException occurs. It is triggered by 'isReferenceTo' method call - specifically by this line of code :

element.getManager().areElementsEquivalent(result.getElement(), element)

Element equivalence cannnot be verified since result.getElement() (element previously pointed at by the PolyVariantReference in question) is already invalid and result.getElement().getContainingFile() throws the exception I mentioned above.
Of course when I override your implementation of 'isReferenceTo' method with one which compares only method name and enclosing class FQN (simple string comparison) - rename works but such implementation doesn't take parameter list comparison into account and seems not  'clean' at best.
I'm new to IDEA plugin development but it seems that when rename refactoring is triggered, IDEA should look for backward references (using 'isReferenceTo' method) when the PSI tree has not been altered yet ('beforeChildReplacement' of a PsiTreeChangeListener ?) and the target PsiElement is still valid.
Do you think I should file a JIRA request for a possible bug ?
Or maybe you can think of a possible workaround ?
Hope this post reaches its' destination :)

Please sign in to leave a comment.