public static <T> Project doGenerateProject(@NotNull String locationString,
                                              @Nullable DirectoryProjectGenerator<T> generator,
                                              @NotNull T settings,
                                              @NotNull OpenProjectTask options) {
    Path location = Paths.get(locationString);
    try {
      Files.createDirectories(location);
    }
    catch (IOException e) {
      LOG.warn(e);
      String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location.toString());
      Messages.showErrorDialog(options.getProjectToClose(), message, ActionsBundle.message("action.NewDirectoryProject.title"));
      return null;
    }

    VirtualFile baseDir = WriteAction.compute(
      () -> LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(location.toString())));
    if (baseDir == null) {
      LOG.error("Couldn't find '" + location + "' in VFS");
      return null;
    }
    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);

    if (baseDir.getChildren().length > 0) {
      String title = ActionsBundle.message("action.NewDirectoryProject.not.empty.dialog.title");
      String message = ActionsBundle.message("action.NewDirectoryProject.not.empty.dialog.text", location.toString());
      String yesText = ActionsBundle.message("action.NewDirectoryProject.not.empty.dialog.create.new");
      String noText = ActionsBundle.message("action.NewDirectoryProject.not.empty.dialog.open.existing");
      int result = Messages.showYesNoDialog(options.getProjectToClose(), message, title, yesText, noText, Messages.getQuestionIcon());
      if (result == Messages.NO) {
        return PlatformProjectOpenProcessor.Companion.doOpenProject(location, OpenProjectTask.build());
      }
    }

    RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getParent());

    if (generator instanceof TemplateProjectDirectoryGenerator) {
      ((TemplateProjectDirectoryGenerator<?>)generator).generateProject(baseDir.getName(), locationString);
    }

    TrustedPaths.getInstance().setProjectPathTrusted(location, true);
    Project project = ProjectManagerEx.getInstanceEx().openProject(location, options);
    if (project != null && generator != null && !(generator instanceof TemplateProjectDirectoryGenerator)) {
      generator.generateProject(project, baseDir, settings, ModuleManager.getInstance(project).getModules()[0]);
    }

    LightweightNewProjectWizardCollector.logProjectGenerated(project, generator != null ? generator.getClass() : null);
    return project;
  }
public static <T> Project doGenerateProject(@NotNull String locationString,
                                              @Nullable DirectoryProjectGenerator<T> generator,
                                              @NotNull T settings,
                                              @NotNull OpenProjectTask options)