コード例 #1
0
ファイル: AbstractModule.java プロジェクト: JetBrains/MPS
  /**
   * AP the contract is not clear: when should this method be called? it seems to be our internal
   * mechanism which is exposed to the client it must be done on the fs update (actually it is
   * #update method here) Nobody must recount the module dependency versions from the outside
   *
   * <p>Currently happens only during migration;
   *
   * @deprecated please do not use
   */
  @Deprecated
  @ToRemove(version = 3.4)
  public void validateLanguageVersions() {
    assertCanChange();
    ModuleDescriptor md = getModuleDescriptor();
    if (md == null) {
      return;
    }
    Map<SLanguage, Integer> oldLanguageVersions = md.getLanguageVersions();
    Map<SLanguage, Integer> newLanguageVersions = new HashMap<SLanguage, Integer>();

    LangAndDevkits langAndDevkits = collectLanguagesAndDevkits();
    Set<SLanguage> usedLanguages = langAndDevkits.languages;
    Set<SModuleReference> devkits = langAndDevkits.devkits;
    SLanguageHierarchy languageHierarchy = new SLanguageHierarchy(usedLanguages);
    Reference<Boolean> hasErrors = new Reference<>(false);
    Set<SLanguage> extendingLangsClosure =
        languageHierarchy.getExtendedLangs(language -> hasErrors.set(true));
    if (hasErrors.get()) {
      return;
    }
    if (!md.hasLanguageVersions()) {
      for (SLanguage lang : extendingLangsClosure) {
        newLanguageVersions.put(lang, 0);
      }
      md.getUsedDevkits().addAll(devkits);
      md.setHasLanguageVersions(true);
    } else {
      for (SLanguage lang : extendingLangsClosure) {
        if (oldLanguageVersions.containsKey(lang)) {
          newLanguageVersions.put(lang, oldLanguageVersions.get(lang));
        } else {
          checkModelVersionsAreValid(lang);
          newLanguageVersions.put(lang, lang.getLanguageVersion());
          // this check is needed to avoid numerous changes in msd/mpl files when opening project
          // without dependency versions
          // here we assume that validateLanguageVersions() is called before
          // validateDependencyVersions()
          // todo: remove this hack after 3.4
          if (md.hasDependencyVersions()) {
            setChanged();
          }
        }
      }
      if (!md.getUsedDevkits().containsAll(devkits)) {
        // intentionally no clean(), augmentation only, just in case there's anything vital already.
        md.getUsedDevkits().addAll(devkits);
        setChanged();
      }
      if (!oldLanguageVersions.equals(newLanguageVersions)) {
        // todo: remove this hack after 3.4
        if (md.hasDependencyVersions()) {
          setChanged();
        }
      }
    }
    oldLanguageVersions.clear();
    oldLanguageVersions.putAll(newLanguageVersions);
  }
コード例 #2
0
ファイル: AbstractModule.java プロジェクト: JetBrains/MPS
 /**
  * FIXME Obviously it must be internal module method: it must be done on the fs update (actually
  * it is #update method here) Nobody must recount the module dependency versions from the outside
  * AP
  *
  * <p>Currently happens only during migration;
  *
  * @deprecated please do not use
  */
 @Deprecated
 @ToRemove(version = 3.4)
 public void validateDependencyVersions() {
   assertCanChange();
   ModuleDescriptor md = getModuleDescriptor();
   if (md == null) {
     return;
   }
   Map<SModuleReference, Integer> oldDepVersions = md.getDependencyVersions();
   Map<SModuleReference, Integer> newDepVersions = new HashMap<SModuleReference, Integer>();
   Set<SModule> visible = new LinkedHashSet<SModule>();
   visible.add(this);
   PostingWarningsErrorHandler handler = new PostingWarningsErrorHandler();
   Collection<SModule> dependentModules =
       new GlobalModuleDependenciesManager(this, handler).getModules(Deptype.VISIBLE);
   if (handler.hasErrors()) {
     return;
   }
   visible.addAll(dependentModules);
   if (!md.hasDependencyVersions()) {
     for (SModule dep : visible) {
       newDepVersions.put(dep.getModuleReference(), 0);
     }
     md.setHasDependencyVersions(true);
   } else {
     for (SModule dep : visible) {
       if (oldDepVersions.containsKey(dep.getModuleReference())) {
         newDepVersions.put(
             dep.getModuleReference(), oldDepVersions.get(dep.getModuleReference()));
       } else {
         newDepVersions.put(dep.getModuleReference(), ((AbstractModule) dep).getModuleVersion());
         setChanged();
       }
     }
     if (oldDepVersions.size() != newDepVersions.size()) {
       setChanged();
     }
   }
   oldDepVersions.clear();
   oldDepVersions.putAll(newDepVersions);
 }