boolean (Module originalModule, Module[] configModules) { if (originalModule == null || configModules.length == 0) { return false; } Deque<Module> queue = new ArrayDeque<>(); queue.addLast(originalModule); Set<Module> modules = new HashSet<>(); while (!queue.isEmpty()) { Module module = queue.removeFirst(); //configModules contains 1 element if (ArrayUtil.contains(module, configModules)) { return true; } for (Module next : ModuleRootManager.getInstance(module).getModuleDependencies(true)) { if (!modules.add(next)) continue; queue.addLast(next); } } return false; }