示例#1
0
 private SNode convertLanguage(LanguageDescriptor source) {
   SNode result =
       SConceptOperations.createNewNode("jetbrains.mps.lang.project.structure.Language", null);
   result.setId(SNodeId.fromString("~root"));
   SModelOperations.addRootNode(myModel, result);
   fill(result, source);
   SPropertyOperations.set(result, "doNotGenerateAdapters", "" + source.isDoNotGenerateAdapters());
   SPropertyOperations.set(result, "genPath", source.getGenPath());
   SPropertyOperations.set(result, "languagePath", myFile.getPath());
   for (SModelReference ref : source.getAccessoryModels()) {
     SLinkOperations.getTargets(result, "accessoryModels", true).add(convert(ref));
   }
   for (GeneratorDescriptor descriptor : source.getGenerators()) {
     SLinkOperations.getTargets(result, "generator", true).add(convert(descriptor));
   }
   for (ModuleReference ref : source.getExtendedLanguages()) {
     SLinkOperations.getTargets(result, "extendedLanguages", true).add(convert(ref));
   }
   for (Dependency dep : source.getRuntimeModules()) {
     SLinkOperations.getTargets(result, "runtimeModules", true).add(convert(dep));
   }
   for (ModelRoot entry : source.getRuntimeStubModels()) {
     SLinkOperations.getTargets(result, "runtimeStubModels", true).add(convert(entry));
   }
   for (StubSolution sol : source.getStubSolutions()) {
     SLinkOperations.getTargets(result, "stubSolutions", true).add(convert(sol));
   }
   collectModels(result, source);
   return result;
 }
  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);
  }