public static void solveLocalNameConflicts(final PsiElement scope, 
                                             final PsiElement placeToInsert,
                                             final PsiElement renameScope) {
    if (scope instanceof PsiVariable || scope instanceof PsiClass) {
      PsiNameIdentifierOwner named = (PsiNameIdentifierOwner)scope;
      String name = named.getName();
      PsiElement identifier = named.getNameIdentifier();
      if (name != null && identifier != null) {
        String oldName = name;
        Project project = scope.getProject();
        final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
        BiFunction<PsiElement, String, String> suggester =
          scope instanceof PsiVariable ?
          (place, curName) -> codeStyleManager.suggestUniqueVariableName(curName, place, true) :
          (place, curName) -> suggestClassName(place, curName);
        while (true) {
          String newName = suggester.apply(placeToInsert, name);
          if (newName.equals(name)) break;
          name = newName;
          newName = suggester.apply(named, name);
          if (newName.equals(name)) break;
          name = newName;
        }
        if (!name.equals(oldName)) {
          for (PsiReference reference : ReferencesSearch.search(named, new LocalSearchScope(renameScope), true)) {
            reference.handleElementRename(name);
          }
          PsiElementFactory factory = JavaPsiFacade.getElementFactory(scope.getProject());
          if (named instanceof PsiClass cls) {
            for (PsiMethod constructor : cls.getConstructors()) {
              if (!(constructor instanceof SyntheticElement) && constructor.getName().equals(oldName)) {
                Objects.requireNonNull(constructor.getNameIdentifier()).replace(factory.createIdentifier(name));
              }
            }
          }
          Objects.requireNonNull(named.getNameIdentifier()).replace(factory.createIdentifier(name));
        }
      }
    }

    PsiElement[] children = scope.getChildren();
    for (PsiElement child : children) {
      solveLocalNameConflicts(child, placeToInsert, renameScope);
    }
  }
public static void solveLocalNameConflicts(final PsiElement scope, 
                                             final PsiElement placeToInsert,
                                             final PsiElement renameScope)