Beispiel #1
0
  /**
   * FIXME module editing is generally done through descriptor and reload. Although I do not mind
   * exposing add/remove methods here, it should be consistent!
   */
  @Nullable
  public Dependency addDependency(@NotNull SModuleReference moduleRef, boolean reexport) {
    assertCanChange();
    ModuleDescriptor descriptor = getModuleDescriptor();
    if (descriptor == null) {
      return null;
    }
    for (Dependency dep : descriptor.getDependencies()) {
      if (!EqualUtil.equals(dep.getModuleRef(), moduleRef)) {
        continue;
      }

      if (reexport && !dep.isReexport()) {
        dep.setReexport(true);
        dependenciesChanged();
        fireChanged();
        setChanged();
      }
      return dep;
    }

    Dependency dep = new Dependency();
    dep.setModuleRef(moduleRef);
    dep.setReexport(reexport);
    descriptor.getDependencies().add(dep);

    dependenciesChanged();
    fireChanged();
    setChanged();
    return dep;
  }
Beispiel #2
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);
  }
Beispiel #3
0
 // unlike similar method in SModel, doesn't take SRepository now
 // according to present use cases, we iterate modules of a repository and update them,
 // hence it's superficial  to pass repository in here (although might add one for consistency)
 public void updateExternalReferences() {
   ModuleDescriptor moduleDescriptor = getModuleDescriptor();
   final SRepository repository = getRepository();
   if (moduleDescriptor == null || repository == null) {
     return;
   }
   if (moduleDescriptor.updateModelRefs(repository)) {
     setChanged();
   }
   if (moduleDescriptor.updateModuleRefs(repository)) {
     setChanged();
   }
 }
Beispiel #4
0
 // todo should be replaced with events
 public final void setModuleDescriptor(ModuleDescriptor moduleDescriptor) {
   assertCanChange();
   doSetModuleDescriptor(moduleDescriptor);
   setChanged();
   reloadAfterDescriptorChange();
   fireChanged();
   dependenciesChanged();
 }
Beispiel #5
0
 /**
  * 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);
 }
Beispiel #6
0
  public void removeDependency(@NotNull Dependency dependency) {
    assertCanChange();
    ModuleDescriptor descriptor = getModuleDescriptor();
    if (descriptor == null) {
      return;
    }
    if (!descriptor.getDependencies().contains(dependency)) {
      return;
    }

    descriptor.getDependencies().remove(dependency);

    dependenciesChanged();
    fireChanged();
    setChanged();
  }
Beispiel #7
0
 public void setModuleVersion(int version) {
   getModuleDescriptor().setModuleVersion(version);
   fireChanged();
   setChanged();
 }