private static void addModuleNodes(@NotNull ExternalProjectsView externalProjectsView,
                                     @NotNull MultiMap<Key<?>, DataNode<?>> dataNodes,
                                     @NotNull List<? super ExternalSystemNode<?>> result) {
    final Collection<DataNode<?>> moduleDataNodes = dataNodes.get(ProjectKeys.MODULE);
    if (!moduleDataNodes.isEmpty()) {
      final AbstractExternalSystemSettings systemSettings =
        ExternalSystemApiUtil.getSettings(externalProjectsView.getProject(), externalProjectsView.getSystemId());

      final Map<String, ModuleNode> groupToModule = new HashMap<>(moduleDataNodes.size());

      List<ModuleNode> moduleNodes = new ArrayList<>();

      for (DataNode<?> dataNode : moduleDataNodes) {
        final ModuleData data = (ModuleData)dataNode.getData();

        final ExternalProjectSettings projectSettings = systemSettings.getLinkedProjectSettings(data.getLinkedExternalProjectPath());
        DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(dataNode, ProjectKeys.PROJECT);
        final boolean isRoot =
          projectSettings != null && data.getLinkedExternalProjectPath().equals(projectSettings.getExternalProjectPath()) &&
          projectDataNode != null && projectDataNode.getData().getInternalName().equals(data.getInternalName());
        //noinspection unchecked
        final ModuleNode moduleNode = new ModuleNode(externalProjectsView, (DataNode<ModuleData>)dataNode, null, isRoot);
        moduleNodes.add(moduleNode);

        String group = moduleNode.getIdeGrouping();
        if (group != null) {
          groupToModule.put(group, moduleNode);
        }
      }

      for (ModuleNode moduleNode : moduleNodes) {
        moduleNode.setAllModules(moduleNodes);
        String parentGroup = moduleNode.getIdeParentGrouping();
        ModuleNode parent = parentGroup != null ? groupToModule.get(parentGroup) : null;
        if (parent == null) {
          continue;
        }
        moduleNode.setParent(parent);
      }

      result.addAll(moduleNodes);
    }
  }
private static void addModuleNodes(@NotNull ExternalProjectsView externalProjectsView,
                                     @NotNull MultiMap<Key<?>, DataNode<?>> dataNodes,
                                     @NotNull List<? super ExternalSystemNode<?>> result)