ModuleDescriptor (List<? extends ModuleDescriptor> descriptors, File file) { ModuleDescriptor result = null; File nearestRoot = null; for (ModuleDescriptor descriptor : descriptors) { for (File root : descriptor.getContentRoots()) { if (FileUtil.isAncestor(root, file, false) && (nearestRoot == null || FileUtil.isAncestor(nearestRoot, root, true))) { result = descriptor; nearestRoot = root; } } } return result; }