public static void buildMultipleDirectoriesInPackageMessage(StringBuffer message,
                                                              String packageQname,
                                                              PsiDirectory[] directories,
                                                              @Nullable PsiDirectory selectedDirectory) {
    message.append(RefactoringBundle.message("multiple.directories.correspond.to.package", packageQname));
    final List<PsiDirectory> generated = new ArrayList<>();
    final List<PsiDirectory> source = new ArrayList<>();
    for (PsiDirectory directory : directories) {
      final VirtualFile virtualFile = directory.getVirtualFile();
      if (GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(virtualFile, directory.getProject())) {
        generated.add(directory);
      } else {
        source.add(directory);
      }
    }
    
    if (selectedDirectory != null) {
      Project project = selectedDirectory.getProject();
      Module selectedModule = Objects.requireNonNull(
        ModuleUtilCore.findModuleForFile(selectedDirectory.getVirtualFile(), project));
      source.sort((d1, d2) -> {
        if (d1 == d2) return 0;
        if (d1 == selectedDirectory) {
          return -1;
        }
        else if (d2 == selectedDirectory) {
          return 1;
        }
        Module m1 = ModuleUtilCore.findModuleForFile(d1.getVirtualFile(), selectedDirectory.getProject());
        Module m2 = ModuleUtilCore.findModuleForFile(d2.getVirtualFile(), selectedDirectory.getProject());
        if (m1 == selectedModule && m2 != selectedModule) {
          return -1;
        }
        else if (m1 != selectedModule && m2 == selectedModule) {
          return 1;
        }

        return presentableUrl(selectedDirectory, d1).compareToIgnoreCase(presentableUrl(selectedDirectory, d2));
      });
      //ensure current on the first place
      source.remove(selectedDirectory);
      source.add(0, selectedDirectory);
    }
    final Function<PsiDirectory, String> directoryPresentation = directory -> presentableUrl(selectedDirectory, directory);
    appendRoots(message, source, directoryPresentation);
    if (!generated.isEmpty()) {
      message.append("\n\n").append(RefactoringBundle.message("also.generated")).append("\n");
      appendRoots(message, generated, directoryPresentation);
    }
  }
public static void buildMultipleDirectoriesInPackageMessage(StringBuffer message,
                                                              String packageQname,
                                                              PsiDirectory[] directories,
                                                              @Nullable PsiDirectory selectedDirectory)