public static void saveLanguageDescriptor(
      IFile file, LanguageDescriptor descriptor, MacroHelper macroHelper) {
    if (file.isReadOnly()) {
      if (LOG.isEnabledFor(Priority.ERROR)) {
        LOG.error("Cant't save " + file.getPath());
      }
      return;
    }

    Element languageElement = new Element("language");
    languageElement.setAttribute("namespace", descriptor.getNamespace());
    String uuid = descriptor.getUUID();
    if (uuid != null) {
      languageElement.setAttribute("uuid", uuid);
    }
    if (descriptor.getGenPath() != null) {
      languageElement.setAttribute(
          "generatorOutputPath", macroHelper.shrinkPath(descriptor.getGenPath()));
    }

    Element models = new Element("models");
    ModuleDescriptorPersistence.saveModelRoots(
        models, descriptor.getModelRootDescriptors(), macroHelper);
    languageElement.addContent(models);

    if (!(descriptor.getModuleFacetDescriptors().isEmpty())) {
      Element facets = new Element("facets");
      ModuleDescriptorPersistence.saveFacets(
          facets, descriptor.getModuleFacetDescriptors(), macroHelper);
      languageElement.addContent(facets);
    }

    Element accessoryModels = new Element("accessoryModels");
    for (SModelReference model : SetSequence.fromSet(descriptor.getAccessoryModels())) {
      XmlUtil.tagWithAttribute(accessoryModels, "model", "modelUID", model.toString());
    }
    languageElement.addContent(accessoryModels);

    Element generators = new Element("generators");
    for (GeneratorDescriptor generatorDescriptor :
        ListSequence.fromList(descriptor.getGenerators())) {
      GeneratorDescriptorPersistence.saveGeneratorDescriptor(
          generators, generatorDescriptor, macroHelper);
    }
    languageElement.addContent(generators);

    if (!(descriptor.getAdditionalJavaStubPaths().isEmpty())) {
      Element stubModelEntries = new Element("stubModelEntries");
      ModuleDescriptorPersistence.saveStubModelEntries(
          stubModelEntries, descriptor.getAdditionalJavaStubPaths(), macroHelper);
      languageElement.addContent(stubModelEntries);
    }

    Element sourcePath = new Element("sourcePath");
    for (String p : descriptor.getSourcePaths()) {
      XmlUtil.tagWithAttribute(sourcePath, "source", "path", macroHelper.shrinkPath(p));
    }
    languageElement.addContent(sourcePath);

    ModuleDescriptorPersistence.saveDependencies(languageElement, descriptor);

    Element extendedLanguages = new Element("extendedLanguages");
    for (SModuleReference ref : SetSequence.fromSet(descriptor.getExtendedLanguages())) {
      XmlUtil.tagWithText(extendedLanguages, "extendedLanguage", ref.toString());
    }
    languageElement.addContent(extendedLanguages);

    try {
      OutputStream os = file.openOutputStream();
      JDOMUtil.writeDocument(new Document(languageElement), os);
    } catch (Exception e) {
      if (LOG.isEnabledFor(Priority.ERROR)) {
        LOG.error("", e);
      }
    }
    ModuleDescriptorPersistence.setTimestamp(descriptor, file);
  }