private static void performRefactoring(@NotNull PsiMember constructorOrClass, @NotNull PsiClass targetClass,
                                         @NotNull UsageData usages, @NotNull ModPsiUpdater updater) {
    Project project = constructorOrClass.getProject();
    PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
    PsiClass wrContainingClass = updater.getWritable(
      constructorOrClass instanceof PsiClass cls ? cls : Objects.requireNonNull(constructorOrClass.getContainingClass()));
    PsiReferenceExpression classReferenceExpression = factory.createReferenceExpression(targetClass);
    List<String> names = suggestNames(targetClass, Objects.requireNonNull(wrContainingClass.getName()));
    String factoryName = names.get(0);
    PsiReferenceExpression qualifiedMethodReference = (PsiReferenceExpression)factory.createExpressionFromText("A." + factoryName, null);
    PsiMethod constructor = ObjectUtils.tryCast(constructorOrClass, PsiMethod.class);

    PsiClass wrClass = updater.getWritable(targetClass);
    PsiMethod wrConstructor = updater.getWritable(constructor);
    List<PsiNewExpression> writableUsages = ContainerUtil.map(usages.newUsages, updater::getWritable);

    PsiMethod factoryMethod = createFactoryMethod(project, wrContainingClass, constructor, factoryName);
    factoryMethod = (PsiMethod)wrClass.add(factoryMethod);

    if (constructor == null) {
      wrConstructor = (PsiMethod)wrContainingClass.add(factory.createConstructor());
    }
    
    PsiUtil.setModifierProperty(wrConstructor, getMinimalAccessLevel(constructorOrClass, usages.otherUsages), true);

    for (PsiNewExpression newExpression : writableUsages) {
      var factoryCall = (PsiMethodCallExpression)factory.createExpressionFromText(factoryName + "()", newExpression);
      CommentTracker ct = new CommentTracker();
      
      factoryCall.getArgumentList().replace(Objects.requireNonNull(ct.markUnchanged(newExpression.getArgumentList())));

      PsiExpression newQualifier = ct.markUnchanged(newExpression.getQualifier());

      PsiReferenceExpression factoryCallRef = factoryCall.getMethodExpression();
      PsiElement resolvedFactoryMethod = factoryCallRef.resolve();
      if (resolvedFactoryMethod != factoryMethod || newQualifier != null) {
        factoryCallRef = (PsiReferenceExpression)factoryCallRef.replace(qualifiedMethodReference);
        PsiElement qualifier = newQualifier == null ? classReferenceExpression : newQualifier;
        Objects.requireNonNull(factoryCallRef.getQualifierExpression()).replace(qualifier);
      }

      ct.replaceAndRestoreComments(newExpression, factoryCall);
    }
    updater.rename(factoryMethod, names);
  }
private static void performRefactoring(@NotNull PsiMember constructorOrClass, @NotNull PsiClass targetClass,
                                         @NotNull UsageData usages, @NotNull ModPsiUpdater updater)