Esempio n. 1
0
  @Override
  public Iterable<SDependency> getDeclaredDependencies() {
    assertCanRead();
    ModuleDescriptor descriptor = getModuleDescriptor();
    if (descriptor == null) {
      return Collections.emptyList();
    }
    HashSet<SDependency> result = new HashSet<SDependency>();
    final SRepository repo = getRepository();
    if (repo == null) {
      throw new IllegalStateException(
          "It is not possible to resolve all declared dependencies with a null repository : module "
              + this);
    }

    // add declared dependencies
    for (Dependency d : descriptor.getDependencies()) {
      result.add(new SDependencyImpl(d.getModuleRef(), repo, d.getScope(), d.isReexport()));
    }

    // add dependencies provided by devkits as nonreexport dependencies
    for (SModuleReference usedDevkit : descriptor.getUsedDevkits()) {
      final SModule devkit = usedDevkit.resolve(repo);
      if (DevKit.class.isInstance(devkit)) {
        for (Solution solution : ((DevKit) devkit).getAllExportedSolutions()) {
          result.add(
              new SDependencyImpl(
                  solution.getModuleReference(), repo, SDependencyScope.DEFAULT, false));
        }
      }
    }
    return result;
  }
Esempio n. 2
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);
  }
Esempio n. 3
0
  /** @return message with the problem description or null if the module is valid */
  @Nullable
  @Hack
  private String getModuleProblemMessage(
      SModuleReference mRef,
      Map<ReloadableModule, AbsentDependencyException> modulesWithAbsentDeps) {
    assert !isChanged();
    if (isModuleDisposed(mRef)) {
      return String.format(
          "Module %s is disposed and therefore was marked invalid for class loading",
          mRef.getModuleName());
    }

    ReloadableModule module = (ReloadableModule) mRef.resolve(myRepository);
    assert module != null;

    // FIXME does not work for now, enable in the 3.4
    if (modulesWithAbsentDeps.containsKey(module)) {
      AbsentDependencyException exception = modulesWithAbsentDeps.get(module);
      return String.format(
          "%s has got an absent dependency problem and therefore was marked invalid for class loading: %s",
          module, exception.getMessage());
    }
    for (SDependency dep : module.getDeclaredDependencies()) {
      if (dep.getScope() == SDependencyScope.DESIGN
          || dep.getScope() == SDependencyScope.GENERATES_INTO) {
        continue;
      }
      if (isModuleDisposed(dep.getTargetModule())) {
        return String.format(
            "%s depends on a disposed module %s and therefore was marked invalid for class loading",
            module, dep.getTargetModule());
      }
    }
    return null;
  }
Esempio n. 4
0
 /*package*/ void updateIcon(SRepository repo) {
   SModule m = myModule.resolve(repo);
   if (m == null) {
     setIcon(IdeIcons.DEFAULT_ICON);
   } else {
     setIcon(IconManager.getIconFor(m));
   }
 }
Esempio n. 5
0
  @Override
  public Dependency addDependency(@NotNull SModuleReference moduleRef, boolean reexport) {
    // we do not add a dependency into solution, we add dependency to idea module instead
    ModifiableRootModel modifiableModel =
        ModuleRootManager.getInstance(myModule).getModifiableModel();

    SModule sModule = moduleRef.resolve(MPSModuleRepository.getInstance()); // FIXME module repo

    if (sModule instanceof SolutionIdea) {
      // we add dependency between idea modules
      Module otherIdeaModule = ((SolutionIdea) sModule).getIdeaModule();
      modifiableModel.addModuleOrderEntry(otherIdeaModule);
    } else {
      ModuleRuntimeLibrariesImporter.importForUsedModules(
          myModule, Collections.singleton(moduleRef), modifiableModel);
    }
    modifiableModel.commit();
    return null;
  }
Esempio n. 6
0
 /**
  * Note: here we are interested in the actual status of module. (not {@link
  * ReferenceStorage#resolveRef}) if it has been already disposed but still remains in our graphs
  * (i.e. ClassLoader is not disposed yet [!]), we need to mark it invalid
  */
 private boolean isModuleDisposed(SModuleReference mRef) {
   SModule resolvedModule = mRef.resolve(myRepository);
   return (resolvedModule == null || resolvedModule.getRepository() == null);
 }
Esempio n. 7
0
  private List<DepLink> dependencies(DependencyUtil.Role role, SModuleReference moduleRef) {
    List<DepLink> result = ListSequence.fromList(new ArrayList<DepLink>());
    SModule module = moduleRef.resolve(myRepo);
    ModuleDescriptor descr = ((AbstractModule) module).getModuleDescriptor();
    if (descr == null) {
      return result;
    }
    switch (role) {
      case OwnedGenerator:
      case None:
        // first step
        addDeps(
            result,
            descr.getUsedDevkits(),
            DependencyUtil.Role.UsedDevkit,
            DependencyUtil.LinkType.UsesDevkit);
        for (SLanguage lang : module.getUsedLanguages()) {
          SModule langModule = lang.getSourceModule();
          if (langModule != null) {
            ListSequence.fromList(result)
                .addElement(
                    new DepLink(
                        langModule.getModuleReference(),
                        DependencyUtil.Role.UsedLanguage,
                        DependencyUtil.LinkType.UsesLanguage));
          }
        }
        for (SDependency dep : module.getDeclaredDependencies()) {
          switch (dep.getScope()) {
            case EXTENDS:
              SModule t = dep.getTarget();
              if (t instanceof Language) {
                ListSequence.fromList(result)
                    .addElement(
                        new DepLink(
                            dep.getTargetModule(),
                            DependencyUtil.Role.RegularDependency,
                            DependencyUtil.LinkType.ExtendsLanguage));
              } else if (t instanceof Generator) {
                ListSequence.fromList(result)
                    .addElement(
                        new DepLink(
                            dep.getTargetModule(),
                            DependencyUtil.Role.RegularDependency,
                            DependencyUtil.LinkType.ExtendsGenerator));
              } else {
                // just in case module could not be resolved
                ListSequence.fromList(result)
                    .addElement(
                        new DepLink(
                            dep.getTargetModule(),
                            DependencyUtil.Role.RegularDependency,
                            DependencyUtil.LinkType.Depends));
              }
              break;
            case DESIGN:
              ListSequence.fromList(result)
                  .addElement(
                      new DepLink(
                          dep.getTargetModule(),
                          DependencyUtil.Role.RegularDependency,
                          DependencyUtil.LinkType.Depends));
              break;
            case RUNTIME:
              ListSequence.fromList(result)
                  .addElement(
                      new DepLink(
                          dep.getTargetModule(),
                          DependencyUtil.Role.RuntimeDependency,
                          DependencyUtil.LinkType.Depends));
              break;
            default:
              ListSequence.fromList(result)
                  .addElement(
                      new DepLink(
                          dep.getTargetModule(),
                          DependencyUtil.Role.RegularDependency,
                          (dep.isReexport()
                              ? DependencyUtil.LinkType.ReexportsDep
                              : DependencyUtil.LinkType.Depends)));
          }
        }
        if (module instanceof Language) {
          // generators and generators dependencies are now also added to language dependencies
          // (MPS-15883)
          for (Generator g : ((Language) module).getGenerators()) {
            ListSequence.fromList(result)
                .addElement(
                    new DepLink(
                        g.getModuleReference(),
                        DependencyUtil.Role.OwnedGenerator,
                        DependencyUtil.LinkType.Generator));
          }
        }
        if (module instanceof Generator) {
          Language srcLang = ((Generator) module).getSourceLanguage();
          ListSequence.fromList(result)
              .addElement(
                  new DepLink(
                      srcLang.getModuleReference(),
                      DependencyUtil.Role.SourceLanguage,
                      DependencyUtil.LinkType.GeneratorLanguage));
        }
        break;

      case UsedDevkit:
        // explicit use of devkit
      case DependencyDevkit:
        DevkitDescriptor devkit = as_he47wm_a0a0a3e0g(descr, DevkitDescriptor.class);
        if (devkit == null) {
          break;
        }
        boolean direct = role == DependencyUtil.Role.UsedDevkit;
        addDeps(
            result,
            devkit.getExtendedDevkits(),
            (direct ? DependencyUtil.Role.UsedDevkit : DependencyUtil.Role.DependencyDevkit),
            DependencyUtil.LinkType.ExtendsDevkit);
        addDeps(
            result,
            devkit.getExportedLanguages(),
            (direct ? DependencyUtil.Role.UsedLanguage : DependencyUtil.Role.DependencyLanguage),
            DependencyUtil.LinkType.ExportsLanguage);
        addDeps(
            result,
            devkit.getExportedSolutions(),
            (direct
                ? DependencyUtil.Role.RegularDependency
                : DependencyUtil.Role.RuntimeDependency),
            DependencyUtil.LinkType.ExportsSolution);
        break;

      case UsedLanguage:
        LanguageDescriptor lang = as_he47wm_a0a0a4e0g(descr, LanguageDescriptor.class);
        if (lang == null) {
          break;
        }
        addDeps(
            result,
            lang.getExtendedLanguages(),
            DependencyUtil.Role.UsedLanguage,
            DependencyUtil.LinkType.ExtendsLanguage);
        if (myNeedRuntime) {
          addDeps(
              result,
              lang.getRuntimeModules(),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.ExportsRuntime);
        }
        break;

      case RegularDependency:
        addDeps(
            result,
            getReexportDeps(descr),
            DependencyUtil.Role.RegularDependency,
            DependencyUtil.LinkType.ReexportsDep);
        if (descr instanceof LanguageDescriptor) {
          addDeps(
              result,
              (as_he47wm_a0a1a0a1a5e0g(descr, LanguageDescriptor.class)).getExtendedLanguages(),
              DependencyUtil.Role.RegularDependency,
              DependencyUtil.LinkType.ExtendsLanguage);
        }
        if (myNeedRuntime) {
          addDeps(
              result,
              getNonreexportDeps(descr),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.Depends);
          addDeps(
              result,
              descr.getUsedLanguages(),
              DependencyUtil.Role.DependencyLanguage,
              DependencyUtil.LinkType.UsesLanguage);
          addDeps(
              result,
              descr.getUsedDevkits(),
              DependencyUtil.Role.DependencyDevkit,
              DependencyUtil.LinkType.UsesDevkit);
        }
        break;

      case RuntimeDependency:
        if (myNeedRuntime) {
          addDeps(
              result,
              getReexportDeps(descr),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.ReexportsDep);
          addDeps(
              result,
              getNonreexportDeps(descr),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.Depends);
          addDeps(
              result,
              descr.getUsedLanguages(),
              DependencyUtil.Role.DependencyLanguage,
              DependencyUtil.LinkType.UsesLanguage);
          addDeps(
              result,
              descr.getUsedDevkits(),
              DependencyUtil.Role.DependencyDevkit,
              DependencyUtil.LinkType.UsesDevkit);
          if (descr instanceof LanguageDescriptor) {
            addDeps(
                result,
                (as_he47wm_a0a1a0a4a0a6e0g(descr, LanguageDescriptor.class)).getExtendedLanguages(),
                DependencyUtil.Role.RuntimeDependency,
                DependencyUtil.LinkType.ExtendsLanguage);
          }
          if (descr instanceof GeneratorDescriptor) {
            GeneratorDescriptor gen = (GeneratorDescriptor) descr;
            // generator languages are now also dependencies
            addDeps(
                result,
                gen.getDepGenerators(),
                DependencyUtil.Role.RuntimeDependency,
                DependencyUtil.LinkType.DependsOnGenerator);
            ListSequence.fromList(result)
                .addElement(
                    new DepLink(
                        (as_he47wm_a0a0a0a0a3a5a0a6e0g(module, Generator.class))
                            .getSourceLanguage()
                            .getModuleReference(),
                        DependencyUtil.Role.RuntimeDependency,
                        DependencyUtil.LinkType.GeneratorLanguage));
          }
        }
        break;

      case SourceLanguage:
        // dependency from generator to its source language
        addDeps(
            result,
            check_he47wm_b0b0h4a6(as_he47wm_a0b0b0h4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.SourceLanguage,
            DependencyUtil.LinkType.ExtendsLanguage);
        addDeps(
            result,
            check_he47wm_b0c0h4a6(as_he47wm_a0b0c0h4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.RuntimeDependency,
            DependencyUtil.LinkType.ExportsRuntime);
        break;

      case DependencyLanguage:
        addDeps(
            result,
            check_he47wm_b0a0i4a6(as_he47wm_a0b0a0i4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.DependencyLanguage,
            DependencyUtil.LinkType.ExtendsLanguage);
        addDeps(
            result,
            check_he47wm_b0b0i4a6(as_he47wm_a0b0b0i4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.RuntimeDependency,
            DependencyUtil.LinkType.ExportsRuntime);
        break;

      default:
    }
    return result;
  }