LexicalIncludePaths { @NotNull public static String findCommonParentFolder(@NotNull Collection<String> folders) { if (folders.isEmpty()) { return ""; } List<String[]> splits = new ArrayList<>(); int minSize = Integer.MAX_VALUE; for (String folder : folders) { String[] split = folder.split(UNIX_SEPARATOR); splits.add(split); minSize = Math.min(minSize, split.length); } StringBuilder buildUp = null; for (int i = 0; i < minSize; ++i) { String prior = null; for (String[] split : splits) { if (prior == null) { prior = split[i]; continue; } if (!prior.equals(split[i])) { return buildUp == null ? "" : buildUp.toString(); } } if (buildUp != null) { buildUp.append(UNIX_SEPARATOR); } if (buildUp == null) { buildUp = new StringBuilder(prior == null ? "" : prior); } else { buildUp.append(prior); } } return buildUp == null ? "" : buildUp.toString(); }  static boolean hasHeaderExtension(@NotNull String filename); @NotNull static String findCommonParentFolder(@NotNull Collection<String> folders); @NotNull static String trimPathSeparators(@NotNull String path); @NotNull static Matcher matchFolderToRegex(@NotNull Pattern pattern, @NotNull File folder); @NotNull
  static final ImmutableSet<String> HEADER_FILE_EXTENSIONS; }
@Test public void testCommonRelativeIncludePath1() { List<String> paths = new ArrayList<>(); paths.add("usr/one/two"); paths.add("usr/one/three"); String common = LexicalIncludePaths.findCommonParentFolder(paths); assertThat(common).isEqualTo("usr/one"); }
@Test public void testCommonRelativeIncludePath2() { List<String> paths = new ArrayList<>(); paths.add("usr/one/two"); paths.add("usr/one/two"); String common = LexicalIncludePaths.findCommonParentFolder(paths); assertThat(common).isEqualTo("usr/one/two"); }
@Test public void testCommonRelativeIncludePath3() { List<String> paths = new ArrayList<>(); paths.add("/usr/one/two"); paths.add("/usr/one/three"); String common = LexicalIncludePaths.findCommonParentFolder(paths); assertThat(common).isEqualTo("/usr/one"); }
@Test public void testCommonRelativeIncludePathWindowsDifferentDrive() { List<String> paths = new ArrayList<>(); paths.add("c:/usr/one/two"); paths.add("d:/usr/one/three"); String common = LexicalIncludePaths.findCommonParentFolder(paths); assertThat(common).isEqualTo(""); }
@Test public void testCommonRelativeIncludePathWindowsSameDrive() { List<String> paths = new ArrayList<>(); paths.add("c:/usr/one/two"); paths.add("c:/usr/one/three"); String common = LexicalIncludePaths.findCommonParentFolder(paths); assertThat(common).isEqualTo("c:/usr/one"); }
@Test public void testCommonRelativeIncludePathEmptyList() { List<String> paths = new ArrayList<>(); String common = LexicalIncludePaths.findCommonParentFolder(paths); assertThat(common).isEqualTo(""); }