docs: private static List<ModuleRef> findModuleRefs(final LinkedHashSet<Object> layers, final ScanSpec scanSpec,
              final LogNode log) {
          if (layers.isEmpty()) {
              return Collections.emptyList();
          }
  
          // Traverse the layer DAG to find the layer resolution order
          final Deque<Object> /* Deque<ModuleLayer> */ layerOrder = new ArrayDeque<>();
          final Set<Object> /* Set<ModuleLayer */ parentLayers = new HashSet<>();
          for (final Object layer : layers) {
              findLayerOrder(layer, /* layerVisited = */ new HashSet<>(), parentLayers, layerOrder);
          }
          if (scanSpec.addedModuleLayers != null) {
              for (final Object layer : scanSpec.addedModuleLayers) {
                  findLayerOrder(layer, /* layerVisited = */ new HashSet<>(), parentLayers, layerOrder);
              }
          }
  
          // Remove parent layers from layer order if scanSpec.ignoreParentModuleLayers is true
          List<Object> /* List<ModuleLayer> */ layerOrderFinal;
          if (scanSpec.ignoreParentModuleLayers) {
              layerOrderFinal = new ArrayList<>();
              for (final Object layer : layerOrder) {
                  if (!parentLayers.contains(layer)) {
                      layerOrderFinal.add(layer);
                  }
              }
          } else {
              layerOrderFinal = new ArrayList<>(layerOrder);
          }
  
          // Find modules in the ordered layers
          final Set<Object> /* Set<ModuleReference> */ addedModules = new HashSet<>();
          final LinkedHashSet<ModuleRef> moduleRefOrder = new LinkedHashSet<>();
          for (final Object /* ModuleLayer */ layer : layerOrderFinal) {
              final Object /* Configuration */ configuration = ReflectionUtils.invokeMethod(layer, "configuration",
                      /* throwException = */ true);
              if (configuration != null) {
                  // Get ModuleReferences from layer configuration
                  @SuppressWarnings("unchecked")
                  final Set<Object> /* Set<ResolvedModule> */ modules = (Set<Object>) ReflectionUtils
                          .invokeMethod(configuration, "modules", /* throwException = */ true);
                  if (modules != null) {
                      final List<ModuleRef> modulesInLayer = new ArrayList<>();
                      for (final Object /* ResolvedModule */ module : modules) {
                          final Object /* ModuleReference */ moduleReference = ReflectionUtils.invokeMethod(module,
                                  "reference", /* throwException = */ true);
                          if (moduleReference != null && addedModules.add(moduleReference)) {
                              try {
                                  modulesInLayer.add(new ModuleRef(moduleReference, layer));
                              } catch (final IllegalArgumentException e) {
                                  if (log != null) {
                                      log.log("Exception while creating ModuleRef for module " + moduleReference, e);
                                  }
                              }
                          }
                      }
                      // Sort modules in layer by name
                      CollectionUtils.sortIfNotEmpty(modulesInLayer);
                      moduleRefOrder.addAll(modulesInLayer);
                  }
              }
          }
          return new ArrayList<>(moduleRefOrder);
      }