RenameData (SmartPsiElementPointer<? extends PsiNameIdentifierOwner> pointer) { PsiNameIdentifierOwner owner = pointer.getElement(); if (owner == null) return null; PsiFile psiFile = owner.getContainingFile(); Collection<PsiReference> references = ReferencesSearch.search(owner, new LocalSearchScope(psiFile)).findAll(); PsiElement scope = PsiTreeUtil.findCommonParent(ContainerUtil.map(references, ref -> ref.getElement())); if (scope != null) { scope = PsiTreeUtil.findCommonParent(scope, owner); } if (scope == null) { scope = psiFile; } return new RenameData(references, scope, owner); }