Class ModuleRepositoryFacade

  • All Implemented Interfaces:
    CoreComponent

    public final class ModuleRepositoryFacade
    extends Object
    implements CoreComponent
    Mediator between API aspects of an SRepository and our implementation aspects, like SRepositoryExt. Use this class to avoid casts to SRepositoryExt IMPORTANT: lifespan of a facade instance shall not last longer than single model read. Implementation may cache values (e.g. model name to model instance) to answer subsequent queries faster, and may not reflect changes made to a repository.
    • Constructor Detail

      • ModuleRepositoryFacade

        @Deprecated
        public ModuleRepositoryFacade​(MPSModuleRepository repo)
        Deprecated.
        This class shall cease to be CoreComponent and singleton. Instead, shall be instantiated directly with ModuleRepositoryFacade(SRepository) when our implementation code need to deal with repository internals
        Parameters:
        repo -
      • ModuleRepositoryFacade

        public ModuleRepositoryFacade​(@NotNull
                                      Project mpsProject)
      • ModuleRepositoryFacade

        public ModuleRepositoryFacade​(@NotNull
                                      SRepository repository)
        Some methods of this facade are bound to implementation-specific SRepositoryExt and MPSModuleOwner interfaces Unless you use them, you're safe to pass any SRepository instance here. If, however, you need to register/unregister modules, make sure repository you pass is instance of SRepositoryExt
        Parameters:
        repository - container for modules as described above
    • Method Detail

      • getRepository

        public SRepository getRepository()
        Returns:
        repository this facade has been initialized with, never null
        Since:
        2017.2
      • getModelByName

        @Nullable
        @Deprecated
        public SModel getModelByName​(@Nullable
                                     String modelQualifiedName)
        Deprecated.
        there could be more than 1 model with the same name, use getModelsByName(SModelName) and pick the one you need. This is provisional API to keep all uses of SModelRepository.getModelDescriptor(String) in a single, controlled place. I could had had created ModelRepositoryFacade, similar to this class, however, it seems just too much for a single method that we shall drop anyway.
        Parameters:
        modelQualifiedName -
        Returns:
        named model
      • getModelsByName

        @NotNull
        public Collection<SModel> getModelsByName​(@Nullable
                                                  SModelName modelName)
        Replacement for getModelByName(String) that respects the case when models with the same name present (e.g. in different modules). Generally, accessing models by name is nad idea, you shall prefer SModelReference to access specific model. There are certain scenarios, though, when we need to access by name, therefore we keep this utility method in a facade class. Note, implementation of this method is ineffective now, as it iterates over all modules and models of a repository.
        Parameters:
        modelName - exact name (qualified, with stereotype, if any) of the model to match
        Returns:
        all models with the same exact name, or empty collection if none found
      • getAllModels

        public Collection<SModel> getAllModels()
        Provisional API while we migrate from singleton SModelRepository. Likely, SModelRepository would become a view of an SRepository, giving access to models and bulk operations for the set of models.
        Returns:
        snapshot state of the models available in the repository
      • getAllExtendingLanguages

        @Deprecated
        public Collection<Language> getAllExtendingLanguages​(Language l)
        Deprecated.
        If there's need for extending language, shall add Language.getDirectlyExtendingLanguage. There's single use in mbeddr.
        Find language modules directly extending the one supplied. There's Language.getAllExtendedLanguages() extended languages. Though it's stupid to keep two locations, this method didn't relocate next to it as there are no uses in MPS and it shall cease to exist
      • unregisterModules

        public void unregisterModules​(MPSModuleOwner owner)
      • unregisterModule

        public void unregisterModule​(@NotNull
                                     SModule module)
        unregisters module from all its owners
      • instantiateModule

        @NotNull
        public SModule instantiateModule​(@NotNull
                                         ModulesMiner.ModuleHandle handle,
                                         @NotNull
                                         MPSModuleOwner owner)
        Instantiate a new module according to description and register it with the facade's repository. If there's module already (expected scenario), just updates its relation to another module owner (same module could get published with few owners)
        Returns:
        instance of a module, either new one or existing from the facade's repository.
        Throws:
        IllegalArgumentException - if handle describes unknown module kind.