List<MavenProject> (Collection<MavenProject> projects) { return withReadLock(() -> { List<MavenProject> result = null; Set<MavenCoordinate> projectIds = new ObjectOpenCustomHashSet<>(projects.size(), new MavenCoordinateHashCodeStrategy()); for (MavenProject project : projects) { projectIds.add(project.getMavenId()); } Set<File> projectPaths = FileCollectionFactory.createCanonicalFileSet(); for (MavenProject project : projects) { projectPaths.add(new File(project.getFile().getPath())); } for (MavenProject project : myVirtualFileToProjectMapping.values()) { boolean isDependent = false; Set<String> pathsInStack = project.getModulePaths(); for (final String path : pathsInStack) { if (projectPaths.contains(new File(path))) { isDependent = true; break; } } if (!isDependent) { for (MavenArtifact dep : project.getDependencies()) { if (projectIds.contains(dep)) { isDependent = true; break; } } } if (isDependent) { if (result == null) result = new ArrayList<>(); result.add(project); } } return result == null ? Collections.emptyList() : result; }); }