public static void doRenameGenericNamedElement(@NotNull PsiElement namedElement,
                                                 String newName,
                                                 UsageInfo[] usages,
                                                 @Nullable RefactoringElementListener listener) {
    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 != null)
          renameReference(namedElement, newName, ref);
      }
    }
    if (listener != null) {
      listener.elementRenamed(namedElement);
    }
  }
public static void doRenameGenericNamedElement(@NotNull PsiElement namedElement,
                                                 String newName,
                                                 UsageInfo[] usages,
                                                 @Nullable RefactoringElementListener listener)