Package jetbrains.mps.project
Class AbstractModule
- java.lang.Object
 - 
- jetbrains.mps.extapi.module.SModuleBase
 - 
- jetbrains.mps.project.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 interfaceEditableSModuleis 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. ThegetModuleDescriptor()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 theAbstractModulemust possess a special#getEditingHandlewhich 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 ofhandle.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 toSModuleBase. AP- See Also:
 for the details
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractModule.LangAndDevkits 
- 
Field Summary
Fields Modifier and Type Field Description static StringCLASSESstatic StringCLASSES_GENstatic StringMODULE_DIR- 
Fields inherited from class jetbrains.mps.extapi.module.SModuleBase
MODEL_BY_NAME_COMPARATOR 
 - 
 
- 
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractModule()Deprecated.protectedAbstractModule(IFile descriptorFile)protectedAbstractModule(FileSystem fileSystem) 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DependencyaddDependency(SModuleReference moduleRef, boolean reexport)FIXME module editing is generally done through descriptor and reload.voidattach(SRepository repository)AbstractModule.LangAndDevkitscollectLanguagesAndDevkits()protected voidcollectMandatoryFacetTypes(Set<String> types)For the time being, MPS enforces certain facets for modules (e.g.protected voiddependenciesChanged()voiddispose()protected voiddoSetModuleDescriptor(ModuleDescriptor moduleDescriptor)Iterable<SDependency>getDeclaredDependencies()All dependencies on modules of all kinds.intgetDependencyVersion(SModule dependency)intgetDependencyVersion(SModule dependency, boolean check)has a fallback if the dependency is absent in the module descriptor.IFilegetDescriptorFile()The use of the method is discouraged as it exposes some internal MPS infrastructure.<T extends SModuleFacet>
TgetFacet(Class<T> clazz)Returns facet of the specified class.Iterable<SModuleFacet>getFacets()Retrieves all instantiated facets.FileSystemgetFileSystem()Iterable<ModelRoot>getModelRoots()ModuleDescriptorgetModuleDescriptor()SModuleIdgetModuleId()The repository-wide unique identifierStringgetModuleName()Identical to getModuleReference.getModuleName()SModuleReferencegetModuleReference()A reference to the module, which persists between subsequent read/write actions.IFilegetModuleSourceDir()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 methodintgetModuleVersion()IFilegetOutputPath()Deprecated.this is internal method, ask ModuleDescriptor for persisted setting directly, if it's what you're looking for (checkProjectPathUtil.getGeneratorOutputPath(ModuleDescriptor).SearchScopegetScope()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.Set<SLanguage>getUsedLanguages()Returns all used languages by this moduleintgetUsedLanguageVersion(SLanguage usedLanguage)Returns version of used languageintgetUsedLanguageVersion(SLanguage usedLanguage, boolean check)Deprecated.hack for migration, will be gone after 3.4static voidhandleReadProblem(AbstractModule module, Exception e, boolean isInConflict)booleanisChanged()booleanisPackaged()The module has been imported as a compiled library, not sources.booleanisReadOnly()No updates are permittedprotected Iterable<ModelRoot>loadRoots()voidonModuleLoad()protected voidreloadAfterDescriptorChange()voidremoveDependency(Dependency dependency)voidrename(String newModuleName)voidrenameModels(String oldName, String newName, boolean moveModels)Must be transferred to workbench or elsewhere as a separate listening mechanism.voidsave()voidsetChanged()voidsetModuleDescriptor(ModuleDescriptor moduleDescriptor)voidsetModuleDescriptor(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.protected voidsetModuleReference(SModuleReference reference)voidsetModuleVersion(int version)protected ModuleFacetBasesetupFacet(ModuleFacetBase facet, Memento memento)StringtoString()voidupdateExternalReferences()protected voidupdateFacets()voidupdateModelsSet()protected voidupdatePackagedDescriptor()Deprecated.no-op, just drop any usage.- 
Methods inherited from class jetbrains.mps.extapi.module.SModuleBase
addModuleListener, assertCanChange, assertCanRead, fireBeforeModelRenamed, fireChanged, fireModelRenamed, fireModuleRenamed, getModel, getModels, getRepository, registerModel, removeModuleListener, unregisterModel 
- 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
- 
Methods inherited from interface org.jetbrains.mps.openapi.module.SModule
addModuleListener, getModel, getModels, getModels, getRepository, removeModuleListener 
 - 
 
 - 
 
- 
- 
Field Detail
- 
MODULE_DIR
public static final String MODULE_DIR
- See Also:
 - Constant Field Values
 
 
- 
CLASSES_GEN
public static final String CLASSES_GEN
- See Also:
 - Constant Field Values
 
 
- 
CLASSES
public static final String CLASSES
- See Also:
 - Constant Field Values
 
 
 - 
 
- 
Constructor Detail
- 
AbstractModule
@Deprecated protected AbstractModule()
Deprecated. 
- 
AbstractModule
protected AbstractModule(@NotNull FileSystem fileSystem)
 
 - 
 
- 
Method Detail
- 
getFileSystem
@NotNull public FileSystem getFileSystem()
 
- 
getModuleId
public SModuleId getModuleId()
Description copied from interface:SModuleThe repository-wide unique identifier- Specified by:
 getModuleIdin interfaceSModule
 
- 
getModuleName
public String getModuleName()
Description copied from interface:SModuleIdentical to getModuleReference.getModuleName()- Specified by:
 getModuleNamein interfaceSModule
 
- 
getDeclaredDependencies
public Iterable<SDependency> getDeclaredDependencies()
Description copied from interface:SModuleAll dependencies on modules of all kinds. Includes only dependencies declared in this model. See also GlobalModuleDependenciesManager [not yet in API]- Specified by:
 getDeclaredDependenciesin interfaceSModule
 
- 
getUsedLanguages
public Set<SLanguage> getUsedLanguages()
Description copied from interface:SModuleReturns all used languages by this module- Specified by:
 getUsedLanguagesin interfaceSModule
 
- 
collectLanguagesAndDevkits
public AbstractModule.LangAndDevkits collectLanguagesAndDevkits()
 
- 
setModuleReference
protected final void setModuleReference(@NotNull SModuleReference reference)
 
- 
getModuleReference
@NotNull public SModuleReference getModuleReference()
Description copied from interface:SModuleA reference to the module, which persists between subsequent read/write actions.- Specified by:
 getModuleReferencein interfaceSModule
 
- 
getModuleDescriptor
@Nullable public ModuleDescriptor getModuleDescriptor()
 
- 
setModuleDescriptor
public final void setModuleDescriptor(@NotNull ModuleDescriptor moduleDescriptor)
 
- 
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)
 
- 
setChanged
public void setChanged()
- Specified by:
 setChangedin interfaceEditableSModule
 
- 
save
public void save()
- Specified by:
 savein interfaceEditableSModule
 
- 
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 
- 
removeDependency
public void removeDependency(@NotNull Dependency dependency)
 
- 
updatePackagedDescriptor
@Deprecated protected void updatePackagedDescriptor()
Deprecated.no-op, just drop any usage. 
- 
getModelRoots
public Iterable<ModelRoot> getModelRoots()
- Specified by:
 getModelRootsin interfaceSModule
 
- 
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 
- 
setupFacet
protected ModuleFacetBase setupFacet(ModuleFacetBase facet, Memento memento)
 
- 
updateFacets
protected void updateFacets()
 
- 
onModuleLoad
public void onModuleLoad()
 
- 
isReadOnly
public boolean isReadOnly()
Description copied from interface:SModuleNo updates are permitted- Specified by:
 isReadOnlyin interfaceSModule
 
- 
isPackaged
public boolean isPackaged()
Description copied from interface:SModuleThe module has been imported as a compiled library, not sources. Implies read only.- Specified by:
 isPackagedin interfaceSModule
 
- 
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 
nullif no such information is available. 
 
- 
setModuleVersion
public void setModuleVersion(int version)
 
- 
getModuleVersion
public int getModuleVersion()
 
- 
rename
public void rename(@NotNull String newModuleName) throws DescriptorTargetFileAlreadyExistsException
 
- 
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 
- 
getScope
@NotNull public SearchScope getScope()
 
- 
attach
public void attach(@NotNull SRepository repository)
- Overrides:
 attachin classSModuleBase
 
- 
dispose
public void dispose()
- Overrides:
 disposein classSModuleBase
 
- 
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()
 
- 
isChanged
public boolean isChanged()
- Specified by:
 isChangedin interfaceEditableSModule
 
- 
getFacet
@Nullable public <T extends SModuleFacet> T getFacet(@NotNull Class<T> clazz)
Description copied from interface:SModuleReturns facet of the specified class. If there is more than one facet instance that conforms specified class, it's unspecified which one is returned, useSModule.getFacets()instead and filter as appropriate. 
- 
getFacets
@NotNull public Iterable<SModuleFacet> getFacets()
Description copied from interface:SModuleRetrieves all instantiated facets. (seeSModuleFacet) 
- 
getOutputPath
@Deprecated public IFile getOutputPath()
Deprecated.this is internal method, ask ModuleDescriptor for persisted setting directly, if it's what you're looking for (checkProjectPathUtil.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
public int getUsedLanguageVersion(@NotNull SLanguage usedLanguage)
Description copied from interface:SModuleReturns version of used language- Specified by:
 getUsedLanguageVersionin interfaceSModule
 
- 
getUsedLanguageVersion
@Deprecated public int getUsedLanguageVersion(@NotNull SLanguage usedLanguage, boolean check)
Deprecated.hack for migration, will be gone after 3.4has 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
 
 - 
 
 -