private Map<JpsModule, Set<String>> computeModuleCharsetMap() {
    final Map<JpsModule, Set<String>> map = new HashMap<>();
    final Iterable<JavaBuilderExtension> builderExtensions = JpsServiceManager.getInstance().getExtensions(JavaBuilderExtension.class);
    for (Map.Entry<String, String> entry : myUrlToCharset.entrySet()) {
      final String fileUrl = entry.getKey();
      final String charset = entry.getValue();
      File file = JpsPathUtil.urlToFile(fileUrl);
      if (charset == null || (!file.isDirectory() && !shouldHonorEncodingForCompilation(builderExtensions, file))) {
        continue;
      }
      final JavaSourceRootDescriptor rootDescriptor = myRootsIndex.findJavaRootDescriptor(null, file);
      if (rootDescriptor == null) {
        continue;
      }
      final JpsModule module = rootDescriptor.target.getModule();
      Set<String> set = map.get(module);
      if (set == null) {
        set = new LinkedHashSet<>();
        map.put(module, set);
        // need to search parents only once because
        // file parent's charset, if explicitly defined, has higher priority than the charset assigned to individual files
        // we deliberately check parents until the source roots
        final File sourceRoot = rootDescriptor.root;
        File current = FileUtilRt.getParentFile(file);
        String parentCharset = null;
        while (current != null) {
          final String currentCharset = lookupCharsetMap(current);
          if (currentCharset != null) {
            parentCharset = currentCharset;
          }
          if (FileUtil.filesEqual(current, sourceRoot)) {
            break;
          }
          current = FileUtilRt.getParentFile(current);
        }
        if (parentCharset != null) {
          set.add(parentCharset);
        }
      }
      set.add(charset);
    }

    // now check source root charsets and up and augment the map so that every module has its preferred charset assigned
    // here apply usual rules from encoding configuration: sub-paths inherit charset assigned to parents unless explicitly overridden.

    for (JpsModule module : myJpsModel.getProject().getModules()) {
      for (JpsModuleSourceRoot srcRoot : module.getSourceRoots()) {
        final String encoding = getEncoding(srcRoot.getFile());
        if (encoding != null) {
          Set<String> charsets = map.get(module);
          if (charsets == null) {
            charsets = new LinkedHashSet<>();
            map.put(module, charsets);
          }
          charsets.add(encoding);
        }
      }
    }

    return map;
  }
private Map<JpsModule, Set<String>> computeModuleCharsetMap()