private void saveTemplates(boolean removeDeleted) {
    final Set<String> allNames = new HashSet<>();
    final Set<String> templatesOnDisk = new HashSet<>();
    processLocal((name, stream, aBoolean) -> {
      templatesOnDisk.add(name);
      allNames.add(name);
      return true;
    });

    final Map<String, FileTemplateBase> templatesToSave = new HashMap<>();

    for (FileTemplateBase template : getAllTemplates(true)) {
      processTemplate(allNames, templatesToSave, template);
      for (FileTemplate child : template.getChildren()) {
        processTemplate(allNames, templatesToSave, (FileTemplateBase)child);
      }
    }

    if (allNames.isEmpty()) {
      return;
    }

    try {
      Files.createDirectories(templateDir);
    }
    catch (IOException e) {
      LOG.info("Cannot create directory: " + templateDir);
    }

    final String lineSeparator = CodeStyle.getDefaultSettings().getLineSeparator();
    for (String name : allNames) {
      final FileTemplateBase templateToSave = templatesToSave.get(name);
      if (!templatesOnDisk.contains(name)) {
        // template was not saved before
        saveTemplate(templateToSave, lineSeparator);
      }
      else if (templateToSave == null) {
        // template was removed
        if (removeDeleted) {
          deleteFile(name);
        }
      }
      else {
        // both customized content on disk and corresponding template are present
        String diskText = readFile(name);
        String templateText = templateToSave.getText();
        if (!templateText.equals(diskText)) {
          // save only if texts differ to avoid unnecessary file touching
          saveTemplate(templateToSave, lineSeparator);
        }
      }
    }
  }
private void saveTemplates(boolean removeDeleted)