PsiNamedElement () { // todo we can use more specific class, shouldn't we? //Class clazz = myElementToRename != null? myElementToRename.getClass() : PsiNameIdentifierOwner.class; if (myElementToRename != null && myElementToRename.isValid()) { if (Comparing.strEqual(myOldName, myElementToRename.getName())) return myElementToRename; if (myRenameOffset != null) return PsiTreeUtil.findElementOfClassAtRange( myElementToRename.getContainingFile(), myRenameOffset.getStartOffset(), myRenameOffset.getEndOffset(), PsiNameIdentifierOwner.class); } if (myRenameOffset != null) { PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument()); if (psiFile != null) { return PsiTreeUtil.findElementOfClassAtRange(psiFile, myRenameOffset.getStartOffset(), myRenameOffset.getEndOffset(), PsiNameIdentifierOwner.class); } } return myElementToRename; }