CheckedTreeNode (Collection<SuggestedChildRootInfo> suggestedRoots) { SuggestedChildRootInfo[] sortedRoots = suggestedRoots.toArray(new SuggestedChildRootInfo[0]); Arrays.sort(sortedRoots, Comparator.comparing(o -> o.getDetectedRoot().getFile().getPresentableUrl())); CheckedTreeNode root = new CheckedTreeNode(null); Map<VirtualFile, CheckedTreeNode> rootCandidateNodes = new HashMap<>(); for (SuggestedChildRootInfo rootInfo : sortedRoots) { final VirtualFile rootCandidate = rootInfo.getRootCandidate(); CheckedTreeNode parent = rootCandidateNodes.get(rootCandidate); if (parent == null) { parent = new VirtualFileCheckedTreeNode(rootCandidate); rootCandidateNodes.put(rootCandidate, parent); root.add(parent); } parent.add(new VirtualFileCheckedTreeNode(rootInfo)); } return root; }