private void setParameters(Sdk jdk, GeneralCommandLine cmdLine) throws CantRunException {
      ParametersList parameters = cmdLine.getParametersList();

      if (myConfiguration.LOCALE != null && myConfiguration.LOCALE.length() > 0) {
        parameters.add("-locale");
        parameters.add(myConfiguration.LOCALE);
      }

      if (myConfiguration.OPTION_SCOPE != null) {
        parameters.add("-" + myConfiguration.OPTION_SCOPE);
      }

      if (!myConfiguration.OPTION_HIERARCHY) {
        parameters.add("-notree");
      }

      if (!myConfiguration.OPTION_NAVIGATOR) {
        parameters.add("-nonavbar");
      }

      if (!myConfiguration.OPTION_INDEX) {
        parameters.add("-noindex");
      }
      else if (myConfiguration.OPTION_SEPARATE_INDEX) {
        parameters.add("-splitindex");
      }

      if (myConfiguration.OPTION_DOCUMENT_TAG_USE) {
        parameters.add("-use");
      }

      if (myConfiguration.OPTION_DOCUMENT_TAG_AUTHOR) {
        parameters.add("-author");
      }

      if (myConfiguration.OPTION_DOCUMENT_TAG_VERSION) {
        parameters.add("-version");
      }

      if (!myConfiguration.OPTION_DOCUMENT_TAG_DEPRECATED) {
        parameters.add("-nodeprecated");
      }
      else if (!myConfiguration.OPTION_DEPRECATED_LIST) {
        parameters.add("-nodeprecatedlist");
      }

      parameters.addParametersString(myConfiguration.OTHER_OPTIONS);

      if (myConfiguration.OPTION_LINK_TO_JDK_DOCS) {
        for (String url : jdk.getRootProvider().getUrls(JavadocOrderRootType.getInstance())) {
          parameters.add("-link");
          parameters.add(url);
        }
      }

      if (myConfiguration.OUTPUT_DIRECTORY != null) {
        parameters.add("-d");
        parameters.add(myConfiguration.OUTPUT_DIRECTORY.replace('/', File.separatorChar));
      }

      Set<Module> modules = new LinkedHashSet<>();
      Set<VirtualFile> sources = new HashSet<>();
      Runnable r = () -> myGenerationOptions.accept(new MyContentIterator(myProject, modules, sources));
      String title = JavaBundle.message("javadoc.generate.sources.progress");
      if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(r, title, true, myProject)) {
        return;
      }
      if (sources.isEmpty()) {
        throw new CantRunException(JavaBundle.message("javadoc.generate.no.classes.in.selected.packages.error"));
      }

      Set<Module> modulesWithoutDescriptor = new HashSet<>(modules);
      Map<Module, VirtualFile> moduleDescriptors = new HashMap<>();
      boolean hasJavaModules = false;
      for (VirtualFile source : sources) {
        if (!PsiJavaModule.MODULE_INFO_FILE.equals(source.getName())) {
          continue;
        }
        hasJavaModules = true;
        Module module = ModuleUtilCore.findModuleForFile(source, myProject);
        if (module != null) {
          moduleDescriptors.put(module, source);
          modulesWithoutDescriptor.remove(module);
        }
      }
      if (hasJavaModules && !modulesWithoutDescriptor.isEmpty()) {
        // So far we can't generate javadoc for each module independently as we have to merge the results into common files,
        // e.g index.html, index-all.html and so on. Moreover, the final javadoc seems obscured in the case when one module contains
        // module-info file but another one is not.
        throw new CantRunException(JavaBundle.message("javadoc.gen.error.modules.without.module.info", modulesWithoutDescriptor.stream()
          .map(m -> "'" + m.getName() + "'").collect(Collectors.joining(","))));
      }

      if (JavaSdkVersionUtil.isAtLeast(jdk, JavaSdkVersion.JDK_11)) {
        for (Module module : modules) {
          LanguageLevel languageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module);
          if (languageLevel.isPreview()) {
            parameters.add(JavaParameters.JAVA_ENABLE_PREVIEW_PROPERTY);
            parameters.add("--source", String.valueOf(languageLevel.feature()));
            break;
          }
        }
      }
      
      File argsFile = createTempArgsFile();
      List<VirtualFile> sourceRoots = findSourceRoots(modules);
      List<VirtualFile> classRoots = findClassRoots(modules, jdk);

      Charset cs = CharsetToolkit.getPlatformCharset();
      try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(argsFile), cs))) {
        if (sourceRoots.size() + classRoots.size() > 0) {
          if (hasJavaModules && JavaSdkUtil.isJdkAtLeast(jdk, JavaSdkVersion.JDK_1_9)) {
            if (modules.size() > 1) {
              writer.println("--module-source-path");
              String moduleSourcePath = computeModuleSourcePath(moduleDescriptors);
              if (moduleSourcePath == null) {
                throw new CantRunException(JavaBundle.message("javadoc.gen.error.module.source.path.is.not.evaluated"));
              }
              writer.println(StringUtil.wrapWithDoubleQuote(moduleSourcePath));
            }
            else if (!sourceRoots.isEmpty()) {
              String path = sourceRoots.stream().map(MyJavaCommandLineState::localPath).collect(Collectors.joining(File.pathSeparator));
              writer.println("--source-path");
              writer.println(StringUtil.wrapWithDoubleQuote(path));
            }

            if (!classRoots.isEmpty()) {
              String path = classRoots.stream().map(MyJavaCommandLineState::localPath).collect(Collectors.joining(File.pathSeparator));
              writer.println("--module-path");
              writer.println(StringUtil.wrapWithDoubleQuote(path));
            }
          }
          else {
            // placing source roots on a classpath is perfectly legal and allows generating correct Javadoc
            // when a module without a module-info.java file depends on another module that has one
            Stream<VirtualFile> roots = Stream.concat(sourceRoots.stream(), classRoots.stream());
            String path = roots.map(MyJavaCommandLineState::localPath).collect(Collectors.joining(File.pathSeparator));
            writer.println("-classpath");
            writer.println(StringUtil.wrapWithDoubleQuote(path));

            if (!sourceRoots.isEmpty() && JavaSdkUtil.isJdkAtLeast(jdk, JavaSdkVersion.JDK_18)) {
              //is needed for javadoc snippets only
              String sourcePath = sourceRoots.stream().map(MyJavaCommandLineState::localPath).collect(Collectors.joining(File.pathSeparator));
              writer.println("--source-path");
              writer.println(StringUtil.wrapWithDoubleQuote(sourcePath));
            }
          }
        }

        for (VirtualFile source : sources) {
          writer.println(StringUtil.wrapWithDoubleQuote(source.getPath()));
        }
      }
      catch (FileNotFoundException e) {
        throw new CantRunException(JavaBundle.message("javadoc.generate.temp.file.does.not.exist"), e);
      }
      catch (CantRunException e) {
        FileUtil.delete(argsFile);
        throw e;
      }

      myArgFileFilter.setPath(argsFile.getPath(), cs);
      parameters.add("@" + argsFile.getPath());
      OSProcessHandler.deleteFileOnTermination(cmdLine, argsFile);
      cmdLine.setCharset(cs);
    }
private void setParameters(Sdk jdk, GeneralCommandLine cmdLine)