Set<FilePath> (@NotNull RecursiveFilePathSet dirs, @NotNull Set<? extends FilePath> files) { Set<FilePath> result = newFilePathsSet(); for (FilePath file : files) { if (dirs.hasAncestor(file)) continue; // if dir non-recursively + non-recursive file child -> can be truncated to dir only if (!file.isDirectory() && files.contains(file.getParentPath())) continue; result.add(file); } return result; }