Class AbstractModule

  • All Implemented Interfaces:
    EditableSModule, SModule
    Direct Known Subclasses:
    DevKit, ProjectStructureModule, ReloadableModuleBase, TempModule2, TransientModelsModule

    public abstract class AbstractModule
    extends SModuleBase
    implements EditableSModule
    First of all, this class serves as a file-based module. Obviously it requires a file which contains a persisted module descriptor (see constructor). Secondly, this class provides a common implementation of the module editing. Not only the implementation of simple interface EditableSModule is here but also a special editing mechanism is suggested below. Nonetheless there are several flaws. 1. We need to separate FileBasedModule from the AbstractModule in order to make the AbstractModule truly abstract. 2. We need to enforce a special committing mechanism (for the module editing) which is only sketched in this class. The getModuleDescriptor() method in fact is just a public property which discloses all the internals of the module. It is undoubtedly ought to be fixed. Moreover the implementations of this method return the original descriptor (copy they must return!). [not the problem of the abstract module per se] Suggestion [to be done]: Rather the AbstractModule must possess a special #getEditingHandle which returns a class which in turn is able to accumulate all the changes user desire to accomplish and when user is finished with editing commit all the changes with one invocation of handle.commit(). [or something like this] 3. Also this subclass serves another purpose: it introduces model roots and module facets into module. I guess this logic might migrate to SModuleBase. AP
    See Also:
    for the details
    • Constructor Detail

      • AbstractModule

        @Deprecated
        protected AbstractModule()
        Deprecated.
      • AbstractModule

        protected AbstractModule​(@Nullable
                                 IFile descriptorFile)
    • Method Detail

      • getModuleId

        public SModuleId getModuleId()
        Description copied from interface: SModule
        The repository-wide unique identifier
        Specified by:
        getModuleId in interface SModule
      • getModuleName

        public String getModuleName()
        Description copied from interface: SModule
        Identical to getModuleReference.getModuleName()
        Specified by:
        getModuleName in interface SModule
      • getDeclaredDependencies

        public Iterable<SDependency> getDeclaredDependencies()
        Description copied from interface: SModule
        All dependencies on modules of all kinds. Includes only dependencies declared in this model. See also GlobalModuleDependenciesManager [not yet in API]
        Specified by:
        getDeclaredDependencies in interface SModule
      • setModuleDescriptor

        public final void setModuleDescriptor​(@NotNull
                                              ModuleDescriptor moduleDescriptor,
                                              boolean setAsChanged)
        PROVISIONAL INTERNAL API, DON'T USE OUTSIDE OF MPS, TO BE CHANGED WITHOUT NOTICE sometimes we do not need to mark the reloaded module as changed (e.g. in the cases when we reload from the disk)
      • doSetModuleDescriptor

        protected void doSetModuleDescriptor​(ModuleDescriptor moduleDescriptor)
      • addDependency

        @Nullable
        public Dependency addDependency​(@NotNull
                                        SModuleReference moduleRef,
                                        boolean reexport)
        FIXME module editing is generally done through descriptor and reload. Although I do not mind exposing add/remove methods here, it should be consistent! There's use in mbeddr
      • updatePackagedDescriptor

        @Deprecated
        protected void updatePackagedDescriptor()
        Deprecated.
        no-op, just drop any usage.
      • reloadAfterDescriptorChange

        protected void reloadAfterDescriptorChange()
      • collectMandatoryFacetTypes

        protected void collectMandatoryFacetTypes​(Set<String> types)
        For the time being, MPS enforces certain facets for modules (e.g. Java facet is essential for classloading mechanism). As we move forward with facets story, we likely respect actual facets for the module (e.g. would force Java facet on module creation only) Need to ensure classloading could deal with modules without Java facet, then can drop these mandatory facets altogether
      • updateFacets

        protected void updateFacets()
      • onModuleLoad

        public void onModuleLoad()
      • isReadOnly

        public boolean isReadOnly()
        Description copied from interface: SModule
        No updates are permitted
        Specified by:
        isReadOnly in interface SModule
      • isPackaged

        public boolean isPackaged()
        Description copied from interface: SModule
        The module has been imported as a compiled library, not sources. Implies read only.
        Specified by:
        isPackaged in interface SModule
      • getModuleSourceDir

        public IFile getModuleSourceDir()
        Module sources folder In case of working on sources == dir with module descriptor In case of working on distribution = {module-name}-src.jar/module/ In case of Generator = sourceLanguage.getModuleSourceDir() ${module} expands to this method
      • getDescriptorFile

        @Nullable
        public final IFile getDescriptorFile()
        The use of the method is discouraged as it exposes some internal MPS infrastructure. Modules do not necessarily originate from files. There's no limitation of number of modules that share same descriptor file.

        Note, the name of descriptor file for deployed module is not necessarily the same as for the same module in sources (e.g. META-INF/module.xml vs mylang/my.lang.mpl)

        Returns:
        a file (might be shared with other module) we took module's description from, or null if no such information is available.
      • setModuleVersion

        public void setModuleVersion​(int version)
      • getModuleVersion

        public int getModuleVersion()
      • renameModels

        public void renameModels​(String oldName,
                                 String newName,
                                 boolean moveModels)
        Must be transferred to workbench or elsewhere as a separate listening mechanism. An induced contract is not part of the module/model api, it is our desire -- I would rather move it to workbench [AP] Please do not use unless absolutely necessary
      • getSourcePaths

        @Deprecated
        public List<String> getSourcePaths()
        Deprecated.
        though there are no uses, I still hesitate what's the right way to access source paths of a module ModuleDesciptor.getSourcePath(), actively in use, is the worst possible way, no MD shall get exposed to end-user. SModuleOperations.getAllSourcePaths(this) is better, yet not that discoverable. AbstractModule.getSourcePaths() is both discoverable and not exposing MD, but cast to AM is odd, and getSourcePaths is definitely not a part of SModule API. To me, it's rather part of JavaModuleFacet. Left as a reminder to refactor uses of other APIs prior to removing the method.
      • updateModelsSet

        public void updateModelsSet()
      • handleReadProblem

        public static void handleReadProblem​(AbstractModule module,
                                             Exception e,
                                             boolean isInConflict)
      • updateExternalReferences

        public void updateExternalReferences()
      • dependenciesChanged

        protected void dependenciesChanged()
      • getFacet

        @Nullable
        public <T extends SModuleFacet> T getFacet​(@NotNull
                                                   Class<T> clazz)
        Description copied from interface: SModule
        Returns facet of the specified class. If there is more than one facet instance that conforms specified class, it's unspecified which one is returned, use SModule.getFacets() instead and filter as appropriate.
        Specified by:
        getFacet in interface SModule
      • getOutputPath

        @Deprecated
        public IFile getOutputPath()
        Deprecated.
        this is internal method, ask ModuleDescriptor for persisted setting directly, if it's what you're looking for (check ProjectPathUtil.getGeneratorOutputPath(ModuleDescriptor). There ain't no such thing as output path for a module in general. This method is no longer used in MPS, do not resurrect its uses. Although it's not part of openapi, AbstractModule is often deemed as 'almost api', left for one release.
      • getUsedLanguageVersion

        @Deprecated
        public int getUsedLanguageVersion​(@NotNull
                                          SLanguage usedLanguage,
                                          boolean check)
        Deprecated.
        hack for migration, will be gone after 3.4
        has a fallback if the usedLanguage is absent in the module descriptor. if it happens then returns simply the current usedLanguage version
        Parameters:
        check - is whether to show error for not found version
      • getDependencyVersion

        public int getDependencyVersion​(@NotNull
                                        SModule dependency)
      • getDependencyVersion

        public int getDependencyVersion​(@NotNull
                                        SModule dependency,
                                        boolean check)
        has a fallback if the dependency is absent in the module descriptor. if it happens then returns simply the current dep. module version
        Parameters:
        check - is whether to show error for not found version