Ejemplo n.º 1
0
  /**
   * 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);
  }
Ejemplo n.º 2
0
 /**
  * has a fallback if the usedLanguage is absent in the module descriptor. if it happens then
  * returns simply the current usedLanguage version
  *
  * @param check is whether to show error for not found version
  * @deprecated hack for migration, will be gone after 3.4
  */
 @ToRemove(version = 3.4)
 @Hack
 @Deprecated
 public int getUsedLanguageVersion(@NotNull SLanguage usedLanguage, boolean check) {
   ModuleDescriptor moduleDescriptor = getModuleDescriptor();
   if (!checkDescriptorNotNull(moduleDescriptor)) {
     return -1;
   }
   Integer res = moduleDescriptor.getLanguageVersions().get(usedLanguage);
   if (res == null) {
     if (check) {
       LOG.warn(
           String.format(
               "#getUsedLanguageVersion can't find a version for language %s in module %s, so it is falling back to the current version of the language. "
                   + "Probably the language is not imported into this module or #validateLanguageVersions() was not called on this module in appropriate moment."
                   + "NB: there might be migrations which must be applied, however they are not going to.",
               usedLanguage.getQualifiedName(), getModuleName()),
           new Throwable());
     }
     return usedLanguage.getLanguageVersion();
   }
   return res;
 }