public static void getOrCreateConsole(@NotNull final Project project,
                                        @NotNull final VirtualFile contentFile,
                                        @NotNull final Consumer<? super GroovyConsole> callback) {
    final GroovyConsole existingConsole = contentFile.getUserData(GROOVY_CONSOLE);
    if (existingConsole != null) {
      callback.consume(existingConsole);
      return;
    }

    final Consumer<Module> initializer = module -> {
      final GroovyConsole console = createConsole(project, contentFile, module);
      if (console != null) {
        callback.consume(console);
      }
    };

    final GroovyConsoleStateService service = GroovyConsoleStateService.getInstance(project);
    final Module module = service.getSelectedModule(contentFile);
    if (module != null) {
      // if module for console is already selected, then use it for creation
      initializer.consume(module);
      return;
    }

    // if not, then select module, then run initializer
    GroovyConsoleUtil.selectModuleAndRun(project, selectedModule -> {
      service.setFileModule(contentFile, selectedModule);
      initializer.consume(selectedModule);
    });
  }
public static void getOrCreateConsole(@NotNull final Project project,
                                        @NotNull final VirtualFile contentFile,
                                        @NotNull final Consumer<? super GroovyConsole> callback)