PsiElement () { final PsiFile currentFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument()); if (currentFile == myElementToRename.getContainingFile()){ return super.getNameIdentifier(); } if (currentFile != null) { int offset = myEditor.getCaretModel().getOffset(); offset = TargetElementUtil.adjustOffset(currentFile, myEditor.getDocument(), offset); final PsiElement elementAt = currentFile.findElementAt(offset); if (elementAt != null) { final PsiElement referenceExpression = elementAt.getParent(); if (referenceExpression != null) { final PsiReference reference = referenceExpression.getReference(); if (reference != null && reference.resolve() == myElementToRename) { return elementAt; } } } return null; } return null; }