private static @NlsSafe @NotNull String generateUniqueName(@NotNull String defaultName, @NotNull String prefix, @NotNull String suffix,
                                                             @NotNull String beforeNumber, @NotNull String afterNumber,
                                                             @NotNull Condition<? super String> validator, int startingNumber) {
    String defaultFullName = (prefix + defaultName + suffix).trim();
    if (validator.value(defaultFullName)) {
      return defaultFullName;
    }

    String baseName = defaultName;
    Pattern pattern = Pattern.compile("(.+?)" + Pattern.quote(beforeNumber) + "(\\d{1,9})");
    java.util.regex.Matcher matcher = pattern.matcher(baseName);
    int index = startingNumber;
    if (matcher.matches()) {
      baseName = matcher.group(1);
      index = Integer.parseInt(matcher.group(2)) + 1;
    }
    while (true) {
      String name = (prefix + baseName + beforeNumber + (index++) + afterNumber + suffix).trim();
      if (validator.value(name)) {
        return name;
      }
    }
  }
private static @NlsSafe @NotNull String generateUniqueName(@NotNull String defaultName, @NotNull String prefix, @NotNull String suffix,
                                                             @NotNull String beforeNumber, @NotNull String afterNumber,
                                                             @NotNull Condition<? super String> validator, int startingNumber)