void (@NotNull Project project, @NotNull Set<TestDataFile> files, @NotNull Consumer<TestDataNavigationElement> consumer) { for (Map.Entry<VirtualFile, Collection<TestDataFile>> e: ContainerUtil.groupBy(files, f -> { VirtualFile file = f.getVirtualFile(); assert file != null; return file.getParent(); }).entrySet()) { Collection<TestDataFile> dirFiles = e.getValue(); Set<TestDataFile> usedPaths = new HashSet<>(); for (TestDataFile testDataFile1 : dirFiles) { if (usedPaths.contains(testDataFile1)) { continue; } boolean groupFound = false; for (TestDataFile testDataFile2 : dirFiles) { VirtualFile file2 = testDataFile2.getVirtualFile(); assert file2 != null; if (testDataFile1.equals(testDataFile2) || usedPaths.contains(testDataFile1)) { continue; } TestDataGroupVirtualFile group = TestDataUtil.getTestDataGroup(testDataFile1, testDataFile2); if (group == null) { continue; } groupFound = true; consumer.accept(TestDataNavigationElementFactory.createForGroup(project, group)); usedPaths.add(testDataFile1); usedPaths.add(testDataFile2); break; } if (!groupFound) { consumer.accept(TestDataNavigationElementFactory.createForFile(project, testDataFile1)); usedPaths.add(testDataFile1); } } } }