/** * Depth-first search visitor. * * @param info the module info * @param sortedList the sorted list to add modules to */ private void visit(ModuleInfo info, List<ModuleInfo> sortedList) { if (info.getOrdinal() == 0) { // not sorted yet if (info.isVisited()) { // cannot happen in jigsaw but one never knows... throw new TentackleRuntimeException("unsortable module hierarchy (cyclic dependency?)"); } info.setVisited(true); for (Iterator<String> iter = info.getRequiredModuleNames().iterator(); iter.hasNext(); ) { String name = iter.next(); ModuleInfo subInfo = nameToModules.get(name); if (subInfo != null) { visit(subInfo, sortedList); } else { // not an application module iter.remove(); } } info.setOrdinal(sortedList.size() + 1); sortedList.add(info); } }