private static void addDependenciesNode(@NotNull ExternalProjectsView externalProjectsView,
                                          @NotNull MultiMap<Key<?>, DataNode<?>> dataNodes,
                                          @NotNull List<? super ExternalSystemNode<?>> result) {
    final Collection<DataNode<?>> depsGraph = dataNodes.get(ProjectKeys.DEPENDENCIES_GRAPH);
    if (!depsGraph.isEmpty()) {
      final ExternalSystemNode<?> depNode = new MyDependenciesNode(externalProjectsView);
      for (DataNode<?> dataNode : depsGraph) {
        if (!(dataNode.getData() instanceof ProjectDependencies projectDependencies)) continue;

        for (ComponentDependencies componentDependencies : projectDependencies.getComponentsDependencies()) {
          depNode.add(new DependencyScopeExternalSystemNode(externalProjectsView, componentDependencies.getCompileDependenciesGraph()));
          depNode.add(new DependencyScopeExternalSystemNode(externalProjectsView, componentDependencies.getRuntimeDependenciesGraph()));
        }
      }

      if (depNode.hasChildren()) {
        result.add(depNode);
      }
      return;
    }

    final Collection<DataNode<?>> moduleDeps = dataNodes.get(ProjectKeys.MODULE_DEPENDENCY);
    final Collection<DataNode<?>> libDeps = dataNodes.get(ProjectKeys.LIBRARY_DEPENDENCY);

    if (!moduleDeps.isEmpty() || !libDeps.isEmpty()) {
      //noinspection rawtypes
      List<ExternalSystemNode<? extends DependencyData>> depNodeChildren = new ArrayList<>();

      for (DataNode<?> dataNode : moduleDeps) {
        if (!(dataNode.getData() instanceof ModuleDependencyData)) continue;
        //noinspection unchecked
        ModuleDependencyDataExternalSystemNode moduleDependencyDataExternalSystemNode =
          new ModuleDependencyDataExternalSystemNode(externalProjectsView, (DataNode<ModuleDependencyData>)dataNode);
        if (dataNode.getParent() != null && dataNode.getParent().getData() instanceof AbstractDependencyData) {
          result.add(moduleDependencyDataExternalSystemNode);
        }
        else {
          depNodeChildren.add(moduleDependencyDataExternalSystemNode);
        }
      }

      for (DataNode<?> dataNode : libDeps) {
        if (!(dataNode.getData() instanceof LibraryDependencyData)) continue;
        //noinspection unchecked
        final ExternalSystemNode<LibraryDependencyData> libraryDependencyDataExternalSystemNode =
          new LibraryDependencyDataExternalSystemNode(externalProjectsView, (DataNode<LibraryDependencyData>)dataNode);
        if (((LibraryDependencyData)dataNode.getData()).getTarget().isUnresolved()) {
          libraryDependencyDataExternalSystemNode.setErrorLevel(
            ExternalProjectsStructure.ErrorLevel.ERROR,
            "Unable to resolve " + ((LibraryDependencyData)dataNode.getData()).getTarget().getExternalName());
        }
        else {
          libraryDependencyDataExternalSystemNode.setErrorLevel(ExternalProjectsStructure.ErrorLevel.NONE);
        }
        if (dataNode.getParent() != null && dataNode.getParent().getData() instanceof ModuleData) {
          depNodeChildren.add(libraryDependencyDataExternalSystemNode);
        }
        else {
          result.add(libraryDependencyDataExternalSystemNode);
        }
      }

      if (!depNodeChildren.isEmpty()) {
        final ExternalSystemNode<?> depNode = new MyDependenciesNode(externalProjectsView);
        depNode.addAll(depNodeChildren);
        result.add(depNode);
      }
    }
  }
private static void addDependenciesNode(@NotNull ExternalProjectsView externalProjectsView,
                                          @NotNull MultiMap<Key<?>, DataNode<?>> dataNodes,
                                          @NotNull List<? super ExternalSystemNode<?>> result)