Пример #1
0
  // fills collections with of imported languages and devkits.
  // Languages include directly imported and coming immediately through devkits; listed devkits are
  // imported directly, without those they extend (why?).
  public LangAndDevkits collectLanguagesAndDevkits() {
    Set<SLanguage> usedLanguages = new LinkedHashSet<>();
    Set<SModuleReference> devkits = new LinkedHashSet<>();

    // perhaps, shall introduce ModuleImports similar to ModelImports to accomplish this?
    for (SModel m : getModels()) {
      final SModelInternal modelInternal = (SModelInternal) m;
      usedLanguages.addAll(modelInternal.importedLanguageIds());
      devkits.addAll(modelInternal.importedDevkits());
    }
    // XXX why don't we respect extended devkits here?
    final SRepository repository = getRepository();
    if (repository != null) {
      for (SModuleReference devkitRef : devkits) {
        final SModule module = devkitRef.resolve(repository);
        if (module instanceof DevKit) {
          for (SLanguage l : ((DevKit) module).getAllExportedLanguageIds()) {
            usedLanguages.add(l);
          }
        }
      }
    }
    usedLanguages.add(BootstrapLanguages.getLangCore());
    return new LangAndDevkits(usedLanguages, devkits);
  }
Пример #2
0
  private void updateUsedLanguages() {
    Set<SLanguage> languagesInModel =
        new HashSet<SLanguage>(((SModelInternal) myModelDescriptor).importedLanguageIds());
    Set<SLanguage> languagesInProps = new HashSet<SLanguage>(getUsedLanguages());
    languagesInProps.removeAll(languagesInModel);

    for (SLanguage lang : languagesInProps) {
      ((SModelInternal) myModelDescriptor).addLanguage(lang);
    }

    languagesInModel.removeAll(getUsedLanguages());
    for (SLanguage lang : languagesInModel) {
      ((SModelInternal) myModelDescriptor).deleteLanguageId(lang);
    }
  }
Пример #3
0
 private void addModelListener(SNode node) {
   SModel sModel = node.getModel();
   SModel descriptor = sModel;
   if (descriptor != null && !myListeningForModels.contains(descriptor)) {
     ((SModelInternal) descriptor).addModelListener(myModelListener);
     myListeningForModels.add(descriptor);
   }
 }
Пример #4
0
 private void addNewModels() {
   Set<SModelReference> modelsInProps = new HashSet<SModelReference>(getImportedModels());
   SModel smodel = myModelDescriptor;
   modelsInProps.removeAll(SModelOperations.getImportedModelUIDs(smodel));
   for (SModelReference modelReference : modelsInProps) {
     ((SModelInternal) smodel).addModelImport(modelReference, false);
   }
 }
Пример #5
0
 private void addModelListener(SModel modelDescriptor) {
   if (modelDescriptor == null) {
     return;
   }
   if (!(SetSequence.fromSet(myListenedModels).contains(modelDescriptor))) {
     ((SModelInternal) modelDescriptor).addModelListener(myModelListener);
     SetSequence.fromSet(myListenedModels).addElement(modelDescriptor);
   }
 }
Пример #6
0
 private void removeUnusedModels() {
   SModel smodel = myModelDescriptor;
   Set<SModelReference> modelsInModel =
       new HashSet<SModelReference>(SModelOperations.getImportedModelUIDs(smodel));
   modelsInModel.removeAll(getImportedModels());
   for (SModelReference modelReference : modelsInModel) {
     ((SModelInternal) smodel).deleteModelImport(modelReference);
   }
 }
Пример #7
0
 private static void addImportIfNeed(SModel model, SModel toImport) {
   if (model == null || toImport == null) {
     return;
   }
   SModelReference ref = toImport.getReference();
   if (model == toImport || SModelOperations.getImportedModelUIDs(model).contains(ref)) {
     return;
   }
   ((SModelInternal) model).addModelImport(ref, false);
 }
Пример #8
0
 private void removeUnusedDevKits() {
   Set<SModuleReference> propsDevKits = new HashSet<SModuleReference>(getUsedDevKits());
   List<SModuleReference> imported =
       new ArrayList<SModuleReference>(((SModelInternal) myModelDescriptor).importedDevkits());
   for (SModuleReference dk : imported) {
     if (!(propsDevKits.contains(dk))) {
       ((SModelInternal) myModelDescriptor).deleteDevKit(dk);
     }
   }
 }
Пример #9
0
 private void removeUnusedEngagedOnGenerationLanguages() {
   Set<SModuleReference> languagesInModel =
       new HashSet<SModuleReference>(
           ((SModelInternal) myModelDescriptor).engagedOnGenerationLanguages());
   Set<SModuleReference> languagesInProps =
       new HashSet<SModuleReference>(getLanguagesEngagedOnGeneration());
   languagesInModel.removeAll(languagesInProps);
   for (SModuleReference ref : languagesInModel) {
     ((SModelInternal) myModelDescriptor).removeEngagedOnGenerationLanguage(ref);
   }
 }
Пример #10
0
 private void addNewEngagedOnGenerationLanguages() {
   Set<SModuleReference> languagesInModel =
       new HashSet<SModuleReference>(
           ((SModelInternal) myModelDescriptor).engagedOnGenerationLanguages());
   Set<SModuleReference> languagesInProps =
       new HashSet<SModuleReference>(getLanguagesEngagedOnGeneration());
   languagesInProps.removeAll(languagesInModel);
   for (SModuleReference namespace : languagesInProps) {
     ((SModelInternal) myModelDescriptor).addEngagedOnGenerationLanguage(namespace);
   }
 }
Пример #11
0
 private void addNewDevKits() {
   Set<SModuleReference> devKitsInModel =
       new HashSet<SModuleReference>(((SModelInternal) myModelDescriptor).importedDevkits());
   Set<SModuleReference> devKitsInProperties = new HashSet<SModuleReference>(getUsedDevKits());
   devKitsInProperties.removeAll(devKitsInModel);
   for (SModuleReference dk : devKitsInProperties) {
     DevKit devKit = ModuleRepositoryFacade.getInstance().getModule(dk, DevKit.class);
     assert devKit != null;
     SModel model = myModelDescriptor;
     ((SModelInternal) model).addDevKit(dk);
   }
 }
Пример #12
0
 private void checkModelVersionsAreValid(SLanguage lang) {
   int currentVersion = lang.getLanguageVersion();
   for (SModel m : getModels()) {
     SModelInternal modelInternal = (SModelInternal) m;
     if (modelInternal.importedLanguageIds().contains(lang)) {
       int modelVer = modelInternal.getLanguageImportVersion(lang);
       if (modelVer != -1) {
         if (modelInternal.importedLanguageIds().contains(lang) && modelVer != currentVersion) {
           LOG.error(
               "Could not update used language versions. Language "
                   + lang
                   + " has current version "
                   + currentVersion
                   + " while model "
                   + m.getName()
                   + " uses this language with version "
                   + modelVer);
         }
       }
     }
   }
 }
Пример #13
0
 public void dispose() {
   for (SModel model : myListeningForModels) {
     ((SModelInternal) model).removeModelListener(myModelListener);
   }
   myListeningForModels.clear();
   for (SNodeReference nodePointer :
       new ArrayList<SNodeReference>(myTypeCheckingContexts.keySet())) {
     removeContextForNode(nodePointer);
   }
   SModelRepository.getInstance().removeModelRepositoryListener(mySModelRepositoryListener);
   myClassLoaderManager.removeReloadHandler(myReloadHandler);
   INSTANCE = null;
 }
Пример #14
0
 protected void addNodeImports(SNode node) {
   final SModelInternal modelInternal = (SModelInternal) myModel;
   final AbstractModule module = ((AbstractModule) myModel.getModule());
   final Collection<SLanguage> importedLanguages = modelInternal.importedLanguageIds();
   for (SNode subNode :
       ListSequence.fromList(
           SNodeOperations.getNodeDescendants(node, null, true, new SAbstractConcept[] {}))) {
     SLanguage usedLanguage = subNode.getConcept().getLanguage();
     if (!(importedLanguages.contains(usedLanguage))) {
       modelInternal.addLanguage(usedLanguage);
     }
     for (SReference ref : ListSequence.fromList(SNodeOperations.getReferences(subNode))) {
       SModel usedModel = SNodeOperations.getModel(SLinkOperations.getTargetNode(ref));
       if (usedModel != null && !(modelInternal.importedModels().contains(usedModel))) {
         modelInternal.addModelImport(usedModel.getReference(), false);
         module.addDependency(
             SNodeOperations.getModel(SLinkOperations.getTargetNode(ref))
                 .getModule()
                 .getModuleReference(),
             false);
       }
     }
   }
 }
Пример #15
0
 protected void addBuiltInImports() {
   SLanguage base =
       MetaAdapterFactory.getLanguage(
           MetaIdFactory.langId(0xde1ad86d6e504a02L, 0xb306d4d17f64c375L),
           "jetbrains.mps.console.base");
   Collection<SLanguage> baseAndExtensions =
       new SLanguageHierarchy(Collections.singleton(base)).getExtending();
   SModelInternal modelInternal = ((SModelInternal) myModel);
   for (SLanguage l : CollectionSequence.fromCollection(baseAndExtensions)) {
     modelInternal.addLanguage(l);
     Language sourceLangModule = (Language) l.getSourceModule();
     if (sourceLangModule == null) {
       continue;
     }
     modelInternal.addModelImport(
         sourceLangModule.getStructureModelDescriptor().getReference(), false);
     ((AbstractModule) myModel.getModule())
         .addDependency(sourceLangModule.getModuleReference(), false);
   }
   modelInternal.addDevKit(
       PersistenceFacade.getInstance()
           .createModuleReference(
               "fbc25dd2-5da4-483a-8b19-70928e1b62d7(jetbrains.mps.devkit.general-purpose)"));
 }
Пример #16
0
 protected void validateImports() {
   SModelInternal modelInternal = (SModelInternal) myModel;
   for (SModuleReference devKit :
       ListSequence.fromListWithValues(
           new ArrayList<SModuleReference>(), modelInternal.importedDevkits())) {
     modelInternal.deleteDevKit(devKit);
   }
   for (SLanguage language :
       ListSequence.fromListWithValues(
           new ArrayList<SLanguage>(), modelInternal.importedLanguageIds())) {
     modelInternal.deleteLanguageId(language);
   }
   for (jetbrains.mps.smodel.SModel.ImportElement model :
       ListSequence.fromListWithValues(
           new ArrayList<jetbrains.mps.smodel.SModel.ImportElement>(),
           modelInternal.importedModels())) {
     modelInternal.deleteModelImport(model.getModelReference());
   }
   addBuiltInImports();
   TemporaryModels.getInstance().addMissingImports(myModel);
 }
Пример #17
0
 private void removeModelListener(SModel modelDescriptor) {
   if (SetSequence.fromSet(myListenedModels).contains(modelDescriptor)) {
     ((SModelInternal) modelDescriptor).removeModelListener(myModelListener);
     SetSequence.fromSet(myListenedModels).removeElement(modelDescriptor);
   }
 }
Пример #18
0
 private void removeModelListener() {
   for (SModel modelDescriptor : myListenedModels) {
     ((SModelInternal) modelDescriptor).removeModelListener(myModelListener);
   }
   SetSequence.fromSet(myListenedModels).clear();
 }
Пример #19
0
 @Override
 public void modelAdded(SModule module, SModel model) {
   if (!(model instanceof SModelInternal)) return;
   ((SModelInternal) model).addModelListener(MODEL_RUNTIME_IMPORTER);
 }