DetectedProjectRoot (ProjectStructureDetector detector, DetectedProjectRoot root) { for (Map.Entry<DetectedProjectRoot, Collection<ProjectStructureDetector>> entry : myRoots.entrySet()) { final DetectedProjectRoot oldRoot = entry.getKey(); final DetectedProjectRoot combined = oldRoot.combineWith(root); if (combined != null) { myRoots.remove(oldRoot); final Set<ProjectStructureDetector> values = new HashSet<>(entry.getValue()); values.add(detector); myRoots.put(combined, values); if (mySelectedRoot == oldRoot) { mySelectedRoot = combined; } return combined; } } myRoots.putValue(root, detector); return root; }