private static void addUnprocessedIdeaGeneratedSourcesDirs(
    @NotNull Map<String, DefaultExternalSourceSet> externalSourceSets, // mutable
    @NotNull GradleSourceSetResolutionContext sourceSetResolutionContext,
    @NotNull String sourceSetName
  ) {
    Collection<File> ideaSourceDirs = SourceSet.TEST_SOURCE_SET_NAME.equals(sourceSetName)
                                      ? sourceSetResolutionContext.ideaTestSourceDirs
                                      : sourceSetResolutionContext.ideaSourceDirs;
    ExternalSystemSourceType sourceType = SourceSet.TEST_SOURCE_SET_NAME.equals(sourceSetName)
                                          ? ExternalSystemSourceType.TEST
                                          : ExternalSystemSourceType.SOURCE;
    ExternalSystemSourceType generatedSourceType = SourceSet.TEST_SOURCE_SET_NAME.equals(sourceSetName)
                                                   ? ExternalSystemSourceType.TEST_GENERATED
                                                   : ExternalSystemSourceType.SOURCE_GENERATED;

    DefaultExternalSourceSet externalSourceSet = externalSourceSets.get(sourceSetName);
    if (externalSourceSet == null) return;

    Collection<File> generatedSourceDirs = new LinkedHashSet<>(sourceSetResolutionContext.unprocessedIdeaGeneratedSourceDirs);
    generatedSourceDirs.retainAll(ideaSourceDirs);
    if (!generatedSourceDirs.isEmpty()) {
      ExternalSourceDirectorySet generatedSourceDirectorySet = externalSourceSet.getSources().get(generatedSourceType);
      if (generatedSourceDirectorySet != null) {
        generatedSourceDirectorySet.getSrcDirs().addAll(generatedSourceDirs);
      }
      else {
        DefaultExternalSourceDirectorySet generatedDirectorySet = new DefaultExternalSourceDirectorySet();
        generatedDirectorySet.setName("generated " + externalSourceSet.getName());
        generatedDirectorySet.getSrcDirs().addAll(generatedSourceDirs);
        ExternalSourceDirectorySet sourceDirectorySet = externalSourceSet.getSources().get(sourceType);
        if (sourceDirectorySet != null) {
          generatedDirectorySet.setGradleOutputDirs(Collections.singleton(sourceDirectorySet.getOutputDir()));
          generatedDirectorySet.setOutputDir(sourceDirectorySet.getOutputDir());
          generatedDirectorySet.setCompilerOutputPathInherited(sourceDirectorySet.isCompilerOutputPathInherited());
        }
        externalSourceSet.addSource(generatedSourceType, generatedDirectorySet);
      }
    }
  }
private static void addUnprocessedIdeaGeneratedSourcesDirs(
    @NotNull Map<String, DefaultExternalSourceSet> externalSourceSets, // mutable
    @NotNull GradleSourceSetResolutionContext sourceSetResolutionContext,
    @NotNull String sourceSetName
  )