public static void doRenameGenericNamedElement( @NotNull PsiElement namedElement, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException { PsiWritableMetaData writableMetaData = null; if (namedElement instanceof PsiMetaOwner) { final PsiMetaData metaData = ((PsiMetaOwner) namedElement).getMetaData(); if (metaData instanceof PsiWritableMetaData) { writableMetaData = (PsiWritableMetaData) metaData; } } if (writableMetaData == null && !(namedElement instanceof PsiNamedElement)) { LOG.error("Unknown element type:" + namedElement); } boolean hasBindables = false; for (UsageInfo usage : usages) { if (!(usage.getReference() instanceof BindablePsiReference)) { rename(usage, newName); } else { hasBindables = true; } } if (writableMetaData != null) { writableMetaData.setName(newName); } else { PsiElement namedElementAfterRename = ((PsiNamedElement) namedElement).setName(newName); if (namedElementAfterRename != null) namedElement = namedElementAfterRename; } if (hasBindables) { for (UsageInfo usage : usages) { final PsiReference ref = usage.getReference(); if (ref instanceof BindablePsiReference) { try { ref.bindToElement(namedElement); } catch (IncorrectOperationException e) { // fall back to old scheme ref.handleElementRename(newName); } } } } if (listener != null) { listener.elementRenamed(namedElement); } }
public static void rename(UsageInfo info, String newName) throws IncorrectOperationException { if (info.getElement() == null) return; PsiReference ref = info.getReference(); if (ref == null) return; ref.handleElementRename(newName); }