void (Collection<? super PsiReference> refs) { PsiFile myEditorFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument()); // Note, that myEditorFile can be different from myElement.getContainingFile() e.g. in injections: myElement declaration in one // file / usage in another ! PsiReference reference = (myEditorFile != null ? myEditorFile : myElementToRename.getContainingFile()) .findReferenceAt(myEditor.getCaretModel().getOffset()); if (reference instanceof PsiMultiReference) { PsiReference[] references = ((PsiMultiReference)reference).getReferences(); for (PsiReference ref : references) { addReferenceIfNeeded(refs, ref); } } else { addReferenceIfNeeded(refs, reference); } }